54
54
#define ERR_SOCKET 4 //Request on a non-existent socket.
55
55
#define ERR_CONNECT 5 //Socket (link) not connected.
56
56
57
+ #define ICP_NONE 0
58
+ #define ICP_SERVER_LISTEN 1
59
+ #define ICP_SERVER_STR 2
60
+ #define ICP_SERVER_SOCKET 3
61
+
57
62
#define CONNECTIONS 20
58
63
59
64
static int fd ;
71
76
{
72
77
client_t client ;
73
78
int host ;
79
+ int icp ;
74
80
struct { int link , size ; uint32_t lsock , rsock ; } rcv , snd ;
75
81
} connection [CONNECTIONS ];
76
82
@@ -168,6 +174,7 @@ static void destroy (int i)
168
174
connection [i ].snd .size = connection [i ].rcv .size = -1 ;
169
175
connection [i ].rcv .lsock = connection [i ].rcv .rsock =
170
176
connection [i ].snd .lsock = connection [i ].snd .rsock = 0 ;
177
+ connection [i ].icp = ICP_NONE ;
171
178
}
172
179
173
180
static void send_imp (int flags , int type , int destination , int link , int id ,
@@ -277,7 +284,7 @@ void ncp_rts (uint8_t destination, uint32_t lsock, uint32_t rsock, uint8_t link)
277
284
void ncp_all (uint8_t destination , uint8_t link , uint16_t msg_space , uint32_t bit_space )
278
285
{
279
286
packet [22 ] = link ;
280
- packet [23 ] = msg_space >> 16 ;
287
+ packet [23 ] = msg_space >> 8 ;
281
288
packet [24 ] = msg_space ;
282
289
packet [25 ] = bit_space >> 24 ;
283
290
packet [26 ] = bit_space >> 16 ;
@@ -438,13 +445,16 @@ static int process_rts (uint8_t source, uint8_t *data)
438
445
{
439
446
int i ;
440
447
uint32_t lsock , rsock ;
448
+ uint8_t link ;
449
+
441
450
rsock = sock (& data [0 ]);
442
451
lsock = sock (& data [4 ]);
452
+ link = data [8 ];
443
453
444
- fprintf (stderr , "NCP: Recieved RTS %u:%u from %03o.\n" ,
445
- lsock , rsock , source );
454
+ fprintf (stderr , "NCP: Received RTS sockets %u:%u link %u from %03o.\n" ,
455
+ lsock , rsock , link , source );
446
456
447
- if (data [ 8 ] < LINK_MIN || data [ 8 ] > LINK_MAX ) {
457
+ if (link < LINK_MIN || link > LINK_MAX ) {
448
458
ncp_err (source , ERR_PARAM , data - 1 , 10 );
449
459
return 9 ;
450
460
}
@@ -468,18 +478,23 @@ static int process_rts (uint8_t source, uint8_t *data)
468
478
fprintf (stderr , "NCP: Listening to %u: connection %d.\n" , lsock , i );
469
479
}
470
480
}
471
- connection [i ].snd .link = data [8 ]; //Send link.
472
- if (connection [i ].rcv .size == -1 ) {
481
+ connection [i ].snd .link = link ; //Send link.
482
+ if (connection [i ].icp == ICP_SERVER_LISTEN ) {
483
+ connection [i ].rcv .size = 32 ; //Send byte size for ICP.
484
+ connection [i ].icp = ICP_SERVER_STR ;
485
+ ncp_str (connection [i ].host , lsock , rsock , connection [i ].rcv .size );
486
+ }
487
+ else if (connection [i ].rcv .size == -1 ) {
473
488
connection [i ].rcv .size = 8 ; //Send byte size.
474
489
ncp_str (connection [i ].host , lsock , rsock , connection [i ].rcv .size );
475
490
if (connection [i ].rcv .link != -1 ) {
476
491
fprintf (stderr , "NCP: Completing incoming RFC.\n" );
477
- reply_listen (source , connection [i ].snd .lsock , i );
492
+ // reply_listen (source, connection[i].snd.lsock, i);
478
493
}
479
494
} else {
480
495
if (connection [i ].snd .size != -1 ) {
481
496
fprintf (stderr , "NCP: Completing outgoing RFC.\n" );
482
- reply_open (source , connection [i ].rcv .rsock , i );
497
+ // reply_open (source, connection[i].rcv.rsock, i);
483
498
}
484
499
}
485
500
@@ -490,17 +505,15 @@ static int process_str (uint8_t source, uint8_t *data)
490
505
{
491
506
int i ;
492
507
uint32_t lsock , rsock ;
508
+ uint8_t size ;
509
+
493
510
rsock = sock (& data [0 ]);
494
511
lsock = sock (& data [4 ]);
512
+ size = data [8 ];
495
513
496
514
fprintf (stderr , "NCP: Recieved STR %u:%u from %03o.\n" ,
497
515
lsock , rsock , source );
498
516
499
- if (data [8 ] < LINK_MIN || data [8 ] > LINK_MAX ) {
500
- ncp_err (source , ERR_PARAM , data - 1 , 10 );
501
- return 9 ;
502
- }
503
-
504
517
if (find_listen (lsock ) == -1 ) {
505
518
i = find_sockets (source , lsock , rsock );
506
519
if (i == -1 ) {
@@ -520,7 +533,7 @@ static int process_str (uint8_t source, uint8_t *data)
520
533
fprintf (stderr , "NCP: Listening to %u: connection %d.\n" , lsock , i );
521
534
}
522
535
}
523
- connection [i ].snd .size = data [ 8 ] ; //Receive byte size.
536
+ connection [i ].snd .size = size ; //Receive byte size.
524
537
if (connection [i ].rcv .link == -1 ) {
525
538
connection [i ].rcv .link = 42 ; //Receive link.
526
539
ncp_rts (connection [i ].host , lsock , rsock , connection [i ].rcv .link );
@@ -578,12 +591,26 @@ static int process_cls (uint8_t source, uint8_t *data)
578
591
static int process_all (uint8_t source , uint8_t * data )
579
592
{
580
593
int i ;
594
+ uint8_t link = data [0 ];
595
+
581
596
fprintf (stderr , "NCP: Recieved ALL from %03o, link %u.\n" ,
582
- source , data [ 0 ] );
583
- i = find_link (source , data [ 0 ] );
584
- if (i == -1 )
597
+ source , link );
598
+ i = find_link (source , link );
599
+ if (i == -1 ) {
585
600
ncp_err (source , ERR_SOCKET , data - 1 , 10 );
586
- return 9 ;
601
+ } else if (connection [i ].icp == ICP_SERVER_STR ) {
602
+ uint8_t tmp [4 ];
603
+ uint32_t s = 0200 ;
604
+ tmp [0 ] = (s >> 24 ) & 0xFF ;
605
+ tmp [1 ] = (s >> 16 ) & 0xFF ;
606
+ tmp [2 ] = (s >> 8 ) & 0xFF ;
607
+ tmp [3 ] = (s >> 0 ) & 0xFF ;
608
+ fprintf (stderr , "NCP: Send socket %u for ICP.\n" , s );
609
+ send_imp (0 , IMP_REGULAR , connection [i ].host , connection [i ].snd .link ,
610
+ 0 , 0 , & tmp , 4 );
611
+ connection [i ].icp = ICP_SERVER_SOCKET ;
612
+ }
613
+ return 7 ;
587
614
}
588
615
589
616
static int process_gvb (uint8_t source , uint8_t * data )
@@ -761,13 +788,17 @@ static int (*ncp_messages[]) (uint8_t source, uint8_t *data) =
761
788
static void process_ncp (uint8_t source , uint8_t * data , uint16_t count )
762
789
{
763
790
int i = 0 , n ;
791
+ fprintf (stderr , "Process NCP: %u bytes.\n" , count );
764
792
while (i < count ) {
765
793
uint8_t type = data [i ++ ];
794
+ fprintf (stderr , "Process NCP: type %u.\n" , type );
766
795
if (type > NCP_MAX ) {
796
+ fprintf (stderr , "Process NCP: bad type.\n" );
767
797
ncp_err (source , ERR_OPCODE , data - 1 , 10 );
768
798
return ;
769
799
}
770
800
n = ncp_messages [type ] (source , & data [i ]);
801
+ fprintf (stderr , "Process NCP: %d bytes data => %d.\n" , n , i + n );
771
802
if (i + n > count )
772
803
ncp_err (source , ERR_SHORT , data - 1 , count - i + 1 );
773
804
i += n ;
@@ -1013,6 +1044,12 @@ static void app_open (void)
1013
1044
memcpy (& connection [i ].client .addr , & client , len );
1014
1045
connection [i ].client .len = len ;
1015
1046
1047
+ // Send ICP RTS.
1048
+ // Wait for STR.
1049
+ // Send ALL.
1050
+ // Wait for data with remote socket.
1051
+ // Wait for CLS / send CLS.
1052
+
1016
1053
// Send RFC messages.
1017
1054
ncp_rts (connection [i ].host , connection [i ].rcv .lsock ,
1018
1055
connection [i ].rcv .rsock , connection [i ].rcv .link );
@@ -1041,6 +1078,7 @@ static void app_listen (void)
1041
1078
listening [i ].sock = socket ;
1042
1079
memcpy (& connection [i ].client .addr , & client , len );
1043
1080
connection [i ].client .len = len ;
1081
+ connection [i ].icp = ICP_SERVER_LISTEN ;
1044
1082
}
1045
1083
1046
1084
static void app_read (void )
0 commit comments