2 * Copyright (c) 1999, Boris Popov
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Boris Popov.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * calls that don't fit to any other category
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
38 #include <sys/types.h>
40 #include <arpa/inet.h>
46 #include <netncp/ncp_lib.h>
49 ncp_nw_to_ctime(struct nw_time_buffer *source) {
52 bzero(&u_time,sizeof(struct tm));
54 * XXX: NW 4.x tracks daylight automatically
57 u_time.tm_sec = source->second;
58 u_time.tm_min = source->minute;
59 u_time.tm_hour = source->hour;
60 u_time.tm_mday = source->day;
61 u_time.tm_mon = source->month - 1;
62 u_time.tm_year = source->year;
64 if (u_time.tm_year < 80) {
65 u_time.tm_year += 100;
67 return mktime(&u_time);
71 ncp_get_file_server_information(NWCONN_HANDLE connid,
72 struct ncp_file_server_info *target)
77 ncp_init_request_s(conn, 17);
78 if ((error = ncp_request(connid, 23, conn)) != 0)
80 memcpy(target, ncp_reply_data(conn, 0), sizeof(*target));
81 target->MaximumServiceConnections
82 = htons(target->MaximumServiceConnections);
83 target->ConnectionsInUse
84 = htons(target->ConnectionsInUse);
85 target->MaxConnectionsEverUsed
86 = htons(target->MaxConnectionsEverUsed);
87 target->NumberMountedVolumes
88 = htons(target->NumberMountedVolumes);
93 ncp_get_stations_logged_info(NWCONN_HANDLE connid, u_int32_t connection,
94 struct ncp_bindery_object *target, time_t *login_time)
99 ncp_init_request_s(conn, 28);
100 ncp_add_dword_lh(conn, connection);
102 if ((error = ncp_request(connid, 23, conn)) != 0)
104 bzero(target, sizeof(*target));
105 target->object_id = ncp_reply_dword_hl(conn, 0);
106 target->object_type = ncp_reply_word_hl(conn, 4);
107 memcpy(target->object_name, ncp_reply_data(conn, 6),
108 sizeof(target->object_name));
109 *login_time = ncp_nw_to_ctime((struct nw_time_buffer *)ncp_reply_data(conn, 54));
114 ncp_get_internet_address(NWCONN_HANDLE connid, u_int32_t connection,
115 struct ipx_addr *target, u_int8_t * conn_type)
120 ncp_init_request_s(conn, 26);
121 ncp_add_dword_lh(conn, connection);
122 error = ncp_request(connid, 23, conn);
123 if (error) return error;
124 bzero(target, sizeof(*target));
125 ipx_netlong(*target) = ncp_reply_dword_lh(conn, 0);
126 memcpy(&(target->x_host), ncp_reply_data(conn, 4), 6);
127 target->x_port = ncp_reply_word_lh(conn, 10);
128 *conn_type = ncp_reply_byte(conn, 12);
133 NWGetObjectConnectionNumbers(NWCONN_HANDLE connHandle,
134 pnstr8 pObjName, nuint16 objType,
135 pnuint16 pNumConns, pnuint16 pConnHandleList,
143 ncp_init_request_s(conn, 27);
144 ncp_add_dword_lh(conn, lastconn);
145 ncp_add_word_hl(conn, objType);
146 ncp_add_pstring(conn, pObjName);
147 if ((error = ncp_request(connHandle, 23, conn)) != 0) return error;
148 n = min(ncp_reply_byte(conn, 0), maxConns);
150 for (i = 0; i < n ; i++) {
151 *pConnHandleList++ = ncp_reply_dword_lh(conn, i * 4 + 1);
157 NWUnpackDateTime(nuint32 dateTime, NW_DATE *sDate, NW_TIME *sTime) {
158 NWUnpackDate(dateTime >> 16, sDate);
159 NWUnpackTime(dateTime & 0xffff, sTime);
163 NWUnpackDate(nuint16 date, NW_DATE *sDate) {
164 sDate->day = date & 0x1f;
165 sDate->month = (date >> 5) & 0xf;
166 sDate->year = ((date >> 9) & 0x7f) + 1980;
170 NWUnpackTime(nuint16 time, NW_TIME *sTime) {
171 sTime->seconds = time & 0x1f;
172 sTime->minutes = (time >> 5) & 0x3f;
173 sTime->hours = (time >> 11) & 0x1f;
177 NWPackDateTime(NW_DATE *sDate, NW_TIME *sTime) {
182 NWPackDate(NW_DATE *sDate) {
187 NWPackTime(NW_TIME *sTime) {
192 ncp_UnpackDateTime(nuint32 dateTime) {
197 NWUnpackDateTime(dateTime, &d, &t);
198 bzero(&u_time,sizeof(struct tm));
199 u_time.tm_isdst = -1;
200 u_time.tm_sec = t.seconds;
201 u_time.tm_min = t.minutes;
202 u_time.tm_hour = t.hours;
203 u_time.tm_mday = d.day;
204 u_time.tm_mon = d.month - 1;
205 u_time.tm_year = d.year - 1900;
207 return mktime(&u_time);
211 ncp_GetFileServerDateAndTime(NWCONN_HANDLE cH, time_t *target) {
215 ncp_init_request(conn);
216 if ((error = ncp_request(cH, 20, conn)) != 0)
218 *target = ncp_nw_to_ctime((struct nw_time_buffer *) ncp_reply_data(conn, 0));
223 ncp_SetFileServerDateAndTime(NWCONN_HANDLE cH, time_t * source) {
225 struct tm *utime = localtime(source);
228 year = utime->tm_year;
232 ncp_init_request_s(conn, 202);
233 ncp_add_byte(conn, year);
234 ncp_add_byte(conn, utime->tm_mon + 1);
235 ncp_add_byte(conn, utime->tm_mday);
236 ncp_add_byte(conn, utime->tm_hour);
237 ncp_add_byte(conn, utime->tm_min);
238 ncp_add_byte(conn, utime->tm_sec);
239 return ncp_request(cH, 23, conn);
243 NWDownFileServer(NWCONN_HANDLE cH, int force) {
246 ncp_init_request_s(conn, 211);
247 ncp_add_byte(conn, force ? 0 : 0xff);
248 return ncp_request(cH, 23, conn);
252 NWCloseBindery(NWCONN_HANDLE cH) {
255 ncp_init_request_s(conn, 68);
256 return ncp_request(cH, 23, conn);
260 NWOpenBindery(NWCONN_HANDLE cH) {
263 ncp_init_request_s(conn, 69);
264 return ncp_request(cH, 23, conn);
268 NWDisableTTS(NWCONN_HANDLE cH) {
271 ncp_init_request_s(conn, 207);
272 return ncp_request(cH, 23, conn);
276 NWEnableTTS(NWCONN_HANDLE cH) {
279 ncp_init_request_s(conn, 208);
280 return ncp_request(cH, 23, conn);
284 NWDisableFileServerLogin(NWCONN_HANDLE cH) {
287 ncp_init_request_s(conn, 203);
288 return ncp_request(cH, 23, conn);
292 NWEnableFileServerLogin(NWCONN_HANDLE cH) {
295 ncp_init_request_s(conn, 204);
296 return ncp_request(cH, 23, conn);