Subversion Repositories Kolibri OS

Rev

Rev 7678 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7678 Rev 7679
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
2
;;                                                              ;;
3
;; Copyright (C) KolibriOS team 2012-2019. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2012-2019. 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
;;  PPPoE.INC                                                   ;;
6
;;  PPPoE.INC                                                   ;;
7
;;                                                              ;;
7
;;                                                              ;;
8
;;  Part of the tcp/ip network stack for KolibriOS              ;;
8
;;  Part of the tcp/ip network stack for KolibriOS              ;;
9
;;                                                              ;;
9
;;                                                              ;;
10
;;    Written by hidnplayr@kolibrios.org                        ;;
10
;;    Written by hidnplayr@kolibrios.org                        ;;
11
;;                                                              ;;
11
;;                                                              ;;
12
;;          GNU GENERAL PUBLIC LICENSE                          ;;
12
;;          GNU GENERAL PUBLIC LICENSE                          ;;
13
;;             Version 2, June 1991                             ;;
13
;;             Version 2, June 1991                             ;;
14
;;                                                              ;;
14
;;                                                              ;;
15
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16
 
16
 
17
$Revision: 7678 $
17
$Revision: 7679 $
18
 
18
 
19
 
19
 
20
struct  PPPoE_frame
20
struct  PPPoE_frame
21
        VersionAndType  db ?
21
        VersionAndType  db ?
22
        Code            db ?
22
        Code            db ?
23
        SessionID       dw ?
23
        SessionID       dw ?
24
        Length          dw ?            ; Length of payload, does NOT include the length PPPoE header.
24
        Length          dw ?            ; Length of payload, does NOT include the length PPPoE header.
25
        Payload         rb 0
25
        Payload         rb 0
26
ends
26
ends
27
 
27
 
28
uglobal
28
uglobal
29
align 4
29
align 4
30
 
30
 
31
        PPPoE_SID       dw ?
31
        PPPoE_SID       dw ?
32
        PPPoE_MAC       dp ?
32
        PPPoE_MAC       dp ?
33
 
33
 
34
endg
34
endg
35
 
35
 
36
;-----------------------------------------------------------------;
36
;-----------------------------------------------------------------;
37
;                                                                 ;
37
;                                                                 ;
38
; pppoe_init: Reset all pppoe variables                           ;
38
; pppoe_init: Reset all pppoe variables                           ;
39
;                                                                 ;
39
;                                                                 ;
40
;-----------------------------------------------------------------;
40
;-----------------------------------------------------------------;
41
macro   pppoe_init {
41
macro   pppoe_init {
42
 
42
 
43
        call    pppoe_stop_connection
43
        call    pppoe_stop_connection
44
 
44
 
45
}
45
}
46
 
46
 
47
 
47
 
48
;-----------------------------------------------------------------;
48
;-----------------------------------------------------------------;
49
;                                                                 ;
49
;                                                                 ;
50
; pppoe_discovery_input                                           ;
50
; pppoe_discovery_input                                           ;
51
;                                                                 ;
51
;                                                                 ;
52
;  IN:  [esp] = ptr to buffer                                     ;
52
;  IN:  [esp] = ptr to buffer                                     ;
53
;       [esp+4] = size of buffer                                  ;
53
;       [esp+4] = size of buffer                                  ;
54
;       ebx = ptr to device struct                                ;
54
;       ebx = ptr to device struct                                ;
55
;       ecx = size of PPP packet                                  ;
55
;       ecx = size of PPP packet                                  ;
56
;       edx = ptr to PPP header                                   ;
56
;       edx = ptr to PPP header                                   ;
57
;                                                                 ;
57
;                                                                 ;
58
;  OUT: /                                                         ;
58
;  OUT: /                                                         ;
59
;                                                                 ;
59
;                                                                 ;
60
;-----------------------------------------------------------------;
60
;-----------------------------------------------------------------;
61
align 4
61
align 4
62
pppoe_discovery_input:
62
pppoe_discovery_input:
63
 
63
 
64
        DEBUGF  DEBUG_NETWORK_VERBOSE, "PPPoE_discovery_input\n"
64
        DEBUGF  DEBUG_NETWORK_VERBOSE, "PPPoE_discovery_input\n"
65
 
65
 
66
; First, find open PPPoE socket
66
; First, find open PPPoE socket
67
 
67
 
68
        pusha
68
        pusha
69
        mov     ecx, socket_mutex
69
        mov     ecx, socket_mutex
70
        call    mutex_lock
70
        call    mutex_lock
71
        popa
71
        popa
72
 
72
 
73
        mov     eax, net_sockets
73
        mov     eax, net_sockets
74
 
74
 
75
  .next_socket:
75
  .next_socket:
76
        mov     eax, [eax + SOCKET.NextPtr]
76
        mov     eax, [eax + SOCKET.NextPtr]
77
        or      eax, eax
77
        or      eax, eax
78
        jz      .dump
78
        jz      .dump
79
 
79
 
80
        cmp     [eax + SOCKET.Domain], AF_PPP
80
        cmp     [eax + SOCKET.Domain], AF_PPP
81
        jne     .next_socket
81
        jne     .next_socket
82
 
82
 
83
        cmp     [eax + SOCKET.Protocol], PPP_PROTO_ETHERNET
83
        cmp     [eax + SOCKET.Protocol], PPP_PROTO_ETHERNET
84
        jne     .next_socket
84
        jne     .next_socket
85
 
85
 
86
        pusha
86
        pusha
87
        mov     ecx, socket_mutex
87
        mov     ecx, socket_mutex
88
        call    mutex_unlock
88
        call    mutex_unlock
89
        popa
89
        popa
90
 
90
 
91
; Now, send it to the this socket
91
; Now, send it to the this socket
92
 
92
 
93
        mov     ecx, [esp + 4]
93
        mov     ecx, [esp + 4]
94
        mov     esi, [esp]
94
        mov     esi, [esp]
95
 
95
 
96
        jmp     socket_input
96
        jmp     socket_input
97
 
97
 
98
  .dump:
98
  .dump:
99
        pusha
99
        pusha
100
        mov     ecx, socket_mutex
100
        mov     ecx, socket_mutex
101
        call    mutex_unlock
101
        call    mutex_unlock
102
        popa
102
        popa
103
 
103
 
104
        DEBUGF  DEBUG_NETWORK_VERBOSE, 'PPPoE_discovery_input: dumping\n'
104
        DEBUGF  DEBUG_NETWORK_VERBOSE, 'PPPoE_discovery_input: dumping\n'
105
        call    net_buff_free
105
        call    net_buff_free
106
        ret
106
        ret
107
 
107
 
108
 
108
 
109
;-----------------------------------------------------------------;
109
;-----------------------------------------------------------------;
110
;                                                                 ;
110
;                                                                 ;
111
; pppoe_discovery_output                                          ;
111
; pppoe_discovery_output                                          ;
112
;                                                                 ;
112
;                                                                 ;
113
;  IN:  eax = socket pointer                                      ;
113
;  IN:  eax = socket pointer                                      ;
114
;       ecx = number of bytes to send                             ;
114
;       ecx = number of bytes to send                             ;
115
;       esi = pointer to data                                     ;
115
;       esi = pointer to data                                     ;
116
;                                                                 ;
116
;                                                                 ;
117
;-----------------------------------------------------------------;
117
;-----------------------------------------------------------------;
118
align 4
118
align 4
119
pppoe_discovery_output:
119
pppoe_discovery_output:
120
 
120
 
121
        DEBUGF  DEBUG_NETWORK_VERBOSE, "PPPoE_discovery_output: socket=%x buffer=%x size=%d\n", eax, esi, ecx
121
        DEBUGF  DEBUG_NETWORK_VERBOSE, "PPPoE_discovery_output: socket=%x buffer=%x size=%d\n", eax, esi, ecx
122
 
122
 
123
; RFC2516: An entire PADI packet (including the PPPoE header) MUST NOT
123
; RFC2516: An entire PADI packet (including the PPPoE header) MUST NOT
124
; exceed 1484 octets.
124
; exceed 1484 octets.
125
        cmp     ecx, 1484 + 14
125
        cmp     ecx, 1484 + 14
126
        ja      .bad
126
        ja      .bad
127
 
127
 
128
; Check that device exists and is ethernet device
128
; Check that device exists and is ethernet device
129
        mov     ebx, [eax + SOCKET.device]
129
        mov     ebx, [eax + SOCKET.device]
130
 
130
 
131
        cmp     ebx, NET_DEVICES_MAX
131
        cmp     ebx, NET_DEVICES_MAX
132
        ja      .bad
132
        ja      .bad
133
 
133
 
134
        mov     ebx, [net_drv_list + 4*ebx]
134
        mov     ebx, [net_device_list + 4*ebx]
135
        test    ebx, ebx
135
        test    ebx, ebx
136
        jz      .bad
136
        jz      .bad
137
 
137
 
138
        cmp     [ebx + NET_DEVICE.device_type], NET_DEVICE_ETH
138
        cmp     [ebx + NET_DEVICE.device_type], NET_DEVICE_ETH
139
        jne     .bad
139
        jne     .bad
140
 
140
 
141
        DEBUGF  DEBUG_NETWORK_VERBOSE, "PPPoE_discovery_output: device=%x\n", ebx
141
        DEBUGF  DEBUG_NETWORK_VERBOSE, "PPPoE_discovery_output: device=%x\n", ebx
142
 
142
 
143
; Create packet.
143
; Create packet.
144
        push    ecx esi
144
        push    ecx esi
145
;;;; FIXME        stdcall kernel_alloc, 1500
145
;;;; FIXME        stdcall kernel_alloc, 1500
146
        pop     esi ecx
146
        pop     esi ecx
147
        test    eax, eax
147
        test    eax, eax
148
        jz      .bad
148
        jz      .bad
149
 
149
 
150
        mov     edx, ecx
150
        mov     edx, ecx
151
        mov     edi, eax
151
        mov     edi, eax
152
        rep movsb
152
        rep movsb
153
 
153
 
154
        cmp     edx, 60         ; Min ETH size
154
        cmp     edx, 60         ; Min ETH size
155
        ja      @f
155
        ja      @f
156
        mov     edx, 60
156
        mov     edx, 60
157
       @@:
157
       @@:
158
 
158
 
159
        push    edx eax         ; size and packet ptr for driver send proc
159
        push    edx eax         ; size and packet ptr for driver send proc
160
 
160
 
161
; Overwrite source MAC and protocol type
161
; Overwrite source MAC and protocol type
162
        lea     edi, [eax + ETH_header.SrcMAC]
162
        lea     edi, [eax + ETH_header.SrcMAC]
163
        lea     esi, [ebx + ETH_DEVICE.mac]
163
        lea     esi, [ebx + ETH_DEVICE.mac]
164
        movsd
164
        movsd
165
        movsw
165
        movsw
166
        cmp     word[edi], ETHER_PROTO_PPP_SESSION      ; Allow only PPP_discovery, or LCP
166
        cmp     word[edi], ETHER_PROTO_PPP_SESSION      ; Allow only PPP_discovery, or LCP
167
        je      @f
167
        je      @f
168
        mov     ax, ETHER_PROTO_PPP_DISCOVERY
168
        mov     ax, ETHER_PROTO_PPP_DISCOVERY
169
        stosw
169
        stosw
170
       @@:
170
       @@:
171
 
171
 
172
; And send the packet
172
; And send the packet
173
        call    [ebx + NET_DEVICE.transmit]
173
        call    [ebx + NET_DEVICE.transmit]
174
 
174
 
175
        xor     eax, eax
175
        xor     eax, eax
176
        ret
176
        ret
177
 
177
 
178
  .bad:
178
  .bad:
179
        or      eax, -1
179
        or      eax, -1
180
        ret
180
        ret
181
 
181
 
182
 
182
 
183
;-----------------------------------------------------------------;
183
;-----------------------------------------------------------------;
184
;                                                                 ;
184
;                                                                 ;
185
; pppoe_session_input                                             ;
185
; pppoe_session_input                                             ;
186
;                                                                 ;
186
;                                                                 ;
187
;  IN:  [esp] = ptr to buffer                                     ;
187
;  IN:  [esp] = ptr to buffer                                     ;
188
;       [esp+4] = size of buffer                                  ;
188
;       [esp+4] = size of buffer                                  ;
189
;       ebx = ptr to device struct                                ;
189
;       ebx = ptr to device struct                                ;
190
;       edx = ptr to PPP header                                   ;
190
;       edx = ptr to PPP header                                   ;
191
;       ecx = size of PPP packet                                  ;
191
;       ecx = size of PPP packet                                  ;
192
;                                                                 ;
192
;                                                                 ;
193
;  OUT: /                                                         ;
193
;  OUT: /                                                         ;
194
;                                                                 ;
194
;                                                                 ;
195
;-----------------------------------------------------------------;
195
;-----------------------------------------------------------------;
196
align 4
196
align 4
197
pppoe_session_input:
197
pppoe_session_input:
198
 
198
 
199
        cmp     [edx + PPPoE_frame.VersionAndType], 0x11
199
        cmp     [edx + PPPoE_frame.VersionAndType], 0x11
200
        jne     .dump
200
        jne     .dump
201
 
201
 
202
        cmp     [edx + PPPoE_frame.Code], 0x00
202
        cmp     [edx + PPPoE_frame.Code], 0x00
203
        jne     .dump
203
        jne     .dump
204
 
204
 
205
        movzx   ecx, [edx + PPPoE_frame.Length]
205
        movzx   ecx, [edx + PPPoE_frame.Length]
206
        xchg    cl, ch
206
        xchg    cl, ch
207
 
207
 
208
        mov     ax, [edx + PPPoE_frame.SessionID]
208
        mov     ax, [edx + PPPoE_frame.SessionID]
209
        DEBUGF  DEBUG_NETWORK_VERBOSE, "PPPoE_input: session ID=%x, length=%u\n", ax, cx
209
        DEBUGF  DEBUG_NETWORK_VERBOSE, "PPPoE_input: session ID=%x, length=%u\n", ax, cx
210
        cmp     ax, [PPPoE_SID]
210
        cmp     ax, [PPPoE_SID]
211
        jne     .dump
211
        jne     .dump
212
 
212
 
213
        mov     ax, word [edx + PPPoE_frame.Payload]
213
        mov     ax, word [edx + PPPoE_frame.Payload]
214
        add     edx, PPPoE_frame.Payload + 2
214
        add     edx, PPPoE_frame.Payload + 2
215
 
215
 
216
        cmp     ax, PPP_PROTO_IPv4
216
        cmp     ax, PPP_PROTO_IPv4
217
        je      ipv4_input
217
        je      ipv4_input
218
 
218
 
219
;        cmp     ax, PPP_PROTO_IPv6
219
;        cmp     ax, PPP_PROTO_IPv6
220
;        je      ipv6_input
220
;        je      ipv6_input
221
 
221
 
222
        jmp     pppoe_discovery_input   ; Send LCP,CHAP,CBCP,... packets to the PPP dialer
222
        jmp     pppoe_discovery_input   ; Send LCP,CHAP,CBCP,... packets to the PPP dialer
223
        DEBUGF  DEBUG_NETWORK_VERBOSE, "PPPoE_input: Unknown protocol=%x\n", ax
223
        DEBUGF  DEBUG_NETWORK_VERBOSE, "PPPoE_input: Unknown protocol=%x\n", ax
224
 
224
 
225
  .dump:
225
  .dump:
226
        DEBUGF  DEBUG_NETWORK_VERBOSE, "PPPoE_input: dumping\n"
226
        DEBUGF  DEBUG_NETWORK_VERBOSE, "PPPoE_input: dumping\n"
227
        call    net_buff_free
227
        call    net_buff_free
228
        ret
228
        ret
229
 
229
 
230
 
230
 
231
 
231
 
232
;-----------------------------------------------------------------;
232
;-----------------------------------------------------------------;
233
;                                                                 ;
233
;                                                                 ;
234
; pppoe_output                                                    ;
234
; pppoe_output                                                    ;
235
;                                                                 ;
235
;                                                                 ;
236
;  IN:  ax = protocol                                             ;
236
;  IN:  ax = protocol                                             ;
237
;       ebx = device ptr                                          ;
237
;       ebx = device ptr                                          ;
238
;       ecx = packet size                                         ;
238
;       ecx = packet size                                         ;
239
;                                                                 ;
239
;                                                                 ;
240
; OUT:  eax = buffer start                                        ;
240
; OUT:  eax = buffer start                                        ;
241
;       eax = 0 on error                                          ;
241
;       eax = 0 on error                                          ;
242
;       ebx = device ptr                                          ;
242
;       ebx = device ptr                                          ;
243
;       ecx = packet size                                         ;
243
;       ecx = packet size                                         ;
244
;       edx = size of complete buffer                             ;
244
;       edx = size of complete buffer                             ;
245
;       edi = start of PPP payload                                ;
245
;       edi = start of PPP payload                                ;
246
;                                                                 ;
246
;                                                                 ;
247
;-----------------------------------------------------------------;
247
;-----------------------------------------------------------------;
248
align 4
248
align 4
249
pppoe_output:
249
pppoe_output:
250
 
250
 
251
        DEBUGF  DEBUG_NETWORK_VERBOSE, "PPPoE_output: size=%u device=%x\n", ecx, ebx
251
        DEBUGF  DEBUG_NETWORK_VERBOSE, "PPPoE_output: size=%u device=%x\n", ecx, ebx
252
 
252
 
253
        pushw   ax
253
        pushw   ax
254
        pushw   [PPPoE_SID]
254
        pushw   [PPPoE_SID]
255
 
255
 
256
        mov     ax, ETHER_PROTO_PPP_SESSION
256
        mov     ax, ETHER_PROTO_PPP_SESSION
257
        add     ecx, PPPoE_frame.Payload + 2
257
        add     ecx, PPPoE_frame.Payload + 2
258
        lea     edx, [PPPoE_MAC]
258
        lea     edx, [PPPoE_MAC]
259
        call    eth_output
259
        call    eth_output
260
        jz      .eth_error
260
        jz      .eth_error
261
 
261
 
262
        sub     ecx, PPPoE_frame.Payload
262
        sub     ecx, PPPoE_frame.Payload
263
        mov     [edi + PPPoE_frame.VersionAndType], 0x11
263
        mov     [edi + PPPoE_frame.VersionAndType], 0x11
264
        mov     [edi + PPPoE_frame.Code], 0
264
        mov     [edi + PPPoE_frame.Code], 0
265
        popw    [edi + PPPoE_frame.SessionID]
265
        popw    [edi + PPPoE_frame.SessionID]
266
        xchg    cl, ch
266
        xchg    cl, ch
267
        mov     [edi + PPPoE_frame.Length], cx
267
        mov     [edi + PPPoE_frame.Length], cx
268
        xchg    cl, ch
268
        xchg    cl, ch
269
 
269
 
270
        pop     word [edi + PPPoE_frame.Payload]
270
        pop     word [edi + PPPoE_frame.Payload]
271
 
271
 
272
        sub     ecx, 2
272
        sub     ecx, 2
273
        add     edi, PPPoE_frame.Payload + 2
273
        add     edi, PPPoE_frame.Payload + 2
274
 
274
 
275
        DEBUGF  DEBUG_NETWORK_VERBOSE, "PPPoE_output: success!\n"
275
        DEBUGF  DEBUG_NETWORK_VERBOSE, "PPPoE_output: success!\n"
276
        ret
276
        ret
277
 
277
 
278
 
278
 
279
  .eth_error:
279
  .eth_error:
280
        add     esp, 4
280
        add     esp, 4
281
        xor     eax, eax
281
        xor     eax, eax
282
        ret
282
        ret
283
 
283
 
284
align 4
284
align 4
285
pppoe_start_connection:
285
pppoe_start_connection:
286
 
286
 
287
        DEBUGF  DEBUG_NETWORK_VERBOSE, "PPPoE_start_connection: %x\n", cx
287
        DEBUGF  DEBUG_NETWORK_VERBOSE, "PPPoE_start_connection: %x\n", cx
288
 
288
 
289
        cmp     [PPPoE_SID], 0
289
        cmp     [PPPoE_SID], 0
290
        jne     .fail
290
        jne     .fail
291
 
291
 
292
        mov     [PPPoE_SID], cx
292
        mov     [PPPoE_SID], cx
293
        mov     dword [PPPoE_MAC], edx
293
        mov     dword [PPPoE_MAC], edx
294
        mov     word [PPPoE_MAC + 4], si
294
        mov     word [PPPoE_MAC + 4], si
295
 
295
 
296
        xor     eax, eax
296
        xor     eax, eax
297
        ret
297
        ret
298
 
298
 
299
  .fail:
299
  .fail:
300
        or      eax, -1
300
        or      eax, -1
301
        ret
301
        ret
302
 
302
 
303
 
303
 
304
align 4
304
align 4
305
pppoe_stop_connection:
305
pppoe_stop_connection:
306
 
306
 
307
        DEBUGF  DEBUG_NETWORK_VERBOSE, "PPPoE_stop_connection\n"
307
        DEBUGF  DEBUG_NETWORK_VERBOSE, "PPPoE_stop_connection\n"
308
 
308
 
309
        xor     eax, eax
309
        xor     eax, eax
310
        mov     [PPPoE_SID], ax
310
        mov     [PPPoE_SID], ax
311
        mov     dword [PPPoE_MAC], eax
311
        mov     dword [PPPoE_MAC], eax
312
        mov     word [PPPoE_MAC + 4], ax
312
        mov     word [PPPoE_MAC + 4], ax
313
 
313
 
314
        ret
314
        ret
315
 
315
 
316
 
316
 
317
;-----------------------------------------------------------------;
317
;-----------------------------------------------------------------;
318
;                                                                 ;
318
;                                                                 ;
319
; pppoe_api: Part of system function 76                           ;
319
; pppoe_api: Part of system function 76                           ;
320
;                                                                 ;
320
;                                                                 ;
321
; IN:  subfunction number in bl                                   ;
321
; IN:  subfunction number in bl                                   ;
322
;      device number in bh                                        ;
322
;      device number in bh                                        ;
323
;      ecx, edx, .. depends on subfunction                        ;
323
;      ecx, edx, .. depends on subfunction                        ;
324
;                                                                 ;
324
;                                                                 ;
325
; OUT:                                                            ;
325
; OUT:                                                            ;
326
;                                                                 ;
326
;                                                                 ;
327
;-----------------------------------------------------------------;
327
;-----------------------------------------------------------------;
328
align 4
328
align 4
329
pppoe_api:
329
pppoe_api:
330
 
330
 
331
        movzx   eax, bh
331
        movzx   eax, bh
332
        shl     eax, 2
332
        shl     eax, 2
333
 
333
 
334
        and     ebx, 0xff
334
        and     ebx, 0xff
335
        cmp     ebx, .number
335
        cmp     ebx, .number
336
        ja      .error
336
        ja      .error
337
        jmp     dword [.table + 4*ebx]
337
        jmp     dword [.table + 4*ebx]
338
 
338
 
339
  .table:
339
  .table:
340
        dd      pppoe_start_connection  ; 0
340
        dd      pppoe_start_connection  ; 0
341
        dd      pppoe_stop_connection   ; 1
341
        dd      pppoe_stop_connection   ; 1
342
  .number = ($ - .table) / 4 - 1
342
  .number = ($ - .table) / 4 - 1
343
 
343
 
344
  .error:
344
  .error:
345
        mov     eax, -1
345
        mov     eax, -1
346
        ret
346
        ret