summaryrefslogtreecommitdiffstats
path: root/lib/libncp/ncpl_msg.c
blob: 5af2d72871857c61c5f312e815e975306890e0a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
 * Copyright (c) 1999, Boris Popov
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *    This product includes software developed by Boris Popov.
 * 4. Neither the name of the author nor the names of any co-contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");

#include <sys/types.h>
#include <errno.h>
#include <stdio.h>
#include <strings.h>

#include <netncp/ncp_lib.h>
#include <netncp/ncp_nls.h>

NWCCODE
NWDisableBroadcasts(NWCONN_HANDLE connHandle) {
	DECLARE_RQ;

	ncp_init_request_s(conn, 2);
	return ncp_request(connHandle, 21, conn);
}

NWCCODE
NWEnableBroadcasts(NWCONN_HANDLE connHandle) {
	DECLARE_RQ;

	ncp_init_request_s(conn, 3);
	return ncp_request(connHandle, 21, conn);
}

NWCCODE
NWBroadcastToConsole(NWCONN_HANDLE connHandle, pnstr8 message) {
	int l, error;
	DECLARE_RQ;

	l = strlen(message);
	if (l > 60) return EMSGSIZE;
	ncp_init_request_s(conn, 9);
	ncp_add_byte(conn, l);
	ncp_add_mem_nls(conn, message, l);
	error = ncp_request(connHandle, 21, conn);
	return error;
}

NWCCODE 
NWSendBroadcastMessage(NWCONN_HANDLE  connHandle, pnstr8 message,
	    nuint16 connCount, pnuint16 connList, pnuint8 resultList)
{
	int l, i, error;
	DECLARE_RQ;

	l = strlen(message);
	if (l > 255) return EMSGSIZE;
	if (connCount > 350) return EINVAL;
		
	ncp_init_request_s(conn, 0x0A);
	ncp_add_word_lh(conn, connCount);
	for (i = 0; i < connCount; i++)
		ncp_add_dword_lh(conn, connList[i]);
	ncp_add_byte(conn, l);
	ncp_add_mem_nls(conn, message, l);
	error = ncp_request(connHandle, 0x15, conn);
	if (!error) {
		l = ncp_reply_word_lh(conn, 0);
		for (i = 0; i < l; i++)
			resultList[i] =  ncp_reply_dword_lh(conn, (i)*4 + 2);
		return 0;
	}
	if (error != 0xfb) return error;
	if (l > 58) return EMSGSIZE;
	ncp_init_request_s(conn, 0);
	ncp_add_byte(conn, connCount);
	for (i = 0; i < connCount; i++)
		ncp_add_byte(conn, connList[i]);
	ncp_add_byte(conn, l);
	ncp_add_mem_nls(conn, message, l);
	error = ncp_request(connHandle, 0x15, conn);
	if (error) return error;
	i = ncp_reply_byte(conn, 0);
	memcpy(resultList, ncp_reply_data(conn, 1), i);
	return 0;
}


NWCCODE
NWGetBroadcastMessage(NWCONN_HANDLE connHandle, pnstr8 message) {
	int i, error;
	DECLARE_RQ;

	ncp_init_request_s(conn, 0x0B);
	error = ncp_request(connHandle, 0x15, conn);
	if (error) {
		if (error != 0x89fb) return error;
		ncp_init_request_s(conn, 0x01);
		if ((error = ncp_request(connHandle, 0x15, conn)) != 0) 
			return error;
	}
	i = ncp_reply_byte(conn, 0);
	if (i == 0) return ENOENT;
	memcpy(message, ncp_reply_data(conn, 1), i);
	message[i] = 0;
	ncp_nls_str_n2u(message, message);
	return 0;
}
OpenPOWER on IntegriCloud