19
19
#include "smb.h"
20
20
#include "cdvd_config.h"
21
21
22
+ #define USE_CUSTOM_RECV 1
23
+
22
24
//Round up the erasure amount, so that memset can erase memory word-by-word.
23
25
#define ZERO_PKT_ALIGNED (hdr , hdrSize ) mips_memset((hdr), 0, ((hdrSize) + 3) & ~3)
24
26
@@ -39,6 +41,7 @@ int smb_io_sema = -1;
39
41
extern int (* plwip_close )(int s ); // #6
40
42
extern int (* plwip_connect )(int s , struct sockaddr * name , socklen_t namelen ); // #7
41
43
extern int (* plwip_recv )(int s , void * mem , int len , unsigned int flags ); // #9
44
+ extern int (* plwip_recvfrom )(int s , void * mem , int hlen , void * payload , int plen , unsigned int flags , struct sockaddr * from , socklen_t * fromlen ); // #10
42
45
extern int (* plwip_send )(int s , void * dataptr , int size , unsigned int flags ); // #11
43
46
extern int (* plwip_socket )(int domain , int type , int protocol ); // #13
44
47
extern int (* plwip_setsockopt )(int s , int level , int optname , const void * optval , socklen_t optlen ); // #19
@@ -606,7 +609,12 @@ static int smb_ReadAndX(u16 FID, u32 offsetlow, u32 offsethigh, void *readbuf, i
606
609
{
607
610
ReadAndXRequest_t * RR = & SMB_buf .smb .readAndXRequest ;
608
611
ReadAndXResponse_t * RRsp = & SMB_buf .smb .readAndXResponse ;
609
- register int r , padding , DataLength ;
612
+ register int r , DataLength ;
613
+ #ifdef USE_CUSTOM_RECV
614
+ int rcv_size , expected_size ;
615
+ #else
616
+ int padding ;
617
+ #endif
610
618
611
619
ZERO_PKT_ALIGNED (RR , sizeof (ReadAndXRequest_t ));
612
620
@@ -624,6 +632,30 @@ static int smb_ReadAndX(u16 FID, u32 offsetlow, u32 offsethigh, void *readbuf, i
624
632
RR -> MaxCountHigh = (u16 )(nbytes >> 16 );
625
633
626
634
nb_SetSessionMessage (sizeof (ReadAndXRequest_t ));
635
+
636
+ #ifdef USE_CUSTOM_RECV
637
+ //Send the whole message, including the 4-byte direct transport packet header.
638
+ r = SendData (main_socket , (char * )& SMB_buf , sizeof (ReadAndXRequest_t ) + 4 );
639
+ if (r <= 0 )
640
+ return -1 ;
641
+
642
+ //offset 49 is the offset of the DataOffset field within the ReadAndXResponse structure.
643
+ //recvfrom() is a custom function that will receive the reply.
644
+ do {
645
+ rcv_size = plwip_recvfrom (main_socket , & SMB_buf , 49 , readbuf , nbytes , 0 , NULL , NULL );
646
+ if (rcv_size <= 0 )
647
+ return -2 ;
648
+ } while (nb_GetPacketType () != 0 ); // dropping NBSS Session Keep alive
649
+
650
+ expected_size = nb_GetSessionMessageLength () + 4 ;
651
+ DataLength = (int )(((u32 )RRsp -> DataLengthHigh << 16 ) | RRsp -> DataLengthLow );
652
+
653
+ // Handle fragmented packets
654
+ while (rcv_size < expected_size ) {
655
+ r = plwip_recvfrom (main_socket , NULL , 0 , & ((u8 * )readbuf )[rcv_size - RRsp -> DataOffset - 4 ], expected_size - rcv_size , 0 , NULL , NULL ); // - rcv_size
656
+ rcv_size += r ;
657
+ }
658
+ #else
627
659
r = GetSMBServerReply (0 , NULL , sizeof (ReadAndXResponse_t ));
628
660
if (r <= 0 )
629
661
return - EIO ;
@@ -648,6 +680,7 @@ static int smb_ReadAndX(u16 FID, u32 offsetlow, u32 offsethigh, void *readbuf, i
648
680
if (r <= 0 )
649
681
return -2 ;
650
682
}
683
+ #endif
651
684
652
685
return DataLength ;
653
686
}
0 commit comments