Subversion Repositories Kolibri OS

Rev

Rev 1885 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1171 hidnplayr 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
1763 hidnplayr 3
;; Copyright (C) KolibriOS team 2004-2011. All rights reserved.    ;;
1171 hidnplayr 4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                                 ;;
6
;;  STACK.INC                                                      ;;
7
;;                                                                 ;;
1763 hidnplayr 8
;;  TCP/IP stack for KolibriOS                                     ;;
1171 hidnplayr 9
;;                                                                 ;;
10
;;    Written by hidnplayr@kolibrios.org                           ;;
11
;;                                                                 ;;
1763 hidnplayr 12
;;     Some parts of code are based on the work of:                ;;
13
;;      Mike Hibbett (menuetos network stack)                      ;;
14
;;      Eugen Brasoveanu (solar os network stack and drivers)      ;;
15
;;      mike.dld (kolibrios socket code)                           ;;
1171 hidnplayr 16
;;                                                                 ;;
1763 hidnplayr 17
;;     TCP part is based on 4.4BSD                                 ;;
18
;;                                                                 ;;
1171 hidnplayr 19
;;          GNU GENERAL PUBLIC LICENSE                             ;;
20
;;             Version 2, June 1991                                ;;
21
;;                                                                 ;;
22
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1159 hidnplayr 23
 
1206 hidnplayr 24
$Revision: 2220 $
1159 hidnplayr 25
 
1763 hidnplayr 26
__DEBUG_LEVEL_OLD__	equ __DEBUG_LEVEL__	; use seperate debug level for network part of kernel
27
__DEBUG_LEVEL__ 	equ 1
1473 hidnplayr 28
 
1159 hidnplayr 29
uglobal
1763 hidnplayr 30
	net_10ms	dd ?
31
	net_tmr_count	dw ?
1159 hidnplayr 32
endg
33
 
1259 hidnplayr 34
MAX_NET_DEVICES 	equ 16
1159 hidnplayr 35
 
1763 hidnplayr 36
MIN_EPHEMERAL_PORT	equ 49152
37
MAX_EPHEMERAL_PORT	equ 61000
1159 hidnplayr 38
 
1514 hidnplayr 39
; Ethernet protocol numbers
1519 hidnplayr 40
ETHER_ARP		equ 0x0608
1733 hidnplayr 41
ETHER_IPv4		equ 0x0008
1519 hidnplayr 42
ETHER_PPP_DISCOVERY	equ 0x6388
43
ETHER_PPP_SESSION	equ 0x6488
1185 hidnplayr 44
 
1514 hidnplayr 45
;Protocol family
1774 hidnplayr 46
AF_UNSPEC		equ 0
47
AF_UNIX 		equ 1
48
AF_INET4		equ 2
49
AF_INET6		equ 10
1159 hidnplayr 50
 
1514 hidnplayr 51
; Internet protocol numbers
1774 hidnplayr 52
IP_PROTO_IP		equ 0
53
IP_PROTO_ICMP		equ 1
54
IP_PROTO_TCP		equ 6
55
IP_PROTO_UDP		equ 17
1159 hidnplayr 56
 
1200 hidnplayr 57
; Socket types
1774 hidnplayr 58
SOCK_STREAM		equ 1
59
SOCK_DGRAM		equ 2
60
SOCK_RAW		equ 3
1200 hidnplayr 61
 
1514 hidnplayr 62
; Socket options
1885 hidnplayr 63
SO_ACCEPTCON		equ 1 shl 0
64
SO_BROADCAST		equ 1 shl 1
65
SO_DEBUG		equ 1 shl 2
66
SO_DONTROUTE		equ 1 shl 3
67
SO_KEEPALIVE		equ 1 shl 4
68
SO_OOBINLINE		equ 1 shl 5
69
SO_REUSEADDR		equ 1 shl 6
70
SO_REUSEPORT		equ 1 shl 7
71
SO_USELOOPBACK		equ 1 shl 8
1159 hidnplayr 72
 
1885 hidnplayr 73
 
1773 hidnplayr 74
; Socket States
1774 hidnplayr 75
SS_NOFDREF		equ 0x001	; no file table ref any more
76
SS_ISCONNECTED		equ 0x002	; socket connected to a peer
77
SS_ISCONNECTING 	equ 0x004	; in process of connecting to peer
78
SS_ISDISCONNECTING	equ 0x008	; in process of disconnecting
79
SS_CANTSENDMORE 	equ 0x010	; can't send more data to peer
80
SS_CANTRCVMORE		equ 0x020	; can't receive more data from peer
81
SS_RCVATMARK		equ 0x040	; at mark on input
82
SS_ISABORTING		equ 0x080	; aborting fd references - close()
83
SS_RESTARTSYS		equ 0x100	; restart blocked system calls
84
SS_ISDISCONNECTED	equ 0x800	; socket disconnected from peer
1773 hidnplayr 85
 
1774 hidnplayr 86
SS_ASYNC		equ 0x100	; async i/o notify
87
SS_ISCONFIRMING 	equ 0x200	; deciding to accept connection req
88
SS_MORETOCOME		equ 0x400
1773 hidnplayr 89
 
90
 
1774 hidnplayr 91
SOCKET_MAXDATA		equ 4096*32	; must be 4096*(power of 2) where 'power of 2' is at least 8
1254 hidnplayr 92
 
1514 hidnplayr 93
; Network driver types
1774 hidnplayr 94
NET_TYPE_ETH		equ 1
95
NET_TYPE_SLIP		equ 2
1254 hidnplayr 96
 
1774 hidnplayr 97
MAX_backlog		equ 20		; maximum backlog for stream sockets
1254 hidnplayr 98
 
1716 hidnplayr 99
; Error Codes
1774 hidnplayr 100
ENOBUFS 		equ 55
101
ECONNREFUSED		equ 61
102
ECONNRESET		equ 52
103
ETIMEDOUT		equ 60
104
ECONNABORTED		equ 53
1529 hidnplayr 105
 
1716 hidnplayr 106
 
107
 
1514 hidnplayr 108
virtual at 0
1254 hidnplayr 109
 
1514 hidnplayr 110
	NET_DEVICE:
1519 hidnplayr 111
 
112
	.type		dd ?	; Type field
113
	.mtu		dd ?	; Maximal Transmission Unit
114
	.name		dd ?	; Ptr to 0 terminated string
115
 
116
	.unload 	dd ?	; Ptrs to driver functions
117
	.reset		dd ?	;
118
	.transmit	dd ?	;
119
 
120
	.bytes_tx	dq ?	; Statistics, updated by the driver
121
	.bytes_rx	dq ?	;
122
	.packets_tx	dd ?	;
123
	.packets_rx	dd ?	;
124
 
1763 hidnplayr 125
;       .hwacc          dd ?    ; bitmask stating available hardware accelerations (offload engines)
1529 hidnplayr 126
 
1514 hidnplayr 127
	.end:
1254 hidnplayr 128
 
1514 hidnplayr 129
end virtual
1254 hidnplayr 130
 
131
 
1514 hidnplayr 132
; Exactly as it says..
1318 hidnplayr 133
macro pseudo_random reg {
134
	add	reg, [esp]
135
	rol	reg, 5
136
	xor	reg, [timer_ticks]
1529 hidnplayr 137
	add	reg, [CPU_FREQ]
1318 hidnplayr 138
	imul	reg, 214013
139
	xor	reg, 0xdeadbeef
140
	rol	reg, 9
1514 hidnplayr 141
}
1318 hidnplayr 142
 
1543 hidnplayr 143
macro ntohd reg {
1318 hidnplayr 144
 
1514 hidnplayr 145
	rol	word reg, 8
146
	rol	dword reg, 16
1529 hidnplayr 147
	rol	word reg , 8
1514 hidnplayr 148
 
1318 hidnplayr 149
}
150
 
1543 hidnplayr 151
macro ntohw reg {
1514 hidnplayr 152
 
153
	rol	word reg, 8
154
 
155
}
156
 
1159 hidnplayr 157
include "queue.inc"
1514 hidnplayr 158
 
159
include "ethernet.inc"
1719 hidnplayr 160
 
1514 hidnplayr 161
;include "slip.inc"
1719 hidnplayr 162
;include "pppoe.inc"
1514 hidnplayr 163
 
1187 hidnplayr 164
include "ARP.inc"
165
include "IPv4.inc"
1514 hidnplayr 166
 
167
include "icmp.inc"
168
include "udp.inc"
1249 hidnplayr 169
include "tcp.inc"
1159 hidnplayr 170
 
1514 hidnplayr 171
include "socket.inc"
172
 
173
 
174
 
175
align 4
176
uglobal
177
 
178
	NET_RUNNING	dd  ?
2220 hidnplayr 179
	NET_DRV_LIST	rd  (MAX_NET_DEVICES + 1)	; device 0 is a link to the default device
1514 hidnplayr 180
 
181
endg
182
 
183
 
1257 hidnplayr 184
;-----------------------------------------------------------------
1159 hidnplayr 185
;
186
; stack_init
187
;
188
;  This function calls all network init procedures
189
;
190
;  IN:  /
191
;  OUT: /
192
;
1257 hidnplayr 193
;-----------------------------------------------------------------
1159 hidnplayr 194
align 4
195
stack_init:
196
 
1514 hidnplayr 197
; Init the network drivers list
198
	xor	eax, eax
199
	mov	edi, NET_RUNNING
2220 hidnplayr 200
	mov	ecx, (MAX_NET_DEVICES + 2)
1514 hidnplayr 201
	rep	stosd
202
 
1529 hidnplayr 203
;        SLIP_init
204
;        PPPOE_init
1514 hidnplayr 205
 
1529 hidnplayr 206
	IPv4_init
207
	ICMP_init
1514 hidnplayr 208
 
1529 hidnplayr 209
	ARP_init
210
	UDP_init
211
	TCP_init
1514 hidnplayr 212
 
1529 hidnplayr 213
	SOCKET_init
1514 hidnplayr 214
 
215
	mov	[net_tmr_count], 0
1159 hidnplayr 216
 
217
	ret
218
 
219
 
1257 hidnplayr 220
;-----------------------------------------------------------------
1159 hidnplayr 221
;
222
; stack_handler
223
;
1514 hidnplayr 224
;  This function is called in kernel loop
1159 hidnplayr 225
;
226
;  IN:  /
227
;  OUT: /
228
;
1257 hidnplayr 229
;-----------------------------------------------------------------
1159 hidnplayr 230
align 4
231
stack_handler:
232
 
1514 hidnplayr 233
	cmp	[NET_RUNNING], 0
1257 hidnplayr 234
	je	.exit
1159 hidnplayr 235
 
1318 hidnplayr 236
	; Test for 10ms tick
1257 hidnplayr 237
	mov	eax, [timer_ticks]
1514 hidnplayr 238
	cmp	eax, [net_10ms]
1257 hidnplayr 239
	je	.exit
1514 hidnplayr 240
	mov	[net_10ms], eax
1159 hidnplayr 241
 
1519 hidnplayr 242
	test	[net_10ms], 0x0f	; 160ms
243
	jnz	.exit
1249 hidnplayr 244
 
1529 hidnplayr 245
	TCP_timer_160ms
1159 hidnplayr 246
 
1519 hidnplayr 247
	test	[net_10ms], 0x3f	; 640ms
248
	jnz	.exit
249
 
1529 hidnplayr 250
	TCP_timer_640ms
251
	ARP_decrease_entry_ttls
252
	IPv4_decrease_fragment_ttls
1159 hidnplayr 253
 
254
  .exit:
1257 hidnplayr 255
	ret
1159 hidnplayr 256
 
257
 
1514 hidnplayr 258
 
1249 hidnplayr 259
;-----------------------------------------------------------------
260
;
2220 hidnplayr 261
; NET_add_device:
1514 hidnplayr 262
;
263
;  This function is called by the network drivers,
264
;  to register each running NIC to the kernel
265
;
266
;  IN:  Pointer to device structure in ebx
267
;  OUT: Device num in eax, -1 on error
268
;
269
;-----------------------------------------------------------------
270
align 4
271
NET_add_device:
272
 
2220 hidnplayr 273
	DEBUGF	1,"NET_Add_Device: %x\n", ebx	;;; TODO: use mutex to lock net device list
1514 hidnplayr 274
 
275
	mov	eax, [NET_RUNNING]
276
	cmp	eax, MAX_NET_DEVICES
277
	jge	.error
278
 
279
;----------------------------------
280
; Check if device is already listed
281
	mov	eax, ebx
2220 hidnplayr 282
	mov	ecx, MAX_NET_DEVICES	; We need to check whole list because a device may be removed without re-organizing list
283
	mov	edi, NET_DRV_LIST+4
1514 hidnplayr 284
 
2220 hidnplayr 285
	repne	scasd			; See if device is already in the list
1514 hidnplayr 286
	jz	.error
287
 
288
;----------------------------
289
; Find empty slot in the list
290
	xor	eax, eax
291
	mov	ecx, MAX_NET_DEVICES
2220 hidnplayr 292
	mov	edi, NET_DRV_LIST+4
1514 hidnplayr 293
 
294
	repne	scasd
295
	jnz	.error
296
 
297
	sub	edi, 4
298
 
2220 hidnplayr 299
;-----------------------------
300
; Add device to the found slot
301
	mov	[edi], ebx		; add device to list
1514 hidnplayr 302
 
2220 hidnplayr 303
	mov	eax, edi		; Calculate device number in eax
304
	sub	eax, NET_DRV_LIST
305
	shr	eax, 2
1514 hidnplayr 306
 
2220 hidnplayr 307
	inc	[NET_RUNNING]		; Indicate that one more network device is up and running
1514 hidnplayr 308
 
2220 hidnplayr 309
	cmp	eax, 1			; If it's the first network device, try to set it as default
310
	jne	@f
311
	push	eax
312
	call	NET_set_default
313
	pop	eax
314
       @@:
1514 hidnplayr 315
 
2220 hidnplayr 316
	DEBUGF	1,"Device number: %u\n", eax
317
	ret
1514 hidnplayr 318
 
2220 hidnplayr 319
  .error:
320
	or	eax, -1
321
	DEBUGF	2,"Adding network device failed\n"
322
	ret
1514 hidnplayr 323
 
324
 
325
 
2220 hidnplayr 326
;-----------------------------------------------------------------
327
;
328
; NET_set_default
329
;
330
;  API to set the default interface
331
;
332
;  IN:  Device num in eax
333
;  OUT: Device num in eax, -1 on error
334
;
335
;-----------------------------------------------------------------
336
align 4
337
NET_set_default:
1514 hidnplayr 338
 
2220 hidnplayr 339
	DEBUGF	1,"NET_set_default %x\n", eax
1514 hidnplayr 340
 
2220 hidnplayr 341
	cmp	eax, MAX_NET_DEVICES
342
	jge	.error
1514 hidnplayr 343
 
2220 hidnplayr 344
	cmp	[NET_DRV_LIST+eax*4], 0
345
	je	.error
346
 
347
	push	[NET_DRV_LIST+eax*4]
348
	pop	[NET_DRV_LIST]
349
 
350
	DEBUGF	1,"Device number %u is now default!\n", eax
1514 hidnplayr 351
	ret
352
 
353
  .error:
354
	or	eax, -1
2220 hidnplayr 355
	DEBUGF	2,"Setting default network device failed\n"
1514 hidnplayr 356
	ret
357
 
358
 
359
;-----------------------------------------------------------------
360
;
361
; NET_Remove_Device:
362
;
363
;  This function is called by etwork drivers,
364
;  to unregister network devices from the kernel
2220 hidnplayr 365
;                                                                                                                                d
1514 hidnplayr 366
;  IN:  Pointer to device structure in ebx
367
;  OUT: eax: -1 on error
368
;
369
;-----------------------------------------------------------------
370
align 4
371
NET_remove_device:
372
 
373
	cmp	[NET_RUNNING], 0
374
	je	.error
375
 
2220 hidnplayr 376
	cmp	[NET_DRV_LIST], ebx
377
	jne	@f
378
	mov	[NET_DRV_LIST], 0
379
	cmp	[NET_RUNNING], 1
380
	je	@f
381
	; there are still active devices, find one and make it default
382
	xor	eax, eax
383
	mov	ecx, MAX_NET_DEVICES
384
	mov	edi, NET_DRV_LIST+4
385
	repe	scasd
386
	jz	@f
387
	push	dword [edi-4]
388
	pop	[NET_DRV_LIST]
389
       @@:
390
 
1514 hidnplayr 391
;----------------------------
392
; Find the driver in the list
393
 
394
	mov	eax, ebx
395
	mov	ecx, MAX_NET_DEVICES
2220 hidnplayr 396
	mov	edi, NET_DRV_LIST+4
1514 hidnplayr 397
 
398
	repne	scasd
399
	jnz	.error
400
 
401
;------------------------
402
; Remove it from the list
403
 
404
	xor	eax, eax
405
	mov	dword [edi-4], eax
406
 
407
	dec	[NET_RUNNING]
408
	ret
409
 
410
  .error:
411
	or	eax, -1
412
	ret
413
 
414
 
415
 
416
;-----------------------------------------------------------------
417
;
418
; NET_ptr_to_num
419
;
420
; IN:  ebx = ptr to device struct
421
; OUT: edi = -1 on error, device number otherwise
422
;
423
;-----------------------------------------------------------------
424
align 4
425
NET_ptr_to_num:
426
	push	ecx
427
 
428
	mov	ecx, MAX_NET_DEVICES
2220 hidnplayr 429
	mov	edi, NET_DRV_LIST+4
1514 hidnplayr 430
 
431
  .loop:
432
	cmp	ebx, [edi]
433
	jz	.found
434
	add	edi, 4
435
	dec	ecx
436
	jnz	.loop
437
 
438
	; repnz  scasd could work too if eax is used instead of ebx!
439
 
440
	or	edi, -1
441
 
442
	pop	ecx
443
	ret
444
 
445
  .found:
446
	sub	edi, NET_DRV_LIST
447
	shr	edi, 2
448
 
449
	pop	ecx
450
	ret
451
 
452
;-----------------------------------------------------------------
453
;
1249 hidnplayr 454
; checksum_1
455
;
1482 hidnplayr 456
;  This is the first of two functions needed to calculate a checksum.
1249 hidnplayr 457
;
1473 hidnplayr 458
;  IN:  edx = start offset for semi-checksum
1249 hidnplayr 459
;       esi = pointer to data
460
;       ecx = data size
461
;  OUT: edx = semi-checksum
462
;
1473 hidnplayr 463
;
464
; Code was optimized by diamond
465
;
1249 hidnplayr 466
;-----------------------------------------------------------------
467
align 4
468
checksum_1:
1159 hidnplayr 469
 
1249 hidnplayr 470
	shr	ecx, 1
471
	pushf
1473 hidnplayr 472
	jz	.no_2
1159 hidnplayr 473
 
1473 hidnplayr 474
	shr	ecx, 1
475
	pushf
476
	jz	.no_4
477
 
478
	shr	ecx, 1
479
	pushf
480
	jz	.no_8
481
 
482
  .loop:
483
	add	dl, [esi+1]
484
	adc	dh, [esi+0]
485
 
486
	adc	dl, [esi+3]
487
	adc	dh, [esi+2]
488
 
489
	adc	dl, [esi+5]
490
	adc	dh, [esi+4]
491
 
492
	adc	dl, [esi+7]
493
	adc	dh, [esi+6]
494
 
495
	adc	edx, 0
496
	add	esi, 8
497
 
498
	dec	ecx
499
	jnz	.loop
500
 
501
	adc	edx, 0
502
 
503
  .no_8:
1249 hidnplayr 504
	popf
1473 hidnplayr 505
	jnc	.no_4
506
 
507
	add	dl, [esi+1]
508
	adc	dh, [esi+0]
509
 
510
	adc	dl, [esi+3]
511
	adc	dh, [esi+2]
512
 
513
	adc	edx, 0
514
	add	esi, 4
515
 
516
  .no_4:
517
	popf
518
	jnc	.no_2
519
 
520
	add	dl, [esi+1]
521
	adc	dh, [esi+0]
522
 
523
	adc	edx, 0
1483 hidnplayr 524
	inc	esi
525
	inc	esi
1473 hidnplayr 526
 
527
  .no_2:
528
	popf
1249 hidnplayr 529
	jnc	.end
1159 hidnplayr 530
 
1473 hidnplayr 531
	add	dh, [esi+0]
1251 clevermous 532
	adc	edx, 0
1473 hidnplayr 533
  .end:
534
	ret
1159 hidnplayr 535
 
1249 hidnplayr 536
;-----------------------------------------------------------------
537
;
538
; checksum_2
539
;
540
;  This function calculates the final ip/tcp/udp checksum for you
541
;
542
;  IN:  edx = semi-checksum
543
;  OUT: dx = checksum (in INET byte order)
544
;
545
;-----------------------------------------------------------------
546
align 4
547
checksum_2:
548
 
549
	mov	ecx, edx
550
	shr	ecx, 16
551
	and	edx, 0xffff
552
	add	edx, ecx
553
 
1482 hidnplayr 554
	mov	ecx, edx
555
	shr	ecx, 16
1529 hidnplayr 556
	add	dx, cx
557
	test	dx, dx		; it seems that ZF is not set when CF is set :(
1249 hidnplayr 558
	not	dx
559
	jnz	.not_zero
560
	dec	dx
561
  .not_zero:
562
	xchg	dl, dh
563
 
1529 hidnplayr 564
	DEBUGF 1,"Checksum: %x\n", dx
1249 hidnplayr 565
 
566
	ret
567
 
568
 
569
 
1159 hidnplayr 570
;----------------------------------------------------------------
571
;
1171 hidnplayr 572
;  System function to work with network devices (73)
1159 hidnplayr 573
;
574
;----------------------------------------------------------------
575
align 4
576
sys_network:
577
 
1196 hidnplayr 578
	cmp	ebx, -1
579
	jne	@f
580
 
1514 hidnplayr 581
	mov	eax, [NET_RUNNING]
1196 hidnplayr 582
	jmp	.return
583
 
584
   @@:
2220 hidnplayr 585
	cmp	bh, MAX_NET_DEVICES		; Check if device number exists
1159 hidnplayr 586
	jge	.doesnt_exist
587
 
588
	mov	esi, ebx
589
	and	esi, 0x0000ff00
590
	shr	esi, 6
591
 
2220 hidnplayr 592
	cmp	dword [esi + NET_DRV_LIST], 0	; check if driver is running
1159 hidnplayr 593
	je	.doesnt_exist
594
 
2220 hidnplayr 595
 
596
 
597
	test	bl, bl			; 0 = Get device type (ethernet/token ring/...)
1159 hidnplayr 598
	jnz	@f
1514 hidnplayr 599
 
1192 hidnplayr 600
	xor	eax, eax
601
	jmp	.return
1159 hidnplayr 602
 
603
 
604
  @@:
605
	dec	bl			; 1 = Get device name
606
	jnz	@f
607
 
1514 hidnplayr 608
	mov	esi, [esi + NET_DRV_LIST]
1519 hidnplayr 609
	mov	esi, [esi + NET_DEVICE.name]
1159 hidnplayr 610
	mov	edi, ecx
611
 
612
	mov	ecx, 64 ; max length
613
	repnz	movsb
614
 
1192 hidnplayr 615
	xor	eax, eax
616
	jmp	.return
1159 hidnplayr 617
 
1192 hidnplayr 618
  @@:
1159 hidnplayr 619
 
1192 hidnplayr 620
	dec	bl			; 2 = Reset the device
621
	jnz	@f
622
 
1514 hidnplayr 623
	mov	esi, [esi + NET_DRV_LIST]
1519 hidnplayr 624
	call	[esi + NET_DEVICE.reset]
1192 hidnplayr 625
	jmp	.return
626
 
1159 hidnplayr 627
  @@:
1192 hidnplayr 628
 
629
	dec	bl			; 3 = Stop driver for this device
630
	jnz	@f
631
 
1514 hidnplayr 632
	mov	esi, [esi + NET_DRV_LIST]
1519 hidnplayr 633
	call	[esi + NET_DEVICE.unload]
1192 hidnplayr 634
	jmp	.return
635
 
636
  @@:
1249 hidnplayr 637
	dec	bl			; 4 = Get driver pointer
638
	jnz	@f
1192 hidnplayr 639
 
1249 hidnplayr 640
	; ..;
2220 hidnplayr 641
	xor	eax, eax
642
	jmp	.return
1249 hidnplayr 643
 
644
 
645
  @@:
2220 hidnplayr 646
	dec	bl			; 5 = Get driver name
647
	jnz	@f
1249 hidnplayr 648
 
2220 hidnplayr 649
	; ..;
650
	xor	eax, eax
651
	jmp	.return
652
 
653
 
654
  @@:
655
	dec	bl			; 6 = Set default device
656
	jnz	@f
657
 
658
	mov	eax, esi
659
	call	NET_set_default
660
	jmp	.return
661
 
662
 
663
  @@:
664
 
1159 hidnplayr 665
  .doesnt_exist:
666
	DEBUGF	1,"sys_network: invalid device/function specified!\n"
667
	mov	eax, -1
668
 
1192 hidnplayr 669
  .return:
670
	mov	[esp+28+4], eax
1159 hidnplayr 671
	ret
672
 
673
 
674
;----------------------------------------------------------------
675
;
1514 hidnplayr 676
;  System function to work with protocols  (75)
1159 hidnplayr 677
;
678
;----------------------------------------------------------------
679
align 4
680
sys_protocols:
681
	cmp	bh, MAX_NET_DEVICES		; Check if device number exists
682
	jge	.doesnt_exist
683
 
684
	mov	esi, ebx
685
	and	esi, 0x0000ff00
1514 hidnplayr 686
	shr	esi, 6				; now we have the device num * 4 in esi
687
	cmp	dword [esi + NET_DRV_LIST], 0	; check if driver is running
1159 hidnplayr 688
	je	.doesnt_exist
689
 
690
	push	.return 			; return address (we will be using jumps instead of calls)
691
 
692
	mov	eax, ebx			; set ax to protocol number
693
	shr	eax, 16 			;
694
 
695
	cmp	ax , IP_PROTO_IP
696
	je	IPv4_API
697
 
698
	cmp	ax , IP_PROTO_ICMP
699
	je	ICMP_API
700
 
701
	cmp	ax , IP_PROTO_UDP
702
	je	UDP_API
703
 
1171 hidnplayr 704
	cmp	ax , IP_PROTO_TCP
1254 hidnplayr 705
	je	TCP_API
1159 hidnplayr 706
 
1171 hidnplayr 707
	cmp	ax , ETHER_ARP
1159 hidnplayr 708
	je	ARP_API
709
 
1519 hidnplayr 710
	cmp	ax , 1337  ;;;;;
1159 hidnplayr 711
	je	ETH_API
712
 
1171 hidnplayr 713
	add	esp, 4				 ; if we reached here, no function was called, so we need to balance stack
1159 hidnplayr 714
 
715
  .doesnt_exist:
1519 hidnplayr 716
	DEBUGF	1,"sys_protocols: protocol %u doesnt exist on device %u!\n", ax, bh
1159 hidnplayr 717
	mov	eax, -1
718
 
719
  .return:
1171 hidnplayr 720
	mov	[esp+28+4], eax
1257 hidnplayr 721
	ret
1473 hidnplayr 722
 
723
 
724
__DEBUG_LEVEL__ equ __DEBUG_LEVEL_OLD__