Subversion Repositories Kolibri OS

Rev

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