1 /*
2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
12 */
13
14 /*
15 * $Source: /cvs/cvsroot/d2x/arch/dos/ipx.c,v $
16 * $Revision: 1.4 $
17 * $Author: bradleyb $
18 * $Date: 2001/10/19 10:46:06 $
19 *
20 * Routines for IPX communications.
21 *
22 * $Log: ipx.c,v $
23 * Revision 1.4 2001/10/19 10:46:06 bradleyb
24 * Re-import of d1x files
25 *
26 * Revision 1.2 2000/02/07 10:26:05 donut
27 * new ipx code structure reduces some redundancy and gives all arches multi netcode ability
28 *
29 * Revision 1.1.1.1 1999/06/14 21:58:22 donut
30 * Import of d1x 1.37 source.
31 *
32 * Revision 2.10 1995/03/29 17:27:55 john
33 * Added code to not duplicate broadcasts.
34 *
35 * Revision 2.9 1995/03/29 15:32:07 john
36 * NEatened.
37 *
38 * Revision 2.8 1995/03/29 15:07:31 john
39 * Added network support.
40 *
41 * Revision 2.7 1995/03/29 11:22:27 john
42 * Added broadcasting over a net.
43 *
44 * Revision 2.6 1995/03/28 20:05:03 john
45 * Took away alternate server stuff.
46 *
47 * Revision 2.5 1995/03/23 19:14:29 john
48 * Added better MAX_USERS message.
49 *
50 * Revision 2.4 1995/03/23 19:00:02 john
51 * Added user list capabitly.
52 *
53 * Revision 2.3 1995/03/23 12:27:05 john
54 * Move IPX into bios lib.
55 *
56 * Revision 2.2 1995/03/22 19:08:15 john
57 * Added code to fix sending packets over router... now
58 * we just need to make broadcasts go over router!!
59 *
60 * Revision 2.1 1995/03/21 08:40:16 john
61 * Ifdef'd out the NETWORK code.
62 *
63 * Revision 2.0 1995/02/27 11:30:45 john
64 * New version 2.0, which has no anonymous unions, builds with
65 * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
66 *
67 * Revision 1.31 1995/02/16 17:35:03 john
68 * Added code to allow dynamic socket changing.
69 *
70 * Revision 1.30 1995/02/01 21:03:45 john
71 * Lintified.
72 *
73 * Revision 1.29 1995/01/22 14:31:05 john
74 * Added key.h
75 *
76 * Revision 1.28 1995/01/22 14:29:26 john
77 * Added code to bypass broadcast messages.
78 *
79 * Revision 1.27 1995/01/03 13:46:16 john
80 * Added code that should make ipx work over different servers,
81 * but ifdef'd it out with SHAREWARE in ipx.c. I haven't tested
82 * this, and I hope it doesn't introduce net bugs.
83 *
84 * Revision 1.26 1994/12/14 11:54:37 rob
85 * Reduce # of ipx packets.
86 *
87 * Revision 1.25 1994/12/11 00:43:28 john
88 * Locked down DOS ipx buffers... probably not necessary, tho.
89 *
90 * Revision 1.24 1994/12/08 15:49:58 rob
91 * Bumped up the # of ipx packets.
92 *
93 * Revision 1.23 1994/12/04 15:23:54 rob
94 * Reduced packet # constants.
95 *
96 * Revision 1.22 1994/11/27 23:12:39 matt
97 * Made changes for new mprintf calling convention
98 *
99 * Revision 1.21 1994/11/19 15:15:19 mike
100 * remove unused code and data
101 *
102 * Revision 1.20 1994/11/10 11:06:07 rob
103 * Raised number of ipx packets to 64 and buffers to 128 (for 8-way games)
104 * Removed (commented out) all the spx support stuff.
105 *
106 * Revision 1.19 1994/11/07 17:50:12 rob
107 * Bumped up max_packets and ipx_num_packets to double their previous
108 * values.
109 *
110 * Revision 1.18 1994/11/07 15:39:01 rob
111 * Removed temporary hacked ipx_send_object function.
112 * Replaced with a more general thing.
113 *
114 * Revision 1.17 1994/11/05 16:08:40 rob
115 * Made a change necessary for object syncing on rejoin.
116 *
117 * Revision 1.16 1994/11/01 15:57:12 rob
118 * Added support for SPX sockets for critical messages.
119 *
120 * Revision 1.15 1994/10/31 19:21:01 rob
121 * Added a routine for sending objects via ipx. Its a hack and shoukld
122 * be replaced by something more general time permitting.
123 *
124 * Revision 1.14 1994/10/20 14:57:42 john
125 * Some test stuff.
126 *
127 * Revision 1.13 1994/10/20 11:22:45 john
128 * Tweaked the number of waiting packets. Added code to print
129 * total packets missed, and to limit the packet send rate to
130 * 10 packets per second unless firing.
131 *
132 * Revision 1.12 1994/10/03 20:50:11 john
133 * Started adding sound pause functions.
134 *
135 * Revision 1.11 1994/09/15 08:54:24 mike
136 * comment out a mprintf.
137 *
138 * Revision 1.10 1994/09/12 19:38:20 john
139 * Made some stuff that prints to the DOS screen go to the
140 * mono instead, since it really is debugging info.
141 *
142 * Revision 1.9 1994/09/07 13:32:03 john
143 * Made ipx_close explicitly close the socket we were using,
144 * because it seems that VLM's don't automatically close them
145 * like the older NETX stuff did (Going from Novell 3.11 driver
146 * to 3.12 anyway).
147 *
148 * Revision 1.8 1994/09/06 19:29:20 john
149 * Added trial version of rejoin function.
150 *
151 * Revision 1.7 1994/08/09 19:31:50 john
152 * Networking changes.
153 *
154 * Revision 1.6 1994/08/05 16:11:41 john
155 * Psuedo working version of networking.
156 *
157 * Revision 1.5 1994/08/04 19:17:21 john
158 * Inbetween version of network stuff.
159 *
160 * Revision 1.4 1994/07/29 16:08:57 john
161 * *** empty log message ***
162 *
163 * Revision 1.3 1994/07/25 12:33:31 john
164 * Network "pinging" in.
165 *
166 * Revision 1.2 1994/07/20 15:58:28 john
167 * First installment of ipx stuff.
168 *
169 * Revision 1.1 1994/07/19 15:42:00 john
170 * Initial revision
171 *
172 *
173 */
174
175 #ifdef HAVE_CONFIG_H
176 #include <conf.h>
177 #endif
178
179 #ifdef __GNUC__
180 #define _BORLAND_DOS_REGS 1
181 #define far
182 #endif
183
184 #include <i86.h>
185 #include <dos.h>
186 #include <stdio.h>
187 #include <string.h>
188 #include <malloc.h>
189 #include <stdlib.h>
190 #include <conio.h>
191 #include <assert.h>
192
193 #include "pstypes.h"
194 #include "timer.h"
195 #include "ipx.h"
196 #include "error.h"
197 #include "u_dpmi.h"
198 #include "key.h"
199 #include "ipx_drv.h"
200
201 typedef unsigned char BYTE;
202 typedef unsigned short WORD;
203 typedef unsigned long DWORD;
204
205 typedef struct local_address {
206 ubyte address[6];
207 } __pack__ local_address;
208
209 typedef struct net_address {
210 BYTE network_id[4];
211 local_address node_id;
212 WORD socket_id;
213 } __pack__ net_address;
214
215 typedef struct ipx_header {
216 WORD checksum;
217 WORD length;
218 BYTE transport_control;
219 BYTE packet_type;
220 net_address destination;
221 net_address source;
222 } __pack__ ipx_header;
223
224 typedef struct ecb_header {
225 WORD link[2];
226 WORD esr_address[2];
227 BYTE in_use;
228 BYTE completion_code;
229 WORD socket_id;
230 BYTE ipx_reserved[14];
231 WORD connection_id;
232 local_address immediate_address;
233 WORD fragment_count;
234 WORD fragment_pointer[2];
235 WORD fragment_size;
236 } __pack__ ecb_header;
237
238 typedef struct packet_data {
239 int packetnum;
240 byte data[IPX_MAX_DATA_SIZE];
241 } __pack__ packet_data;
242
243 typedef struct ipx_packet {
244 ecb_header ecb;
245 ipx_header ipx;
246 packet_data pd;
247 } __pack__ ipx_packet;
248
249 static int ipx_packetnum = 0;
250
251 #define MAX_PACKETS 64
252
253 static packet_data packet_buffers[MAX_PACKETS];
254 static short packet_free_list[MAX_PACKETS];
255 static int num_packets = 0;
256 static int largest_packet_index = 0;
257 static short packet_size[MAX_PACKETS];
258
259 WORD ipx_socket=0;
260 static ubyte ipx_installed=0;
261 WORD ipx_vector_segment;
262 WORD ipx_vector_offset;
263 ubyte ipx_socket_life = 0; // 0=closed at prog termination, 0xff=closed when requested.
264 //DWORD ipx_network = 0;
265 //local_address ipx_my_node;
266 #define ipx_my_node (ipx_MyAddress+4)
267 WORD ipx_num_packets=32; // 32 Ipx packets
268 ipx_packet * packets;
269 int neterrors = 0;
270 ushort ipx_packets_selector;
271
272 ecb_header * last_ecb=NULL;
273 int lastlen=0;
274
275 static void got_new_packet( ecb_header * ecb );
276 static void ipx_listen_for_packet(ecb_header * ecb );
277
free_packet(int id)278 static void free_packet( int id )
279 {
280 packet_buffers[id].packetnum = -1;
281 packet_free_list[ --num_packets ] = id;
282 if (largest_packet_index==id)
283 while ((--largest_packet_index>0) && (packet_buffers[largest_packet_index].packetnum == -1 ));
284 }
285
ipx_dos_get_packet_data(ubyte * data)286 static int ipx_dos_get_packet_data( ubyte * data )
287 {
288 int i, n, best, best_id, size;
289
290 for (i=1; i<ipx_num_packets; i++ ) {
291 if ( !packets[i].ecb.in_use ) {
292 got_new_packet( &packets[i].ecb );
293 packets[i].ecb.in_use = 0;
294 ipx_listen_for_packet(&packets[i].ecb);
295 }
296 }
297
298 best = -1;
299 n = 0;
300 best_id = -1;
301
302 for (i=0; i<=largest_packet_index; i++ ) {
303 if ( packet_buffers[i].packetnum > -1 ) {
304 n++;
305 if ( best == -1 || (packet_buffers[i].packetnum<best) ) {
306 best = packet_buffers[i].packetnum;
307 best_id = i;
308 }
309 }
310 }
311
312 //mprintf( (0, "Best id = %d, pn = %d, last_ecb = %x, len=%x, ne = %d\n", best_id, best, last_ecb, lastlen, neterrors ));
313 //mprintf( (1, "<%d> ", neterrors ));
314
315 if ( best_id < 0 ) return 0;
316
317 size = packet_size[best_id];
318 memcpy( data, packet_buffers[best_id].data, size );
319 free_packet(best_id);
320
321 return size;
322 }
323
324 #ifndef __GNUC__
swap_short(unsigned int short)325 unsigned int swap_short( unsigned int short )
326 #pragma aux swap_short parm [eax] = "xchg al,ah";
327 #else
328 static inline unsigned int swap_short( unsigned int sshort ) {
329 int __retval;
330 asm("xchg %%ah,%%al" : "=a" (__retval) : "a" (sshort));
331 return __retval;
332 }
333 #endif
334
335 static void got_new_packet( ecb_header * ecb )
336 {
337 ipx_packet * p;
338 int id;
339 unsigned short datasize;
340
341 datasize = 0;
342 last_ecb = ecb;
343 p = (ipx_packet *)ecb;
344
345 if ( p->ecb.in_use ) { neterrors++; return; }
346 if ( p->ecb.completion_code ) { neterrors++; return; }
347
348 // Error( "Recieve error %d for completion code", p->ecb.completion_code );
349
350 if ( memcmp( &p->ipx.source.node_id, ipx_my_node, 6 ) ) {
351 datasize=swap_short(p->ipx.length);
352 lastlen=datasize;
353 datasize -= sizeof(ipx_header);
354 // Find slot to put packet in...
355 if ( datasize > 0 && datasize <= sizeof(packet_data) ) {
356 if ( num_packets >= MAX_PACKETS ) {
357 //printf( 1, "IPX: Packet buffer overrun!!!\n" );
358 neterrors++;
359 return;
360 }
361 id = packet_free_list[ num_packets++ ];
362 if (id > largest_packet_index ) largest_packet_index = id;
363 packet_size[id] = datasize-sizeof(int);
364 packet_buffers[id].packetnum = p->pd.packetnum;
365 if ( packet_buffers[id].packetnum < 0 ) { neterrors++; return; }
366 memcpy( packet_buffers[id].data, p->pd.data, packet_size[id] );
367 } else {
368 neterrors++; return;
369 }
370 }
371 // Repost the ecb
372 p->ecb.in_use = 0;
373 //ipx_listen_for_packet(&p->ecb);
374 }
375
376 /*ubyte * ipx_get_my_local_address()
377 {
378 return ipx_my_node.address;
379 }
380
381 ubyte * ipx_get_my_server_address()
382 {
383 return (ubyte *)&ipx_network;
384 }*/
385
ipx_listen_for_packet(ecb_header * ecb)386 static void ipx_listen_for_packet(ecb_header * ecb )
387 {
388 dpmi_real_regs rregs;
389 ecb->in_use = 0x1d;
390 memset(&rregs,0,sizeof(dpmi_real_regs));
391 rregs.ebx = 4; // Listen For Packet function
392 rregs.esi = DPMI_real_offset(ecb);
393 rregs.es = DPMI_real_segment(ecb);
394 dpmi_real_int386x( 0x7A, &rregs );
395 }
396
397 /*static void ipx_cancel_listen_for_packet(ecb_header * ecb )
398 {
399 dpmi_real_regs rregs;
400 memset(&rregs,0,sizeof(dpmi_real_regs));
401 rregs.ebx = 6; // IPX Cancel event
402 rregs.esi = DPMI_real_offset(ecb);
403 rregs.es = DPMI_real_segment(ecb);
404 dpmi_real_int386x( 0x7A, &rregs );
405 }
406 */
407
ipx_send_packet(ecb_header * ecb)408 static void ipx_send_packet(ecb_header * ecb )
409 {
410 dpmi_real_regs rregs;
411 memset(&rregs,0,sizeof(dpmi_real_regs));
412 rregs.ebx = 3; // Send Packet function
413 rregs.esi = DPMI_real_offset(ecb);
414 rregs.es = DPMI_real_segment(ecb);
415 dpmi_real_int386x( 0x7A, &rregs );
416 }
417
418 typedef struct {
419 ubyte network[4];
420 ubyte node[6];
421 ubyte local_target[6];
422 } __pack__ net_xlat_info;
423
ipx_dos_get_local_target(ubyte * server,ubyte * node,ubyte * local_target)424 static void ipx_dos_get_local_target( ubyte * server, ubyte * node, ubyte * local_target )
425 {
426 net_xlat_info * info;
427 dpmi_real_regs rregs;
428
429 // Get dos memory for call...
430 info = (net_xlat_info *)dpmi_get_temp_low_buffer( sizeof(net_xlat_info) );
431 assert( info != NULL );
432 memcpy( info->network, server, 4 );
433 memcpy( info->node, node, 6 );
434
435 memset(&rregs,0,sizeof(dpmi_real_regs));
436
437 rregs.ebx = 2; // Get Local Target
438 rregs.es = DPMI_real_segment(info);
439 rregs.esi = DPMI_real_offset(info->network);
440 rregs.edi = DPMI_real_offset(info->local_target);
441
442 dpmi_real_int386x( 0x7A, &rregs );
443
444 // Save the local target...
445 memcpy( local_target, info->local_target, 6 );
446 }
447
ipx_dos_close()448 static void ipx_dos_close()
449 {
450 dpmi_real_regs rregs;
451 if ( ipx_installed ) {
452 // When using VLM's instead of NETX, the sockets don't
453 // seem to automatically get closed, so we must explicitly
454 // close them at program termination.
455 ipx_installed = 0;
456 memset(&rregs,0,sizeof(dpmi_real_regs));
457 rregs.edx = ipx_socket;
458 rregs.ebx = 1; // Close socket
459 dpmi_real_int386x( 0x7A, &rregs );
460 }
461 }
462
463
464 //---------------------------------------------------------------
465 // Initializes all IPX internals.
466 // If socket_number==0, then opens next available socket.
467 // Returns: 0 if successful.
468 // -1 if socket already open.
469 // -2 if socket table full.
470 // -3 if IPX not installed.
471 // -4 if couldn't allocate low dos memory
472 // -5 if error with getting internetwork address
473
ipx_dos_init(int socket_number)474 static int ipx_dos_init( int socket_number )
475 {
476 int show_address=0;
477 dpmi_real_regs rregs;
478 ubyte *ipx_real_buffer;
479 int i;
480
481 // atexit(ipx_close);
482
483 ipx_packetnum = 0;
484
485 // init packet buffers.
486 for (i=0; i<MAX_PACKETS; i++ ) {
487 packet_buffers[i].packetnum = -1;
488 packet_free_list[i] = i;
489 }
490 num_packets = 0;
491 largest_packet_index = 0;
492
493 // Get the IPX vector
494 memset(&rregs,0,sizeof(dpmi_real_regs));
495 rregs.eax=0x00007a00;
496 dpmi_real_int386x( 0x2f, &rregs );
497
498 if ( (rregs.eax & 0xFF) != 0xFF ) {
499 return 3;
500 }
501 ipx_vector_offset = rregs.edi & 0xFFFF;
502 ipx_vector_segment = rregs.es;
503 //printf( "IPX entry point at %.4x:%.4x\n", ipx_vector_segment, ipx_vector_offset );
504
505 // Open a socket for IPX
506
507 memset(&rregs,0,sizeof(dpmi_real_regs));
508 swab( (char *)&socket_number,(char *)&ipx_socket, 2 );
509 rregs.edx = ipx_socket;
510 rregs.eax = ipx_socket_life;
511 rregs.ebx = 0; // Open socket
512 dpmi_real_int386x( 0x7A, &rregs );
513
514 ipx_socket = rregs.edx & 0xFFFF;
515
516 if ( rregs.eax & 0xFF ) {
517 //mprintf( (1, "IPX error opening channel %d\n", socket_number-IPX_DEFAULT_SOCKET ));
518 return -2;
519 }
520
521 ipx_installed = 1;
522
523 // Find our internetwork address
524 ipx_real_buffer = dpmi_get_temp_low_buffer( 1024 ); // 1k block
525 if ( ipx_real_buffer == NULL ) {
526 //printf( "Error allocation realmode memory\n" );
527 return -4;
528 }
529
530 memset(&rregs,0,sizeof(dpmi_real_regs));
531 rregs.ebx = 9; // Get internetwork address
532 rregs.esi = DPMI_real_offset(ipx_real_buffer);
533 rregs.es = DPMI_real_segment(ipx_real_buffer);
534 dpmi_real_int386x( 0x7A, &rregs );
535
536 if ( rregs.eax & 0xFF ) {
537 //printf( "Error getting internetwork address!\n" );
538 return -2;
539 }
540
541 /* memcpy( &ipx_network, ipx_real_buffer, 4 );
542 memcpy( ipx_my_node, &ipx_real_buffer[4], 6 );*/
543 memcpy(ipx_MyAddress,ipx_real_buffer,10);
544
545 if ( show_address ) {
546 printf( "My IPX addresss is " );
547 printf( "%02X%02X%02X%02X/", ipx_real_buffer[0],ipx_real_buffer[1],ipx_real_buffer[2],ipx_real_buffer[3] );
548 printf( "%02X%02X%02X%02X%02X%02X\n", ipx_real_buffer[4],ipx_real_buffer[5],ipx_real_buffer[6],ipx_real_buffer[7],ipx_real_buffer[8],ipx_real_buffer[9] );
549 printf( "\n" );
550 }
551
552 packets = dpmi_real_malloc( sizeof(ipx_packet)*ipx_num_packets, &ipx_packets_selector );
553 if ( packets == NULL ) {
554 //printf( "Couldn't allocate real memory for %d packets\n", ipx_num_packets );
555 return -4;
556 }
557 #if 0 /* adb: not needed, fails with cwsdpmi */
558 if (!dpmi_lock_region( packets, sizeof(ipx_packet)*ipx_num_packets )) {
559 //printf( "Couldn't lock real memory for %d packets\n", ipx_num_packets );
560 return -4;
561 }
562 #endif
563 memset( packets, 0, sizeof(ipx_packet)*ipx_num_packets );
564
565 for (i=1; i<ipx_num_packets; i++ ) {
566 packets[i].ecb.in_use = 0x1d;
567 //packets[i].ecb.in_use = 0;
568 packets[i].ecb.socket_id = ipx_socket;
569 packets[i].ecb.fragment_count = 1;
570 packets[i].ecb.fragment_pointer[0] = DPMI_real_offset(&packets[i].ipx);
571 packets[i].ecb.fragment_pointer[1] = DPMI_real_segment(&packets[i].ipx);
572 packets[i].ecb.fragment_size = sizeof(ipx_packet)-sizeof(ecb_header); //-sizeof(ecb_header);
573
574 ipx_listen_for_packet(&packets[i].ecb);
575 }
576
577 packets[0].ecb.socket_id = ipx_socket;
578 packets[0].ecb.fragment_count = 1;
579 packets[0].ecb.fragment_pointer[0] = DPMI_real_offset(&packets[0].ipx);
580 packets[0].ecb.fragment_pointer[1] = DPMI_real_segment(&packets[0].ipx);
581 packets[0].ipx.packet_type = 4; // IPX packet
582 packets[0].ipx.destination.socket_id = ipx_socket;
583 // memcpy( packets[0].ipx.destination.network_id, &ipx_network, 4 );
584 memset( packets[0].ipx.destination.network_id, 0, 4 );
585
586 return 0;
587 }
588
ipx_dos_send_packet_data(ubyte * data,int datasize,ubyte * network,ubyte * address,ubyte * immediate_address)589 static void ipx_dos_send_packet_data( ubyte * data, int datasize, ubyte *network, ubyte *address, ubyte *immediate_address )
590 {
591 assert(ipx_installed);
592
593 if ( datasize >= IPX_MAX_DATA_SIZE ) {
594 printf( "Data too big\n" );
595 //added/replaced on 11/8/98 by Victor Rachels to stop crappage
596 return;
597 // exit(1);
598 //end this section replacement - VR
599 }
600
601 // Make sure no one is already sending something
602 while( packets[0].ecb.in_use )
603 {
604 }
605
606 if (packets[0].ecb.completion_code) {
607 // printf( "Send error %d for completion code\n", packets[0].ecb.completion_code );
608 //added/replaced on 11/8/98 by Victor Rachels to stop crappage
609 return;
610 // exit(1);
611 //end this section replacement - VR
612
613 }
614
615 // Fill in destination address
616 if ( memcmp( network, &ipx_network, 4 ) )
617 memcpy( packets[0].ipx.destination.network_id, network, 4 );
618 else
619 memset( packets[0].ipx.destination.network_id, 0, 4 );
620 memcpy( packets[0].ipx.destination.node_id.address, address, 6 );
621 memcpy( packets[0].ecb.immediate_address.address, immediate_address, 6 );
622 packets[0].pd.packetnum = ipx_packetnum++;
623
624 // Fill in data to send
625 packets[0].ecb.fragment_size = sizeof(ipx_header) + sizeof(int) + datasize;
626
627 assert( datasize > 1 );
628 assert( packets[0].ecb.fragment_size <= 576 );
629
630 memcpy( packets[0].pd.data, data, datasize );
631
632 // Send it
633 ipx_send_packet( &packets[0].ecb );
634
635 }
636
637 /*static int ipx_change_default_socket( ushort socket_number )
638 {
639 int i;
640 WORD new_ipx_socket;
641 dpmi_real_regs rregs;
642
643 if ( !ipx_installed ) return -3;
644
645 // Open a new socket
646 memset(&rregs,0,sizeof(dpmi_real_regs));
647 swab( (char *)&socket_number,(char *)&new_ipx_socket, 2 );
648 rregs.edx = new_ipx_socket;
649 rregs.eax = ipx_socket_life;
650 rregs.ebx = 0; // Open socket
651 dpmi_real_int386x( 0x7A, &rregs );
652
653 new_ipx_socket = rregs.edx & 0xFFFF;
654
655 if ( rregs.eax & 0xFF ) {
656 //printf( (1, "IPX error opening channel %d\n", socket_number-IPX_DEFAULT_SOCKET ));
657 return -2;
658 }
659
660 for (i=1; i<ipx_num_packets; i++ ) {
661 ipx_cancel_listen_for_packet(&packets[i].ecb);
662 }
663
664 // Close existing socket...
665 memset(&rregs,0,sizeof(dpmi_real_regs));
666 rregs.edx = ipx_socket;
667 rregs.ebx = 1; // Close socket
668 dpmi_real_int386x( 0x7A, &rregs );
669
670 ipx_socket = new_ipx_socket;
671
672 // Repost all listen requests on the new socket...
673 for (i=1; i<ipx_num_packets; i++ ) {
674 packets[i].ecb.in_use = 0;
675 packets[i].ecb.socket_id = ipx_socket;
676 ipx_listen_for_packet(&packets[i].ecb);
677 }
678
679 packets[0].ecb.socket_id = ipx_socket;
680 packets[0].ipx.destination.socket_id = ipx_socket;
681
682 ipx_packetnum = 0;
683 // init packet buffers.
684 for (i=0; i<MAX_PACKETS; i++ ) {
685 packet_buffers[i].packetnum = -1;
686 packet_free_list[i] = i;
687 }
688 num_packets = 0;
689 largest_packet_index = 0;
690
691 return 0;
692 }
693 */
694
695 struct ipx_driver ipx_dos = {
696 // NULL,
697 ipx_dos_init,
698 ipx_dos_close,
699 NULL,
700 NULL,
701 NULL,
702 NULL,
703 1,
704 ipx_dos_get_local_target,
705 ipx_dos_get_packet_data,
706 ipx_dos_send_packet_data
707 };
708
arch_ipx_set_driver(char * arg)709 struct ipx_driver * arch_ipx_set_driver(char *arg)
710 {
711 return &ipx_dos;
712 }
713
714
715 //---typedef struct rip_entry {
716 //--- uint network;
717 //--- ushort nhops;
718 //--- ushort nticks;
719 //---} rip_entry;
720 //---
721 //---typedef struct rip_packet {
722 //--- ushort operation; //1=request, 2=response
723 //--- rip_entry rip[50];
724 //---} rip_packet;
725 //---
726 //---
727 //---void ipx_find_all_servers()
728 //---{
729 //--- int i;
730 //--- rip_packet * rp;
731 //--- assert(ipx_installed);
732 //---
733 //--- ipx_change_default_socket( 0x0453 );
734 //--- // ipx_change_default_socket( 0x5304 );
735 //---
736 //--- // Make sure no one is already sending something
737 //--- while( packets[0].ecb.in_use )
738 //--- {
739 //--- }
740 //---
741 //--- if (packets[0].ecb.completion_code) {
742 //--- printf( "AAAA:Send error %d for completion code\n", packets[0].ecb.completion_code );
743 //--- //exit(1);
744 //--- }
745 //---
746 //--- rp = (rip_packet *)&packets[0].pd;
747 //---
748 //--- // Fill in destination address
749 //--- {
750 //--- char mzero1[] = {0,0,0,1};
751 //--- char mzero[] = {0,0,0,0,0,1};
752 //--- char immediate[6];
753 //--- //memcpy( packets[0].ipx.destination.network_id, &ipx_network, 4 );
754 //--- //memcpy( packets[0].ipx.destination.node_id.address, ipx_my_node.address, 6 );
755 //---
756 //--- memcpy( packets[0].ipx.destination.network_id, mzero1, 4 );
757 //--- memcpy( packets[0].ipx.destination.node_id.address, mzero, 6 );
758 //---
759 //--- memcpy( packets[0].ipx.destination.socket_id, &ipx_socket, 2 );
760 //--- memcpy( packets[0].ipx.source.network_id, &ipx_network, 4 );
761 //--- memcpy( packets[0].ipx.source.node_id.address, ipx_my_node.address, 6 );
762 //--- memcpy( packets[0].ipx.source.socket_id, &ipx_socket, 2 );
763 //--- //memcpy( packets[0].ecb.immediate_address.address, ipx_my_node.address, 6 );
764 //--- //mzero1[3] = 1;
765 //--- //memcpy( packets[0].ipx.destination.network_id, mzero1, 4 );
766 //--- //mzero[5] = 1;
767 //--- //memcpy( packets[0].ipx.destination.node_id.address, mzero, 6 );
768 //--- //ipx_get_local_target( mzero1, mzero, immediate );
769 //--- //memcpy( packets[0].ecb.immediate_address.address, mzero, 6 );
770 //--- //memcpy( packets[0].ecb.immediate_address.address, immediate, 6 );
771 //--- //mzero[5] = 0;
772 //--- }
773 //---
774 //--- packets[0].ipx.packet_type = 1; // RIP packet
775 //---
776 //--- // Fill in data to send
777 //--- packets[0].ecb.fragment_size = sizeof(ipx_header) + sizeof(rip_packet);
778 //--- assert( packets[0].ecb.fragment_size <= 576 );
779 //---
780 //--- rp->operation = 0; // Request
781 //--- for (i=0;i<50; i++) {
782 //--- rp->rip[i].network = 0xFFFFFFFF;
783 //--- rp->rip[i].nhops = 0;
784 //--- rp->rip[i].nticks = 0;
785 //--- }
786 //---
787 //--- // Send it
788 //--- ipx_send_packet( &packets[0].ecb );
789 //---
790 //--- for (i=0;i<50; i++) {
791 //--- if ( rp->rip[i].network != 0xFFFFFFFF )
792 //--- printf( "Network = %8x, Hops=%d, Ticks=%d\n", rp->rip[i].network, rp->rip[i].nhops, rp->rip[i].nticks );
793 //--- }
794 //---}
795 //---
796 //---
797