Subversion Repositories Kolibri OS

Rev

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

Rev 1171 Rev 1196
Line 1... Line 1...
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
2
;;                                                                 ;;
3
;; Copyright (C) KolibriOS team 2004-2008. All rights reserved.    ;;
3
;; Copyright (C) KolibriOS team 2004-2009. 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
;;  IP.INC                                                         ;;
6
;;  IP.INC                                                         ;;
7
;;                                                                 ;;
7
;;                                                                 ;;
8
;;  Part of the tcp/ip network stack for KolibriOS                 ;;
8
;;  Part of the tcp/ip network stack for KolibriOS                 ;;
Line 83... Line 83...
83
align 4
83
align 4
84
IPv4_init:
84
IPv4_init:
Line 85... Line 85...
85
 
85
 
86
	or	eax, -1
86
	or	eax, -1
-
 
87
	mov	edi, BROADCAST
-
 
88
	stosd
87
	mov	edi, BROADCAST
89
	xor	eax, eax
88
	mov	ecx, 1+4*MAX_IP
90
	mov	ecx, 4*MAX_IP
Line 89... Line 91...
89
	rep	stosd
91
	rep	stosd
90
 
92
 
91
	xor	eax, eax
93
	xor	eax, eax
Line 114... Line 116...
114
;  OUT: /
116
;  OUT: /
115
;
117
;
116
;-----------------------------------------------------------------
118
;-----------------------------------------------------------------
Line 117... Line 119...
117
 
119
 
118
align 4
120
align 4
Line 119... Line 121...
119
IPv4_Handler:
121
IPv4_handler:
120
 
122
 
121
	DEBUGF	1,"IP_Handler - start\n"
123
	DEBUGF	1,"IP_Handler - start\n"
Line 184... Line 186...
184
	push	eax
186
	push	eax
185
	mov	al , [edx + IPv4_Packet.Protocol]
187
	mov	al , [edx + IPv4_Packet.Protocol]
186
	pop	edx						; Offset to data (tcp/udp/icmp/.. Packet)
188
	pop	edx						; Offset to data (tcp/udp/icmp/.. Packet)
Line 187... Line 189...
187
 
189
 
188
	cmp	al , IP_PROTO_TCP
190
	cmp	al , IP_PROTO_TCP
Line 189... Line 191...
189
;        je      TCP_Handler
191
;        je      TCP_handler
190
 
192
 
Line 191... Line 193...
191
	cmp	al , IP_PROTO_UDP
193
	cmp	al , IP_PROTO_UDP
192
	je	UDP_Handler
194
	je	UDP_handler
Line 193... Line 195...
193
 
195
 
Line 194... Line 196...
194
	cmp	al , IP_PROTO_ICMP
196
	cmp	al , IP_PROTO_ICMP
195
	je	ICMP_Handler
197
	je	ICMP_handler
Line 389... Line 391...
389
	add	eax, edx
391
	add	eax, edx
390
	push	eax
392
	push	eax
391
	mov	al , [edx + IPv4_Packet.Protocol]
393
	mov	al , [edx + IPv4_Packet.Protocol]
392
	pop	edx						; Offset to data (tcp/udp/icmp/.. Packet)
394
	pop	edx						; Offset to data (tcp/udp/icmp/.. Packet)
Line 393... Line 395...
393
 
395
 
394
;        cmp     al , IP_PROTO_TCP
396
	cmp	al , IP_PROTO_TCP
Line 395... Line 397...
395
;        je      TCP_Handler
397
;        je      TCP_handler
396
 
398
 
Line 397... Line 399...
397
	cmp	al , IP_PROTO_UDP
399
	cmp	al , IP_PROTO_UDP
398
	je	UDP_Handler
400
	je	UDP_handler
Line 399... Line 401...
399
 
401
 
Line 400... Line 402...
400
	cmp	al , IP_PROTO_ICMP
402
	cmp	al , IP_PROTO_ICMP
401
	je	ICMP_Handler_fragments
403
	je	ICMP_handler_fragments
Line 503... Line 505...
503
;-----------------------------------------------------------------
505
;-----------------------------------------------------------------
Line 504... Line 506...
504
 
506
 
Line 505... Line 507...
505
;;; TODO: create fragmented packets
507
;;; TODO: create fragmented packets
506
 
508
 
Line 507... Line 509...
507
align 4
509
align 4
Line 508... Line 510...
508
IPv4_create_Packet:
510
IPv4_create_packet:
509
 
511
 
Line 510... Line 512...
510
	DEBUGF 1,"Create IPv4 Packet\n"
512
	DEBUGF 1,"Create IPv4 Packet\n"
511
 
513
 
Line 512... Line -...
512
	cmp	ecx, 1514
-
 
513
	jg	.exit_
-
 
514
 
514
	cmp	ecx, 1514
-
 
515
	jg	.exit_
515
	cmp	eax, -1
516
 
516
	je	.broadcast		  ; If it is broadcast, just send
517
	cmp	eax, -1
Line 517... Line 518...
517
 
518
	je	.broadcast		  ; If it is broadcast, just send
Line 518... Line 519...
518
	push	eax
519
 
519
	stdcall arp_table_manager, ARP_TABLE_IP_TO_MAC, eax, temp_dstmac	;opcode,IP,MAC_ptr - Get the MAC address.
520
	call	ARP_IP_to_MAC
Line 520... Line 521...
520
	cmp	eax, ARP_NO_ENTRY
521
 
Line -... Line 522...
-
 
522
	cmp	eax, -1
-
 
523
	jne	.found
-
 
524
 
-
 
525
	DEBUGF 1,"Create IPv4 Packet - ARP entry not found!\n"
-
 
526
 
-
 
527
	; TODO: QUEUE!
521
	pop	eax
528
	or	edi, -1
522
	jne	.send
529
 
523
 
530
	ret
Line 524... Line 531...
524
	DEBUGF 1,"Create IPv4 Packet - ARP entry not found!\n"
531
 
525
 
532
  .found:
526
	; TODO: QUEUE!
533
	push	ax
527
	or	edi, -1
534
	push	ebx
528
 
535
 
529
	ret
536
	jmp	.send
530
 
537
 
531
  .broadcast:
538
  .broadcast:
532
	mov	dword [temp_dstmac], -1
539
	push	word -1
-
 
540
	push	dword -1
533
	mov	word [temp_dstmac+4], -1
541
 
534
 
542
 
535
 
543
  .send:
536
  .send:
544
	push	ecx eax ebx dx di
Line 570... Line 578...
570
	pop	eax ecx
578
	pop	eax ecx
571
	add	edi, IPv4_Packet.DataOrOptional
579
	add	edi, IPv4_Packet.DataOrOptional
Line 572... Line 580...
572
 
580
 
Line -... Line 581...
-
 
581
	DEBUGF 1,"IPv4 Packet for device %x created successfully\n", edx
-
 
582
 
573
	DEBUGF 1,"IPv4 Packet for device %x created successfully\n", edx
583
	add	esp, 6
Line 574... Line 584...
574
 
584
 
575
	ret
585
	ret
576
 
586
 
577
  .exit:
587
  .exit:
578
	add	esp, 16
588
	add	esp, 16+6
579
  .exit_:
589
  .exit_:
Line 580... Line -...
580
	DEBUGF 1,"Create IPv4 Packet - failed\n"
-
 
581
	or	edi, -1
-
 
582
	ret
-
 
583
 
-
 
Line 584... Line 590...
584
 
590
	DEBUGF 1,"Create IPv4 Packet - failed\n"
585
uglobal
591
	or	edi, -1
586
	temp_dstmac dp ?    ; TODO: place this in stack instead!
592
	ret
587
endg
593