Rev 5522 | Rev 7678 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3545 | hidnplayr | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
5363 | yogev_ezra | 3 | ;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;; |
3545 | hidnplayr | 4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
||
6 | ;; ETHERNET.INC ;; |
||
7 | ;; ;; |
||
8 | ;; Ethernet network layer for KolibriOS ;; |
||
9 | ;; ;; |
||
10 | ;; Written by hidnplayr@kolibrios.org ;; |
||
11 | ;; ;; |
||
12 | ;; GNU GENERAL PUBLIC LICENSE ;; |
||
13 | ;; Version 2, June 1991 ;; |
||
14 | ;; ;; |
||
15 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
16 | |||
4850 | mario79 | 17 | $Revision: 6011 $ |
3545 | hidnplayr | 18 | |
19 | ETH_FRAME_MINIMUM = 60 |
||
3982 | hidnplayr | 20 | ETH_QUEUE_SIZE = 255 |
3545 | hidnplayr | 21 | |
22 | struct ETH_header |
||
23 | |||
24 | DstMAC dp ? ; destination MAC-address |
||
25 | SrcMAC dp ? ; source MAC-address |
||
26 | Type dw ? ; type of the upper-layer protocol |
||
27 | |||
28 | ends |
||
29 | |||
30 | struct ETH_DEVICE NET_DEVICE |
||
31 | |||
32 | mac dp ? |
||
33 | |||
34 | ends |
||
35 | |||
5522 | hidnplayr | 36 | iglobal |
37 | align 4 |
||
3982 | hidnplayr | 38 | |
5522 | hidnplayr | 39 | ETH_BROADCAST dp 0xffffffffffff |
3982 | hidnplayr | 40 | |
5522 | hidnplayr | 41 | ETH_frame_queued dd 0 ; Number of queued frames |
3982 | hidnplayr | 42 | |
5522 | hidnplayr | 43 | ETH_frame_head dd ETH_frame_head ; Pointer to next frame in the linked list |
44 | ETH_frame_tail dd ETH_frame_head ; Pointer to last frame in the linked list |
||
3545 | hidnplayr | 45 | |
46 | endg |
||
47 | |||
3982 | hidnplayr | 48 | uglobal |
49 | align 4 |
||
50 | ETH_input_event dd ? |
||
51 | endg |
||
52 | |||
6011 | hidnplayr | 53 | macro eth_init { |
3982 | hidnplayr | 54 | |
55 | movi ebx, 1 |
||
6011 | hidnplayr | 56 | mov ecx, eth_process_input |
3982 | hidnplayr | 57 | call new_sys_threads |
58 | test eax, eax |
||
59 | jns @f |
||
60 | DEBUGF DEBUG_NETWORK_ERROR,'K : cannot create kernel thread for ethernet, error %d\n', eax |
||
61 | @@: |
||
62 | |||
63 | } |
||
64 | |||
6011 | hidnplayr | 65 | ;-----------------------------------------------------------------; |
66 | ; ; |
||
67 | ; eth_input: This function is called by ethernet drivers. ; |
||
68 | ; Push the received ethernet packet onto the ethernet input queue.; |
||
69 | ; ; |
||
70 | ; IN: [esp] = Pointer to buffer ; |
||
71 | ; ; |
||
72 | ; OUT: / ; |
||
73 | ; ; |
||
74 | ;-----------------------------------------------------------------; |
||
3545 | hidnplayr | 75 | align 4 |
6011 | hidnplayr | 76 | eth_input: |
3545 | hidnplayr | 77 | |
5522 | hidnplayr | 78 | pop eax |
79 | pushf |
||
80 | cli |
||
3982 | hidnplayr | 81 | |
5522 | hidnplayr | 82 | cmp [ETH_frame_queued], ETH_QUEUE_SIZE |
83 | jae .full |
||
84 | inc [ETH_frame_queued] |
||
3982 | hidnplayr | 85 | |
5522 | hidnplayr | 86 | ; Add frame to the end of the linked list |
87 | mov [eax + NET_BUFF.NextPtr], ETH_frame_head |
||
88 | |||
89 | mov ebx, [ETH_frame_tail] |
||
90 | mov [eax + NET_BUFF.PrevPtr], ebx |
||
91 | |||
92 | mov [ETH_frame_tail], eax |
||
93 | mov [ebx + NET_BUFF.NextPtr], eax |
||
94 | |||
95 | popf |
||
96 | |||
97 | ; Now queue an event to process it |
||
3982 | hidnplayr | 98 | xor edx, edx |
99 | mov eax, [ETH_input_event] |
||
100 | mov ebx, [eax + EVENT.id] |
||
101 | xor esi, esi |
||
102 | call raise_event |
||
103 | |||
104 | ret |
||
105 | |||
5522 | hidnplayr | 106 | .full: |
4511 | hidnplayr | 107 | DEBUGF DEBUG_NETWORK_ERROR, "ETH incoming queue is full, discarding packet!\n" |
5522 | hidnplayr | 108 | popf |
109 | push eax |
||
6011 | hidnplayr | 110 | call net_buff_free |
3982 | hidnplayr | 111 | ret |
112 | |||
113 | |||
114 | |||
6011 | hidnplayr | 115 | ;-----------------------------------------------------------------; |
116 | ; ; |
||
117 | ; eth_process_input: Process packets from ethernet input queue. ; |
||
118 | ; ; |
||
119 | ; IN: / ; |
||
120 | ; ; |
||
121 | ; OUT: / ; |
||
122 | ; ; |
||
123 | ;-----------------------------------------------------------------; |
||
3982 | hidnplayr | 124 | align 4 |
6011 | hidnplayr | 125 | eth_process_input: |
3982 | hidnplayr | 126 | |
127 | xor esi, esi |
||
128 | mov ecx, MANUAL_DESTROY |
||
129 | call create_event |
||
130 | mov [ETH_input_event], eax |
||
5522 | hidnplayr | 131 | pushf |
3982 | hidnplayr | 132 | .wait: |
5522 | hidnplayr | 133 | popf |
3982 | hidnplayr | 134 | mov eax, [ETH_input_event] |
135 | mov ebx, [eax + EVENT.id] |
||
136 | call wait_event |
||
137 | |||
138 | .loop: |
||
5522 | hidnplayr | 139 | pushf |
140 | cli |
||
141 | cmp [ETH_frame_queued], 0 |
||
142 | je .wait |
||
3982 | hidnplayr | 143 | |
5522 | hidnplayr | 144 | dec [ETH_frame_queued] |
3982 | hidnplayr | 145 | |
5522 | hidnplayr | 146 | mov esi, [ETH_frame_head] |
147 | mov ebx, [esi + NET_BUFF.NextPtr] |
||
3982 | hidnplayr | 148 | |
5522 | hidnplayr | 149 | mov [ETH_frame_head], ebx |
150 | mov [ebx + NET_BUFF.PrevPtr], ETH_frame_head |
||
151 | |||
152 | popf |
||
153 | |||
154 | mov eax, [esi + NET_BUFF.offset] |
||
155 | add eax, esi |
||
156 | mov ecx, [esi + NET_BUFF.length] |
||
157 | mov ebx, [esi + NET_BUFF.device] |
||
158 | |||
159 | pushd .loop ; return address for protocol handler |
||
160 | push esi ; keep pointer to NET_BUFF on stack |
||
161 | |||
3982 | hidnplayr | 162 | DEBUGF DEBUG_NETWORK_VERBOSE, "ETH_input: size=%u\n", ecx |
3643 | hidnplayr | 163 | sub ecx, sizeof.ETH_header |
3545 | hidnplayr | 164 | jb .dump |
165 | |||
5522 | hidnplayr | 166 | ; Set registers for protocol handlers |
3545 | hidnplayr | 167 | lea edx, [eax + sizeof.ETH_header] |
168 | mov ax, [eax + ETH_header.Type] |
||
169 | |||
5522 | hidnplayr | 170 | ; Place protocol handlers here |
3600 | hidnplayr | 171 | cmp ax, ETHER_PROTO_IPv4 |
6011 | hidnplayr | 172 | je ipv4_input |
3545 | hidnplayr | 173 | |
3601 | hidnplayr | 174 | cmp ax, ETHER_PROTO_ARP |
6011 | hidnplayr | 175 | je arp_input |
3545 | hidnplayr | 176 | |
5001 | hidnplayr | 177 | ; cmp ax, ETHER_PROTO_IPv6 |
6011 | hidnplayr | 178 | ; je ipv6_input |
3545 | hidnplayr | 179 | |
5001 | hidnplayr | 180 | ; cmp ax, ETHER_PROTO_PPP_DISCOVERY |
6011 | hidnplayr | 181 | ; je pppoe_discovery_input |
3545 | hidnplayr | 182 | |
5001 | hidnplayr | 183 | ; cmp ax, ETHER_PROTO_PPP_SESSION |
6011 | hidnplayr | 184 | ; je pppoe_session_input |
3545 | hidnplayr | 185 | |
4256 | hidnplayr | 186 | DEBUGF DEBUG_NETWORK_VERBOSE, "ETH_input: Unknown packet type=%x\n", ax |
3545 | hidnplayr | 187 | |
188 | .dump: |
||
4256 | hidnplayr | 189 | DEBUGF DEBUG_NETWORK_VERBOSE, "ETH_input: dumping\n" |
6011 | hidnplayr | 190 | call net_buff_free |
3545 | hidnplayr | 191 | ret |
192 | |||
6011 | hidnplayr | 193 | |
194 | |||
195 | ;-----------------------------------------------------------------; |
||
196 | ; ; |
||
197 | ; eth_output ; |
||
198 | ; ; |
||
199 | ; IN: ax = protocol ; |
||
200 | ; ebx = device ptr ; |
||
201 | ; ecx = payload size ; |
||