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. Neither the name of the author nor the names of any co-contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * calls that don't fit to any other category
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
35 #include <sys/types.h>
37 #include <arpa/inet.h>
43 #include <netncp/ncp_lib.h>
46 ncp_nw_to_ctime(struct nw_time_buffer *source) {
49 bzero(&u_time,sizeof(struct tm));
51 * XXX: NW 4.x tracks daylight automatically
54 u_time.tm_sec = source->second;
55 u_time.tm_min = source->minute;
56 u_time.tm_hour = source->hour;
57 u_time.tm_mday = source->day;
58 u_time.tm_mon = source->month - 1;
59 u_time.tm_year = source->year;
61 if (u_time.tm_year < 80) {
62 u_time.tm_year += 100;
64 return mktime(&u_time);
68 ncp_get_file_server_information(NWCONN_HANDLE connid,
69 struct ncp_file_server_info *target)
74 ncp_init_request_s(conn, 17);
75 if ((error = ncp_request(connid, 23, conn)) != 0)
77 memcpy(target, ncp_reply_data(conn, 0), sizeof(*target));
78 target->MaximumServiceConnections
79 = htons(target->MaximumServiceConnections);
80 target->ConnectionsInUse
81 = htons(target->ConnectionsInUse);
82 target->MaxConnectionsEverUsed
83 = htons(target->MaxConnectionsEverUsed);
84 target->NumberMountedVolumes
85 = htons(target->NumberMountedVolumes);
90 ncp_get_stations_logged_info(NWCONN_HANDLE connid, u_int32_t connection,
91 struct ncp_bindery_object *target, time_t *login_time)
96 ncp_init_request_s(conn, 28);
97 ncp_add_dword_lh(conn, connection);
99 if ((error = ncp_request(connid, 23, conn)) != 0)
101 bzero(target, sizeof(*target));
102 target->object_id = ncp_reply_dword_hl(conn, 0);
103 target->object_type = ncp_reply_word_hl(conn, 4);
104 memcpy(target->object_name, ncp_reply_data(conn, 6),
105 sizeof(target->object_name));
106 *login_time = ncp_nw_to_ctime((struct nw_time_buffer *)ncp_reply_data(conn, 54));
111 ncp_get_internet_address(NWCONN_HANDLE connid, u_int32_t connection,
112 struct ipx_addr *target, u_int8_t * conn_type)
117 ncp_init_request_s(conn, 26);
118 ncp_add_dword_lh(conn, connection);
119 error = ncp_request(connid, 23, conn);
120 if (error) return error;
121 bzero(target, sizeof(*target));
122 ipx_netlong(*target) = ncp_reply_dword_lh(conn, 0);
123 memcpy(&(target->x_host), ncp_reply_data(conn, 4), 6);
124 target->x_port = ncp_reply_word_lh(conn, 10);
125 *conn_type = ncp_reply_byte(conn, 12);
130 NWGetObjectConnectionNumbers(NWCONN_HANDLE connHandle,
131 pnstr8 pObjName, nuint16 objType,
132 pnuint16 pNumConns, pnuint16 pConnHandleList,
140 ncp_init_request_s(conn, 27);
141 ncp_add_dword_lh(conn, lastconn);
142 ncp_add_word_hl(conn, objType);
143 ncp_add_pstring(conn, pObjName);
144 if ((error = ncp_request(connHandle, 23, conn)) != 0) return error;
145 n = min(ncp_reply_byte(conn, 0), maxConns);
147 for (i = 0; i < n ; i++) {
148 *pConnHandleList++ = ncp_reply_dword_lh(conn, i * 4 + 1);
154 NWUnpackDateTime(nuint32 dateTime, NW_DATE *sDate, NW_TIME *sTime) {
155 NWUnpackDate(dateTime >> 16, sDate);
156 NWUnpackTime(dateTime & 0xffff, sTime);
160 NWUnpackDate(nuint16 date, NW_DATE *sDate) {
161 sDate->day = date & 0x1f;
162 sDate->month = (date >> 5) & 0xf;
163 sDate->year = ((date >> 9) & 0x7f) + 1980;
167 NWUnpackTime(nuint16 time, NW_TIME *sTime) {
168 sTime->seconds = time & 0x1f;
169 sTime->minutes = (time >> 5) & 0x3f;
170 sTime->hours = (time >> 11) & 0x1f;
174 NWPackDateTime(NW_DATE *sDate, NW_TIME *sTime) {
179 NWPackDate(NW_DATE *sDate) {
184 NWPackTime(NW_TIME *sTime) {
189 ncp_UnpackDateTime(nuint32 dateTime) {
194 NWUnpackDateTime(dateTime, &d, &t);
195 bzero(&u_time,sizeof(struct tm));
196 u_time.tm_isdst = -1;
197 u_time.tm_sec = t.seconds;
198 u_time.tm_min = t.minutes;
199 u_time.tm_hour = t.hours;
200 u_time.tm_mday = d.day;
201 u_time.tm_mon = d.month - 1;
202 u_time.tm_year = d.year - 1900;
204 return mktime(&u_time);
208 ncp_GetFileServerDateAndTime(NWCONN_HANDLE cH, time_t *target) {
212 ncp_init_request(conn);
213 if ((error = ncp_request(cH, 20, conn)) != 0)
215 *target = ncp_nw_to_ctime((struct nw_time_buffer *) ncp_reply_data(conn, 0));
220 ncp_SetFileServerDateAndTime(NWCONN_HANDLE cH, time_t * source) {
222 struct tm *utime = localtime(source);
225 year = utime->tm_year;
229 ncp_init_request_s(conn, 202);
230 ncp_add_byte(conn, year);
231 ncp_add_byte(conn, utime->tm_mon + 1);
232 ncp_add_byte(conn, utime->tm_mday);
233 ncp_add_byte(conn, utime->tm_hour);
234 ncp_add_byte(conn, utime->tm_min);
235 ncp_add_byte(conn, utime->tm_sec);
236 return ncp_request(cH, 23, conn);
240 NWDownFileServer(NWCONN_HANDLE cH, int force) {
243 ncp_init_request_s(conn, 211);
244 ncp_add_byte(conn, force ? 0 : 0xff);
245 return ncp_request(cH, 23, conn);
249 NWCloseBindery(NWCONN_HANDLE cH) {
252 ncp_init_request_s(conn, 68);
253 return ncp_request(cH, 23, conn);
257 NWOpenBindery(NWCONN_HANDLE cH) {
260 ncp_init_request_s(conn, 69);
261 return ncp_request(cH, 23, conn);
265 NWDisableTTS(NWCONN_HANDLE cH) {
268 ncp_init_request_s(conn, 207);
269 return ncp_request(cH, 23, conn);
273 NWEnableTTS(NWCONN_HANDLE cH) {
276 ncp_init_request_s(conn, 208);
277 return ncp_request(cH, 23, conn);
281 NWDisableFileServerLogin(NWCONN_HANDLE cH) {
284 ncp_init_request_s(conn, 203);
285 return ncp_request(cH, 23, conn);
289 NWEnableFileServerLogin(NWCONN_HANDLE cH) {
292 ncp_init_request_s(conn, 204);
293 return ncp_request(cH, 23, conn);