Subversion Repositories Kolibri OS

Rev

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

Rev 1256 Rev 1257
Line 11... Line 11...
11
;;          GNU GENERAL PUBLIC LICENSE                             ;;
11
;;          GNU GENERAL PUBLIC LICENSE                             ;;
12
;;             Version 2, June 1991                                ;;
12
;;             Version 2, June 1991                                ;;
13
;;                                                                 ;;
13
;;                                                                 ;;
14
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 15... Line 15...
15
 
15
 
Line 16... Line 16...
16
$Revision: 1256 $
16
$Revision: 1257 $
17
 
17
 
18
struct	SOCKET_head
18
struct	SOCKET_head
19
	 .PrevPtr		dd ? ; pointer to previous socket in list
19
	 .PrevPtr		dd ? ; pointer to previous socket in list
Line 95... Line 95...
95
ends
95
ends
Line 96... Line 96...
96
 
96
 
97
MAX_backlog		equ 20	     ; backlog for stream sockets
97
MAX_backlog		equ 20	     ; backlog for stream sockets
98
SOCKETBUFFSIZE		equ 4096     ; in bytes
98
SOCKETBUFFSIZE		equ 4096     ; in bytes
-
 
99
SOCKET_QUEUE_SIZE	equ 10	     ; maximum number ofincoming packets queued for 1 socket
Line 99... Line 100...
99
SOCKET_QUEUE_SIZE	equ 10	     ; maximum number ofincoming packets queued for 1 socket
100
SOCKET_QUEUE_LOCATION	equ 2048     ; the incoming packet queue for sockets is placed in the socket struct itself, at this location from start
100
 
101
 
101
uglobal
102
uglobal
102
	net_sockets	rd 2
103
	net_sockets	rd 2
103
	last_UDP_port	dw ? ; These values give the number of the last used ephemeral port
104
	last_UDP_port	dw ? ; These values give the number of the last used ephemeral port
Line 104... Line 105...
104
	last_TCP_port	dw ? ;
105
	last_TCP_port	dw ? ;
105
endg
106
endg
106
 
107
 
107
 
108
 
108
;-----------------------------------------------
109
;-----------------------------------------------------------------
109
;
110
;
110
; SOCKET_init
111
; SOCKET_init
111
;
112
;
112
;  -
113
;  -
113
;
114
;
114
;  IN:  /
-
 
115
;  OUT: /
115
;  IN:  /
116
;
116
;  OUT: /
Line 117... Line 117...
117
;-----------------------------------------------
117
;
118
 
118
;-----------------------------------------------------------------
Line 126... Line 126...
126
	mov	[last_TCP_port], MIN_EPHEMERAL_PORT
126
	mov	[last_TCP_port], MIN_EPHEMERAL_PORT
Line 127... Line 127...
127
 
127
 
Line 128... Line 128...
128
	ret
128
	ret
129
 
129
 
130
 
130
 
131
;-----------------------------------------------
131
;-----------------------------------------------------------------
132
;
132
;
133
; Socket API (function 74)
-
 
134
;
133
; Socket API (function 74)
135
;-----------------------------------------------
134
;
136
 
135
;-----------------------------------------------------------------
137
align 4
136
align 4
138
sys_socket:
137
sys_socket:
Line 159... Line 158...
159
	mov	dword [esp+32],-1
158
	mov	dword [esp+32],-1
Line 160... Line 159...
160
 
159
 
Line 161... Line 160...
161
	ret
160
	ret
162
 
161
 
163
 
162
 
164
;-----------------------------------------------
163
;-----------------------------------------------------------------
165
;
164
;
166
; SOCKET_open
165
; SOCKET_open
167
;
166
;
168
;
167
;
169
;  IN:  domain in ecx
168
;  IN:  domain in ecx
170
;       type in edx
169
;       type in edx
171
;       protocol in esi
170
;       protocol in esi
172
;  OUT: eax is socket num, -1 on error
171
;  OUT: eax is socket num, -1 on error
173
;
172
;
Line 174... Line 173...
174
;-----------------------------------------------
173
;-----------------------------------------------------------------
Line 186... Line 185...
186
	mov	[eax + SOCKET_head.Protocol], esi
185
	mov	[eax + SOCKET_head.Protocol], esi
Line 187... Line 186...
187
 
186
 
188
	stdcall net_socket_addr_to_num, eax
187
	stdcall net_socket_addr_to_num, eax
Line 189... Line 188...
189
	DEBUGF	1,", socketnumber: %u\n", eax
188
	DEBUGF	1,", socketnumber: %u\n", eax
Line 190... Line 189...
190
 
189
 
Line 191... Line 190...
191
	; TODO: if it is txcp socket, set state to TCB_CLOSED
190
	; TODO: if it is a tcp socket, set state to TCB_CLOSED
Line 192... Line -...
192
 
-
 
193
	mov	[esp+32], eax
-
 
194
 
-
 
195
	ret
-
 
196
 
-
 
197
 
191
 
198
 
192
	mov	[esp+32], eax
199
 
193
 
200
 
194
	ret
201
 
195
 
202
 
196
 
203
 
197
 
204
;-----------------------------------------------
198
;-----------------------------------------------------------------
205
;
199
;
206
; SOCKET_bind
200
; SOCKET_bind
207
;
201
;
208
;  IN:  socket number in ecx
202
;  IN:  socket number in ecx
Line 209... Line 203...
209
;       pointer to sockaddr struct in edx
203
;       pointer to sockaddr struct in edx
Line 276... Line 270...
276
	ret
270
	ret
Line 277... Line 271...
277
 
271
 
278
 
272
 
279
 
273
 
280
 
274
 
281
;-----------------------------------------------
275
;-----------------------------------------------------------------
282
;
276
;
283
; SOCKET_connect
277
; SOCKET_connect
284
;
278
;
285
;
279
;
286
;  IN:  socket number in ecx
280
;  IN:  socket number in ecx
287
;       pointer to sockaddr struct in edx
281
;       pointer to sockaddr struct in edx
288
;       length of that struct in esi
282
;       length of that struct in esi
289
;  OUT: 0 on success
283
;  OUT: 0 on success
Line 290... Line 284...
290
;
284
;
Line 373... Line 367...
373
 
367
 
374
	mov	dword [esp+32],0
368
	mov	dword [esp+32],0
Line 375... Line -...
375
	ret
-
 
376
 
-
 
377
 
369
	ret
378
 
370
 
379
 
371
 
380
;-----------------------------------------------
372
;-----------------------------------------------------------------
381
;
373
;
382
; SOCKET_listen
374
; SOCKET_listen
383
;
375
;
384
;
376
;
385
;  IN:  socket number in ecx
377
;  IN:  socket number in ecx
386
;       backlog in edx
378
;       backlog in edx
387
;  OUT: eax is socket num, -1 on error
379
;  OUT: eax is socket num, -1 on error
388
;
380
;
Line 389... Line 381...
389
;-----------------------------------------------
381
;-----------------------------------------------------------------
Line 412... Line 404...
412
 
404
 
413
	mov	dword [esp+32], 0
405
	mov	dword [esp+32], 0
Line 414... Line -...
414
	ret
-
 
415
 
-
 
416
 
-
 
417
 
-
 
418
 
406
	ret
419
 
407
 
420
 
408
 
421
;-----------------------------------------------
409
;-----------------------------------------------------------------
422
;
410
;
423
; SOCKET_accept
411
; SOCKET_accept
424
;
412
;
425
;
413
;
426
;  IN:  socket number in ecx
414
;  IN:  socket number in ecx
427
;       addr in edx
415
;       addr in edx
428
;       addrlen in esi
416
;       addrlen in esi
429
;  OUT: eax is socket num, -1 on error
417
;  OUT: eax is socket num, -1 on error
430
;
418
;
Line 431... Line 419...
431
;-----------------------------------------------
419
;-----------------------------------------------------------------
Line 467... Line 455...
467
  .unlock_err:
455
  .unlock_err:
468
	mov	[esi + SOCKET_head.lock], 0
456
	mov	[esi + SOCKET_head.lock], 0
469
	jmp	s_error
457
	jmp	s_error
Line 470... Line 458...
470
 
458
 
471
 
459
 
472
;-----------------------------------------------
460
;-----------------------------------------------------------------
473
;
461
;
474
; SOCKET_close
462
; SOCKET_close
475
;
463
;
476
;
464
;
477
;  IN:  socket number in ecx
465
;  IN:  socket number in ecx
478
;  OUT: eax is socket num, -1 on error
466
;  OUT: eax is socket num, -1 on error
479
;
467
;
480
;-----------------------------------------------
468
;-----------------------------------------------------------------
Line 481... Line 469...
481
align 4
469
align 4
Line 557... Line 545...
557
	ret
545
	ret
Line 558... Line 546...
558
 
546
 
559
 
547
 
560
 
548
 
561
 
549
 
562
;-----------------------------------------------
550
;-----------------------------------------------------------------
563
;
551
;
564
; SOCKET_receive
552
; SOCKET_receive
565
;
553
;
566
;
554
;
567
;  IN:  socket number in ecx
555
;  IN:  socket number in ecx
568
;       addr to buffer in edx
556
;       addr to buffer in edx
569
;       length of buffer in esi
557
;       length of buffer in esi
570
;       flags in edi
558
;       flags in edi
571
;  OUT: eax is number of bytes copied, -1 on error
559
;  OUT: eax is number of bytes copied, -1 on error
Line 572... Line 560...
572
;
560
;
Line 580... Line 568...
580
	or	eax, eax
568
	or	eax, eax
581
	jz	s_error
569
	jz	s_error
Line 582... Line 570...
582
 
570
 
Line 583... Line 571...
583
	DEBUGF	1,"Socket pointer: %x\n", eax
571
	DEBUGF	1,"Socket pointer: %x\n", eax
Line 584... Line 572...
584
 
572
 
585
	get_from_queue (eax + 2048), SOCKET_QUEUE_SIZE, 4*3, s_error
573
	get_from_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, socket_queue_entry.size, s_error
Line 586... Line 574...
586
 
574
 
Line 613... Line 601...
613
	call	kernel_free
601
	call	kernel_free
Line 614... Line 602...
614
 
602
 
Line 615... Line 603...
615
	ret
603
	ret
616
 
604
 
617
 
605
 
618
;-----------------------------------------------
606
;-----------------------------------------------------------------
619
;
607
;
620
; SOCKET_send
608
; SOCKET_send
621
;
609
;
622
;
610
;
623
;  IN:  socket number in ecx
611
;  IN:  socket number in ecx
624
;       pointer to data in edx
612
;       pointer to data in edx
625
;       datalength in esi
613
;       datalength in esi
626
;       flags in edi
614
;       flags in edi
627
;  OUT: -1 on error
-
 
628
;
615
;  OUT: -1 on error
629
;-----------------------------------------------
616
;
Line 630... Line 617...
630
 
617
;-----------------------------------------------------------------
Line 743... Line 730...
743
;        call    ICMP_create_packet
730
;        call    ICMP_create_packet
Line 744... Line 731...
744
 
731
 
745
	mov	[esp+32], eax
732
	mov	[esp+32], eax
Line 746... Line 733...
746
	ret
733
	ret
747
 
734
 
748
;-----------------------------------------------
735
;-----------------------------------------------------------------
749
;
736
;
750
; SOCKET_send
737
; SOCKET_get_options
751
;
738
;
752
;
739
;
753
;  IN:  socket number in ecx
740
;  IN:  socket number in ecx
754
;       edx points to the options:
741
;       edx points to the options:
755
;       	dd	level, optname, optval, optlen
742
;               dd      level, optname, optval, optlen
756
;  OUT: -1 on error
743
;  OUT: -1 on error
757
;
744
;
758
; At moment, uses only pseudo-optname -2 for get last_ack_number for TCP.
745
; At moment, uses only pseudo-optname -2 for get last_ack_number for TCP.
759
; TODO: find best way to notify that send()'ed data were acknowledged
746
; TODO: find best way to notify that send()'ed data were acknowledged
-
 
747
;
760
;
748
;-----------------------------------------------------------------
-
 
749
align 4
761
;-----------------------------------------------
750
socket_get_opt:
762
socket_get_opt:
751
 
763
	cmp	dword [edx], IP_PROTO_TCP
752
	cmp	dword [edx], IP_PROTO_TCP
764
	jnz	.unknown
753
	jnz	.unknown
765
	cmp	dword [edx+4], -2
754
	cmp	dword [edx+4], -2
Line 778... Line 767...
778
	mov	eax, [edx+8]
767
	mov	eax, [edx+8]
779
	test	eax, eax
768
	test	eax, eax
780
	jz	@f
769
	jz	@f
781
	mov	[eax], ecx
770
	mov	[eax], ecx
782
@@:
771
@@:
783
	xor	eax, eax
772
	mov	dword [esp+32], 0
784
	ret
773
	ret
785
.fail:
774
.fail:
786
.unknown:
775
.unknown:
787
	or	eax, -1
776
	mov	dword [esp+32], -1
788
	ret
777
	ret
Line 789... Line 778...
789
 
778
 
790
 
779
 
791
;-----------------------------------------------
780
;-----------------------------------------------------------------
792
;
781
;
793
; SOCKET_find_free_port (local port)
782
; SOCKET_find_free_port (local port)
794
;
783
;
795
; works with INET byte order
784
; works with INET byte order
796
;
785
;
797
;  IN:  type in ecx (TCP/UDP)
786
;  IN:  type in ecx (TCP/UDP)
798
;  OUT: bx = 0 on error, portnumber otherwise
787
;  OUT: bx = 0 on error, portnumber otherwise
799
;
788
;
800
;-----------------------------------------------
789
;-----------------------------------------------------------------
Line 801... Line 790...
801
align 4
790
align 4
Line 846... Line 835...
846
 
835
 
847
  .port_ok:
836
  .port_ok:
848
	rol	bx, 8
837
	rol	bx, 8
Line -... Line 838...
-
 
838
	ret
-
 
839
 
849
	ret
840
 
850
 
841
 
851
;-----------------------------------------------
842
;-----------------------------------------------------------------
852
;
843
;
853
; SOCKET_check_port (local port)
844
; SOCKET_check_port (local port)
854
;
845
;
855
; works with INET byte order
846
; works with INET byte order
856
;
847
;
857
;  IN:  type in ecx (TCP/UDP)
848
;  IN:  type in ecx (TCP/UDP)
858
;       port to check in bx
849
;       port to check in bx
859
;  OUT: bx = 0 on error, unchanged otherwise
850
;  OUT: bx = 0 on error, unchanged otherwise
860
;
851
;
861
;-----------------------------------------------
852
;-----------------------------------------------------------------
862
align 4
853
align 4
Line 863... Line 854...
863
socket_check_port:
854
socket_check_port:
Line 878... Line 869...
878
 
869
 
879
  .port_ok:
870
  .port_ok:
Line -... Line 871...
-
 
871
	ret
880
	ret
872
 
881
 
873
 
882
 
874
 
883
;-----------------------------------------------
875
;-----------------------------------------------------------------
884
;
876
;
885
; SOCKET_internal_receiver
877
; SOCKET_internal_receiver
Line 893... Line 885...
893
;       esi = pointer to buffer
885
;       esi = pointer to buffer
894
;       edi = offset
886
;       edi = offset
895
;
887
;
896
;  OUT: xxx
888
;  OUT: xxx
897
;
889
;
898
;-----------------------------------------------
890
;-----------------------------------------------------------------
899
align 4
891
align 4
900
socket_internal_receiver:
892
socket_internal_receiver:
Line 901... Line 893...
901
 
893
 
Line 902... Line 894...
902
	DEBUGF 1,"Internal socket receiver: buffer %x, offset: %x size=%u socket: %x\n", esi, edi, ecx, eax
894
	DEBUGF 1,"Internal socket receiver: buffer %x, offset: %x size=%u socket: %x\n", esi, edi, ecx, eax
903
 
895
 
904
	push	edi	; offset
896
	push	edi	; offset
905
	push	ecx	; size
897
	push	ecx	; size
906
	push	esi	; data_ptr
898
	push	esi	; data_ptr
907
	mov	esi, esp
899
	mov	esi, esp
908
	add_to_queue (eax + 2048), SOCKET_QUEUE_SIZE, 3*4, notify_network_event.full
900
	add_to_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, socket_queue_entry.size, notify_network_event.full
Line 909... Line 901...
909
	DEBUGF	1,"Queued packet successfully\n"
901
	DEBUGF	1,"Queued packet successfully\n"
Line 910... Line 902...
910
	add	esp, 4*3
902
	add	esp, socket_queue_entry.size
911
 
903
 
Line 962... Line 954...
962
;        cld
954
;        cld
963
	xor	eax, eax
955
	xor	eax, eax
964
	rep	stosd
956
	rep	stosd
965
	pop	eax
957
	pop	eax
Line 966... Line 958...
966
 
958
 
Line 967... Line 959...
967
	init_queue (eax + 2048)
959
	init_queue (eax + SOCKET_QUEUE_LOCATION)
968
 
960
 
969
	; add socket to the list by changing pointers
961
	; add socket to the list by changing pointers
970
	mov	ebx, net_sockets
962
	mov	ebx, net_sockets