Subversion Repositories Kolibri OS

Rev

Rev 5201 | Rev 5984 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5201 Rev 5565
Line 1... Line 1...
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
2
;;                                                                 ;;
3
;; Copyright (C) KolibriOS team 2004-2013. All rights reserved.    ;;
3
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved.    ;;
4
;; Distributed under terms of the GNU General Public License       ;;
4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                                 ;;
5
;;                                                                 ;;
6
;;  STACK.INC                                                      ;;
6
;;  STACK.INC                                                      ;;
7
;;                                                                 ;;
7
;;                                                                 ;;
8
;;  TCP/IP stack for KolibriOS                                     ;;
8
;;  TCP/IP stack for KolibriOS                                     ;;
Line 19... Line 19...
19
;;          GNU GENERAL PUBLIC LICENSE                             ;;
19
;;          GNU GENERAL PUBLIC LICENSE                             ;;
20
;;             Version 2, June 1991                                ;;
20
;;             Version 2, June 1991                                ;;
21
;;                                                                 ;;
21
;;                                                                 ;;
22
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
22
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 23... Line 23...
23
 
23
 
Line 24... Line 24...
24
$Revision: 5201 $
24
$Revision: 5565 $
25
 
25
 
26
uglobal
26
uglobal
27
        net_10ms        dd ?
27
        net_10ms        dd ?
Line 28... Line 28...
28
        net_tmr_count   dw ?
28
        net_tmr_count   dw ?
29
endg
29
endg
Line 30... Line 30...
30
 
30
 
-
 
31
DEBUG_NETWORK_ERROR     = 1
-
 
32
DEBUG_NETWORK_VERBOSE   = 0
31
DEBUG_NETWORK_ERROR     = 1
33
 
Line 32... Line 34...
32
DEBUG_NETWORK_VERBOSE   = 0
34
NET_DEVICES_MAX         = 16
33
 
35
NET_BUFFERS             = 512
34
NET_DEVICES_MAX         = 16
36
NET_BUFFER_SIZE         = 2048
Line 144... Line 146...
144
NET_DEVICE_LOOPBACK     = 0
146
NET_DEVICE_LOOPBACK     = 0
145
NET_DEVICE_ETH          = 1
147
NET_DEVICE_ETH          = 1
146
NET_DEVICE_SLIP         = 2
148
NET_DEVICE_SLIP         = 2
Line 147... Line 149...
147
 
149
 
148
; Network link types (link protocols)
150
; Network link types (link protocols)
149
NET_LINK_LOOPBACK       = 0     ;;; Really a link type?
151
NET_LINK_LOOPBACK       = 0
150
NET_LINK_MAC            = 1     ; Media access control (ethernet, isdn, ...)
152
NET_LINK_MAC            = 1     ; Media access control (ethernet, isdn, ...)
151
NET_LINK_PPP            = 2     ; Point to Point Protocol (PPPoE, ...)
153
NET_LINK_PPP            = 2     ; Point to Point Protocol (PPPoE, ...)
Line 152... Line 154...
152
NET_LINK_IEEE802.11     = 3     ; IEEE 802.11 (WiFi)
154
NET_LINK_IEEE802.11     = 3     ; IEEE 802.11 (WiFi)
153
 
155
 
154
; Hardware acceleration bits
156
; Hardware acceleration bits
Line -... Line 157...
-
 
157
NET_HWACC_TCP_IPv4_IN   = 1 shl 0
-
 
158
NET_HWACC_TCP_IPv4_OUT  = 1 shl 1
-
 
159
 
-
 
160
; Network frame types
155
NET_HWACC_TCP_IPv4_IN   = 1 shl 0
161
NET_BUFF_LOOPBACK      = 0
Line 156... Line 162...
156
NET_HWACC_TCP_IPv4_OUT  = 1 shl 1
162
NET_BUFF_ETH           = 1
157
 
163
 
158
struct  NET_DEVICE
164
struct  NET_DEVICE
Line 173... Line 179...
173
        link_state      dd ?    ; link state (0 = no link)
179
        link_state      dd ?    ; link state (0 = no link)
174
        hwacc           dd ?    ; bitmask stating enabled HW accelerations (offload engines)
180
        hwacc           dd ?    ; bitmask stating enabled HW accelerations (offload engines)
Line 175... Line 181...
175
 
181
 
Line -... Line 182...
-
 
182
ends
-
 
183
 
-
 
184
struct  NET_BUFF
-
 
185
 
-
 
186
        NextPtr         dd ?    ; pointer to next frame in list
-
 
187
        PrevPtr         dd ?    ; pointer to previous frame in list
-
 
188
        device          dd ?    ; ptr to NET_DEVICE structure
-
 
189
        type            dd ?    ; encapsulation type: e.g. Ethernet
-
 
190
        length          dd ?    ; size of encapsulated data
-
 
191
        offset          dd ?    ; offset to actual data (24 bytes for default frame)
-
 
192
        data            rb 0
-
 
193
 
Line 176... Line 194...
176
ends
194
ends
177
 
195
 
178
 
196
 
179
; Exactly as it says..
197
; Exactly as it says..
Line 227... Line 245...
227
align 4
245
align 4
Line 228... Line 246...
228
 
246
 
229
        NET_RUNNING     dd  ?
247
        NET_RUNNING     dd ?
Line -... Line 248...
-
 
248
        NET_DRV_LIST    rd NET_DEVICES_MAX
-
 
249
 
-
 
250
        NET_BUFFS_FREE  rd NET_BUFFERS
230
        NET_DRV_LIST    rd  NET_DEVICES_MAX
251
        .current        dd ?
Line 231... Line 252...
231
 
252
 
232
endg
253
endg
Line 243... Line 264...
243
;
264
;
244
;-----------------------------------------------------------------
265
;-----------------------------------------------------------------
245
align 4
266
align 4
246
stack_init:
267
stack_init:
Line -... Line 268...
-
 
268
 
-
 
269
; allocate network buffers
-
 
270
        stdcall kernel_alloc, NET_BUFFER_SIZE*NET_BUFFERS
-
 
271
        test    eax, eax
-
 
272
        jz      .fail
-
 
273
 
-
 
274
        mov     edi, NET_BUFFS_FREE
-
 
275
        mov     ecx, NET_BUFFERS
-
 
276
        cld
-
 
277
  .loop:
-
 
278
        stosd
-
 
279
        add     eax, NET_BUFFER_SIZE
-
 
280
        dec     ecx
-
 
281
        jnz     .loop
-
 
282
 
-
 
283
        mov     eax, NET_BUFFS_FREE
-
 
284
        stosd
247
 
285
 
248
; Init the network drivers list
286
; Init the network drivers list
249
        xor     eax, eax
287
        xor     eax, eax
250
        mov     edi, NET_RUNNING
288
        mov     edi, NET_RUNNING
251
        mov     ecx, (NET_DEVICES_MAX + 2)
289
        mov     ecx, (NET_DEVICES_MAX + 1)
Line 252... Line 290...
252
        rep stosd
290
        rep stosd
Line 253... Line 291...
253
 
291
 
Line 266... Line 304...
266
        SOCKET_init
304
        SOCKET_init
Line 267... Line 305...
267
 
305
 
Line 268... Line 306...
268
        LOOP_init
306
        LOOP_init
-
 
307
 
Line -... Line 308...
-
 
308
        mov     [net_tmr_count], 0
-
 
309
        ret
269
 
310
 
Line 270... Line 311...
270
        mov     [net_tmr_count], 0
311
  .fail:
Line 325... Line 366...
325
  .exit:
366
  .exit:
326
        ret
367
        ret
Line 327... Line 368...
327
 
368
 
-
 
369
 
-
 
370
align 4
-
 
371
proc NET_BUFF_alloc stdcall, buffersize
-
 
372
        cmp     [buffersize], NET_BUFFER_SIZE
-
 
373
        ja      .too_large
-
 
374
 
-
 
375
        spin_lock_irqsave
-
 
376
 
-
 
377
        mov     eax, [NET_BUFFS_FREE.current]
-
 
378
        cmp     eax, NET_BUFFS_FREE+NET_BUFFERS*4
-
 
379
        jae     .out_of_mem
-
 
380
        mov     eax, [eax]
-
 
381
        add     [NET_BUFFS_FREE.current], 4
-
 
382
 
-
 
383
        spin_unlock_irqrestore
-
 
384
 
-
 
385
        DEBUGF  DEBUG_NETWORK_VERBOSE, "net alloc: 0x%x\n", eax
328
 
386
        ret
-
 
387
 
-
 
388
  .out_of_mem:
-
 
389
        spin_unlock_irqrestore
-
 
390
 
-
 
391
        xor     eax, eax
-
 
392
        DEBUGF  DEBUG_NETWORK_ERROR, "NET_BUFF_alloc: out of mem!\n"
-
 
393
        ret
-
 
394
 
-
 
395
  .too_large:
-
 
396
        xor     eax, eax
-
 
397
        DEBUGF  DEBUG_NETWORK_ERROR, "NET_BUFF_alloc: too large!\n"
-
 
398
        ret
-
 
399
endp
-
 
400
 
-
 
401
 
-
 
402
align 4
-
 
403
proc NET_BUFF_free stdcall, buffer
-
 
404
 
-
 
405
        DEBUGF  DEBUG_NETWORK_VERBOSE, "net free: 0x%x\n", [buffer]
-
 
406
 
-
 
407
        spin_lock_irqsave
-
 
408
 
-
 
409
        sub     [NET_BUFFS_FREE.current], 4
329
align 4
410
        mov     eax, [NET_BUFFS_FREE.current]
-
 
411
        push    [buffer]
330
NET_packet_free:
412
        pop     dword[eax]
-
 
413
 
-
 
414
        spin_unlock_irqrestore
-
 
415
 
Line 331... Line 416...
331
        and     dword[esp+4], not 0xfff
416
        ret
332
        jmp     kernel_free
417
endp
Line 480... Line 565...
480
        ret
565
        ret
Line 481... Line 566...
481
 
566
 
482
align 4
567
align 4
Line 483... Line 568...
483
NET_ptr_to_num4:                ; Todo, place number in device structure so we only need to verify?
568
NET_ptr_to_num4:                ; Todo, place number in device structure so we only need to verify?
-
 
569
 
Line -... Line 570...
-
 
570
        test    ebx, ebx
484
 
571
        jz      .fail
485
        push    ecx
572
 
486
 
573
        push    ecx
487
        mov     ecx, NET_DEVICES_MAX
574
        mov     ecx, NET_DEVICES_MAX
488
        mov     edi, NET_DRV_LIST
575
        mov     edi, NET_DRV_LIST
489
  .loop:
576
  .loop:
490
        cmp     ebx, [edi]
577
        cmp     ebx, [edi]
491
        je      .found
578
        je      .found
Line 492... Line -...
492
        add     edi, 4
-
 
493
        dec     ecx
579
        add     edi, 4
-
 
580
        dec     ecx
-
 
581
        jnz     .loop
494
        jnz     .loop
582
 
Line 495... Line 583...
495
 
583
        pop     ecx
496
        or      edi, -1
584
  .fail:
497
        pop     ecx
585
        or      edi, -1