152153Sbp/* 252153Sbp * Copyright (c) 1999, Boris Popov 352153Sbp * All rights reserved. 452153Sbp * 552153Sbp * Redistribution and use in source and binary forms, with or without 652153Sbp * modification, are permitted provided that the following conditions 752153Sbp * are met: 852153Sbp * 1. Redistributions of source code must retain the above copyright 952153Sbp * notice, this list of conditions and the following disclaimer. 1052153Sbp * 2. Redistributions in binary form must reproduce the above copyright 1152153Sbp * notice, this list of conditions and the following disclaimer in the 1252153Sbp * documentation and/or other materials provided with the distribution. 13165920Simp * 3. Neither the name of the author nor the names of any co-contributors 1452153Sbp * may be used to endorse or promote products derived from this software 1552153Sbp * without specific prior written permission. 1652153Sbp * 1752153Sbp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1852153Sbp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1952153Sbp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2052153Sbp * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2152153Sbp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2252153Sbp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2352153Sbp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2452153Sbp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2552153Sbp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2652153Sbp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2752153Sbp * SUCH DAMAGE. 2852153Sbp */ 2984213Sdillon 3084213Sdillon#include <sys/cdefs.h> 3184213Sdillon__FBSDID("$FreeBSD$"); 3284213Sdillon 3352153Sbp#include <sys/types.h> 3452153Sbp#include <errno.h> 3552153Sbp#include <stdio.h> 36162486Skan#include <string.h> 3752153Sbp 3852153Sbp#include <netncp/ncp_lib.h> 3952153Sbp#include <netncp/ncp_nls.h> 4052153Sbp 4152153SbpNWCCODE 4252153SbpNWDisableBroadcasts(NWCONN_HANDLE connHandle) { 4352153Sbp DECLARE_RQ; 4452153Sbp 4552153Sbp ncp_init_request_s(conn, 2); 4652153Sbp return ncp_request(connHandle, 21, conn); 4752153Sbp} 4852153Sbp 4952153SbpNWCCODE 5052153SbpNWEnableBroadcasts(NWCONN_HANDLE connHandle) { 5152153Sbp DECLARE_RQ; 5252153Sbp 5352153Sbp ncp_init_request_s(conn, 3); 5452153Sbp return ncp_request(connHandle, 21, conn); 5552153Sbp} 5652153Sbp 5752153SbpNWCCODE 5852153SbpNWBroadcastToConsole(NWCONN_HANDLE connHandle, pnstr8 message) { 5952153Sbp int l, error; 6052153Sbp DECLARE_RQ; 6152153Sbp 6252153Sbp l = strlen(message); 6352153Sbp if (l > 60) return EMSGSIZE; 6452153Sbp ncp_init_request_s(conn, 9); 6552153Sbp ncp_add_byte(conn, l); 6652153Sbp ncp_add_mem_nls(conn, message, l); 6752153Sbp error = ncp_request(connHandle, 21, conn); 6852153Sbp return error; 6952153Sbp} 7052153Sbp 7152153SbpNWCCODE 7252153SbpNWSendBroadcastMessage(NWCONN_HANDLE connHandle, pnstr8 message, 7352153Sbp nuint16 connCount, pnuint16 connList, pnuint8 resultList) 7452153Sbp{ 7552153Sbp int l, i, error; 7652153Sbp DECLARE_RQ; 7752153Sbp 7852153Sbp l = strlen(message); 7952153Sbp if (l > 255) return EMSGSIZE; 8052153Sbp if (connCount > 350) return EINVAL; 8152153Sbp 8252153Sbp ncp_init_request_s(conn, 0x0A); 8352153Sbp ncp_add_word_lh(conn, connCount); 8452153Sbp for (i = 0; i < connCount; i++) 8552153Sbp ncp_add_dword_lh(conn, connList[i]); 8652153Sbp ncp_add_byte(conn, l); 8752153Sbp ncp_add_mem_nls(conn, message, l); 8852153Sbp error = ncp_request(connHandle, 0x15, conn); 8952153Sbp if (!error) { 9052153Sbp l = ncp_reply_word_lh(conn, 0); 9152153Sbp for (i = 0; i < l; i++) 9252153Sbp resultList[i] = ncp_reply_dword_lh(conn, (i)*4 + 2); 9352153Sbp return 0; 9452153Sbp } 9552153Sbp if (error != 0xfb) return error; 9652153Sbp if (l > 58) return EMSGSIZE; 9752153Sbp ncp_init_request_s(conn, 0); 9852153Sbp ncp_add_byte(conn, connCount); 9952153Sbp for (i = 0; i < connCount; i++) 10052153Sbp ncp_add_byte(conn, connList[i]); 10152153Sbp ncp_add_byte(conn, l); 10252153Sbp ncp_add_mem_nls(conn, message, l); 10352153Sbp error = ncp_request(connHandle, 0x15, conn); 10452153Sbp if (error) return error; 10552153Sbp i = ncp_reply_byte(conn, 0); 10652153Sbp memcpy(resultList, ncp_reply_data(conn, 1), i); 10752153Sbp return 0; 10852153Sbp} 10952153Sbp 11052153Sbp 11152153SbpNWCCODE 11252153SbpNWGetBroadcastMessage(NWCONN_HANDLE connHandle, pnstr8 message) { 11352153Sbp int i, error; 11452153Sbp DECLARE_RQ; 11552153Sbp 11652153Sbp ncp_init_request_s(conn, 0x0B); 11752153Sbp error = ncp_request(connHandle, 0x15, conn); 11852153Sbp if (error) { 11952153Sbp if (error != 0x89fb) return error; 12052153Sbp ncp_init_request_s(conn, 0x01); 12152153Sbp if ((error = ncp_request(connHandle, 0x15, conn)) != 0) 12252153Sbp return error; 12352153Sbp } 12452153Sbp i = ncp_reply_byte(conn, 0); 12552153Sbp if (i == 0) return ENOENT; 12652153Sbp memcpy(message, ncp_reply_data(conn, 1), i); 12752153Sbp message[i] = 0; 12852153Sbp ncp_nls_str_n2u(message, message); 12952153Sbp return 0; 13052153Sbp} 131