Commits

izdubar committed 643458d

fix for broken SMB (by r517) on some setup

Comments (0)

Files changed (3)

modules/iopcore/cdvdman/smb.c

 //-------------------------------------------------------------------------
 int smb_ReadFile(u16 FID, u32 offsetlow, u32 offsethigh, void *readbuf, u16 nbytes)
 {	
-	register int rcv_size, pkt_size;
+	register int rcv_size, pkt_size, expected_size;
 
 	struct ReadAndXRequest_t *RR = (struct ReadAndXRequest_t *)SMB_buf;
 
 
 	plwip_send(main_socket, SMB_buf, 63, 0);
 receive:
-	rcv_size = plwip_recvfrom(main_socket, SMB_buf, 63, readbuf, nbytes, 0, NULL, NULL);
+	rcv_size = plwip_recvfrom(main_socket, SMB_buf, 49, readbuf, nbytes, 0, NULL, NULL);
+	expected_size = rawTCP_GetSessionHeader() + 4;
 
 	if (SMB_buf[0] != 0)	// dropping NBSS Session Keep alive
 		goto receive;
 
 	// Handle fragmented packets
-	while (rcv_size < (rawTCP_GetSessionHeader() + 4)) {
-		pkt_size = plwip_recvfrom(main_socket, NULL, 0, &((u8 *)readbuf)[rcv_size - 63], nbytes, 0, NULL, NULL); // - rcv_size
+	while (rcv_size < expected_size) {
+		pkt_size = plwip_recvfrom(main_socket, NULL, 0, &((u8 *)readbuf)[rcv_size - SMB_buf[49] - 4], expected_size - rcv_size, 0, NULL, NULL); // - rcv_size
 		rcv_size += pkt_size;
 	}
 

modules/network/SMSTCPIP/include/lwip/sockets.h

 int lwip_listen(int s, int backlog);
 int lwip_recv(int s, void *mem, int len, unsigned int flags);
 int lwip_read(int s, void *mem, int len);
-int lwip_recvfrom(int s, void *header, int hlen, void *payload, int plen, unsigned int flags,
+int lwip_recvfrom(int s, void *header, int index, void *payload, int plen, unsigned int flags,
       struct sockaddr *from, socklen_t *fromlen);
 int lwip_send(int s, void *dataptr, int size, unsigned int flags);
 int lwip_sendto(int s, void *dataptr, int size, unsigned int flags,

modules/network/SMSTCPIP/sockets.c

 }
 
 int
-lwip_recvfrom(int s, void *header, int hlen, void *payload, int plen, unsigned int flags,
+lwip_recvfrom(int s, void *header, int index, void *payload, int plen, unsigned int flags,
         struct sockaddr *from, socklen_t *fromlen)
 {
   struct lwip_socket *sock;
   struct netbuf *buf;
-  u16_t avail_len;
+  u16_t avail_len, copylen = 0;
   struct ip_addr *addr;
   u16_t port;
 
 
   /* copy the contents of the received buffer into
      the supplied memory pointer mem */
-  if (hlen) {
-    if (hlen > avail_len)
-      hlen = avail_len;
-
-    netbuf_copy_partial(buf, header, hlen, sock->lastoffset);
-    avail_len -= hlen;
+  if (index) {
+    if (avail_len >= 63) { // header of READ ANDX RESPONSE is 63 + padding bytes, which are "0x00" thus useless
+      netbuf_copy_partial(buf, header, 63, sock->lastoffset);
+      index = ((u8_t*)header)[index] + 4;
+      copylen = index;
+      avail_len -= index;
+    } else {
+   	  netbuf_copy_partial(buf, header, avail_len, sock->lastoffset);
+      copylen = avail_len;
+   	  avail_len = 0;
+    }
   }
 
-  if (plen > avail_len)
-    plen = avail_len;
+  if (avail_len) {
+    if (plen > avail_len)
+      plen = avail_len;
 
-  netbuf_copy_partial(buf, payload, plen, sock->lastoffset + hlen);
-  avail_len -= plen;
+    netbuf_copy_partial(buf, payload, plen, sock->lastoffset + index);
+    copylen += plen;
+    avail_len -= plen;
+  }
 
   /* Check to see from where the data was. */
   if (from && fromlen) {
      time around. */
   if (netconn_type(sock->conn) == NETCONN_TCP && avail_len > 0) {
     sock->lastdata = buf;
-    sock->lastoffset += hlen + plen;
+    sock->lastoffset += copylen;
   } else {
     sock->lastdata = NULL;
     sock->lastoffset = 0;
   }
 
   sock_set_errno(sock, 0);
-  return hlen + plen;
+  return copylen;
 }
 
 int
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.