21#define ZERO_PKT_ALIGNED(hdr, hdrSize) memset((hdr), 0, ((hdrSize) + 3) & ~3)
28#define CLIENT_MAX_BUFFER_SIZE USHRT_MAX
29#define CLIENT_MAX_XFER_SIZE USHRT_MAX
31static int main_socket = -1;
39 u8 u8buff[MAX_SMB_BUF + MAX_SMB_BUF_HDR];
40 u16 u16buff[(MAX_SMB_BUF + MAX_SMB_BUF_HDR) /
sizeof(u16)];
41 s16 s16buff[(MAX_SMB_BUF + MAX_SMB_BUF_HDR) /
sizeof(s16)];
42 NegotiateProtocolRequest_t negotiateProtocolRequest;
43 NegotiateProtocolResponse_t negotiateProtocolResponse;
44 SessionSetupAndXRequest_t sessionSetupAndXRequest;
45 SessionSetupAndXResponse_t sessionSetupAndXResponse;
46 TreeConnectAndXRequest_t treeConnectAndXRequest;
47 TreeConnectAndXResponse_t treeConnectAndXResponse;
48 TreeDisconnectRequest_t treeDisconnectRequest;
49 TreeDisconnectResponse_t treeDisconnectResponse;
50 NetShareEnumRequest_t netShareEnumRequest;
51 NetShareEnumResponse_t netShareEnumResponse;
52 LogOffAndXRequest_t logOffAndXRequest;
53 LogOffAndXResponse_t logOffAndXResponse;
54 EchoRequest_t echoRequest;
55 EchoResponse_t echoResponse;
56 QueryInformationDiskRequest_t queryInformationDiskRequest;
57 QueryInformationDiskResponse_t queryInformationDiskResponse;
58 QueryPathInformationRequest_t queryPathInformationRequest;
59 QueryPathInformationResponse_t queryPathInformationResponse;
60 FindFirstNext2Request_t findFirstNext2Request;
61 FindFirstNext2Response_t findFirstNext2Response;
62 NTCreateAndXRequest_t ntCreateAndXRequest;
63 NTCreateAndXResponse_t ntCreateAndXResponse;
64 OpenAndXRequest_t openAndXRequest;
65 OpenAndXResponse_t openAndXResponse;
66 ReadAndXRequest_t readAndXRequest;
67 ReadAndXResponse_t readAndXResponse;
68 WriteAndXRequest_t writeAndXRequest;
69 WriteAndXResponse_t writeAndXResponse;
70 CloseRequest_t closeRequest;
71 CloseResponse_t closeResponse;
72 DeleteRequest_t deleteRequest;
73 DeleteResponse_t deleteResponse;
74 ManageDirectoryRequest_t manageDirectoryRequest;
75 ManageDirectoryResponse_t manageDirectoryResponse;
76 RenameRequest_t renameRequest;
77 RenameResponse_t renameResponse;
88static void nb_SetSessionMessage(u32 size)
92 SMB_buf.sessionHeader = ((size & 0xff0000) >> 8) | ((size & 0xff00) << 8) | ((size & 0xff) << 24);
96static int nb_GetSessionMessageLength(
void)
102 size = ((SMB_buf.sessionHeader << 8) & 0xff0000) | ((SMB_buf.sessionHeader >> 8) & 0xff00) | ((SMB_buf.sessionHeader >> 24) & 0xff);
107static u8 nb_GetPacketType(
void)
110 return ((u8)(SMB_buf.sessionHeader & 0xff));
114static int OpenTCPSession(
struct in_addr dst_IP, u16 dst_port,
int *sock)
122 sck = lwip_socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
129 lwip_setsockopt(sck, IPPROTO_TCP, TCP_NODELAY, (
char *)&opt,
sizeof(opt));
131 memset(&sock_addr, 0,
sizeof(sock_addr));
132 sock_addr.sin_addr = dst_IP;
133 sock_addr.sin_family = AF_INET;
134 sock_addr.sin_port = htons(dst_port);
136 ret = lwip_connect(sck, (
struct sockaddr *)&sock_addr,
sizeof(sock_addr));
152static int RecvTimeout(
int sock,
void *buf,
int bsize,
int timeout_ms)
161 ret = poll(
pollfd, 1, timeout_ms);
172 ret = lwip_recv(sock, buf, bsize, 0);
179static int SendData(
int sock,
char *buf,
int size)
186 while (remaining > 0) {
189 result = lwip_send(sock, ptr, remaining, 0);
200static int RecvData(
int sock,
char *buf,
int size,
int timeout_ms)
207 while (remaining > 0) {
210 result = RecvTimeout(sock, ptr, remaining, timeout_ms);
222static int GetSMBServerReply(
int shdrlen,
void *spayload,
int rhdrlen)
224 int rcv_size, totalpkt_size, size;
226 totalpkt_size = nb_GetSessionMessageLength() + 4;
230 rcv_size = SendData(main_socket, (
char *)&SMB_buf, totalpkt_size);
237 rcv_size = SendData(main_socket, (
char *)&SMB_buf, size);
241 rcv_size = SendData(main_socket, spayload, totalpkt_size - size);
248 rcv_size = RecvData(main_socket, (
char *)&SMB_buf.sessionHeader,
sizeof(SMB_buf.sessionHeader), 10000);
251 }
while (nb_GetPacketType() != 0);
253 totalpkt_size = nb_GetSessionMessageLength();
256 size = (rhdrlen == 0) ? totalpkt_size : rhdrlen;
257 rcv_size = RecvData(main_socket, (
char *)&SMB_buf.smb, size, 3000);
261 return totalpkt_size;
266static int asciiToUtf16(
char *out,
const char *in)
272 for (pIn = in, pOut = out, len = 0; *pIn !=
'\0'; pIn++, pOut += 2, len += 2) {
284static int utf16ToAscii(
char *out,
const char *in,
int inbytes)
286 int len, bytesProcessed;
291 for (pIn = in, pOut = out, len = 0, bytesProcessed = 0; (inbytes == 0) || (bytesProcessed < inbytes); len++) {
292 wchar = pIn[0] | ((u16)pIn[1] << 8);
296 if (wchar >= 0xD800 && wchar < 0xDC00) {
304 *pOut = (wchar > 128) ?
'?' : (char)wchar;
318static int setStringField(
char *out,
const char *in)
322 if (server_specs.Capabilities & SERVER_CAP_UNICODE) {
323 len = asciiToUtf16(out, in);
325 len = strlen(in) + 1;
332static int getStringField(
char *out,
const char *in,
int inbytes)
336 if (server_specs.Capabilities & SERVER_CAP_UNICODE) {
337 len = utf16ToAscii(out, in, inbytes);
340 strncpy(out, in, inbytes);
344 len = strlen(out) + 1;
351int smb_NegotiateProtocol(u32 *capabilities)
353 static char *dialect =
"NT LM 0.12";
354 int r, length, retry_count;
355 NegotiateProtocolRequest_t *NPR = &SMB_buf.smb.negotiateProtocolRequest;
356 NegotiateProtocolResponse_t *NPRsp = &SMB_buf.smb.negotiateProtocolResponse;
362 ZERO_PKT_ALIGNED(NPR,
sizeof(NegotiateProtocolRequest_t));
364 NPR->smbH.Magic = SMB_MAGIC;
365 NPR->smbH.Cmd = SMB_COM_NEGOTIATE;
366 NPR->smbH.Flags = SMB_FLAGS_CASELESS_PATHNAMES;
367 NPR->smbH.Flags2 = SMB_FLAGS2_KNOWS_LONG_NAMES | SMB_FLAGS2_32BIT_STATUS;
368 length = strlen(dialect);
369 NPR->ByteCount = length +
sizeof(NPR->DialectFormat) + 1;
370 NPR->DialectFormat = 0x02;
371 strcpy(NPR->DialectName, dialect);
373 nb_SetSessionMessage(
sizeof(NegotiateProtocolRequest_t) + length + 1);
374 r = GetSMBServerReply(0, NULL, 0);
376 goto negotiate_error;
379 if (NPRsp->smbH.Magic != SMB_MAGIC)
380 goto negotiate_error;
383 if (NPRsp->smbH.Eclass != STATUS_SUCCESS)
384 goto negotiate_error;
386 if (NPRsp->smbWordcount != 17)
387 goto negotiate_error;
389 *capabilities = NPRsp->Capabilities & (CLIENT_CAP_LARGE_WRITEX | CLIENT_CAP_LARGE_READX | CLIENT_CAP_UNICODE | CLIENT_CAP_LARGE_FILES | CLIENT_CAP_STATUS32);
391 server_specs.Capabilities = NPRsp->Capabilities;
392 server_specs.SecurityMode = (NPRsp->SecurityMode & NEGOTIATE_SECURITY_USER_LEVEL) ? SERVER_USER_SECURITY_LEVEL : SERVER_SHARE_SECURITY_LEVEL;
393 server_specs.PasswordType = (NPRsp->SecurityMode & NEGOTIATE_SECURITY_CHALLENGE_RESPONSE) ? SERVER_USE_ENCRYPTED_PASSWORD : SERVER_USE_PLAINTEXT_PASSWORD;
396 server_specs.MaxBufferSize = NPRsp->MaxBufferSize;
397 server_specs.MaxMpxCount = NPRsp->MaxMpxCount;
398 server_specs.SessionKey = NPRsp->SessionKey;
399 memcpy(server_specs.EncryptionKey, NPRsp->ByteField, NPRsp->KeyLength);
400 getStringField(server_specs.PrimaryDomainServerName, (
char *)&NPRsp->ByteField[NPRsp->KeyLength], 0);
408 goto negotiate_retry;
414static int AddPassword(
char *Password,
int PasswordType,
int AuthType,
void *AnsiPassLen,
void *UnicodePassLen, u8 *Buffer)
420 if ((Password) && (PasswordType != NO_PASSWORD)) {
421 if (server_specs.PasswordType == SERVER_USE_ENCRYPTED_PASSWORD) {
423 switch (PasswordType) {
424 case HASHED_PASSWORD:
425 if (AuthType == LM_AUTH) {
426 memcpy(passwordhash, Password, 16);
427 memcpy(AnsiPassLen, &passwordlen, 2);
429 if (AuthType == NTLM_AUTH) {
430 memcpy(passwordhash, &Password[16], 16);
431 memcpy(UnicodePassLen, &passwordlen, 2);
436 if (AuthType == LM_AUTH) {
437 LM_Password_Hash((
const unsigned char *)Password, passwordhash);
438 memcpy(AnsiPassLen, &passwordlen, 2);
439 }
else if (AuthType == NTLM_AUTH) {
440 NTLM_Password_Hash((
const unsigned char *)Password, passwordhash);
441 memcpy(UnicodePassLen, &passwordlen, 2);
444 LM_Response(passwordhash, server_specs.EncryptionKey, LMresponse);
445 memcpy(Buffer, LMresponse, passwordlen);
446 }
else if (server_specs.PasswordType == SERVER_USE_PLAINTEXT_PASSWORD) {
448 passwordlen = strlen(Password);
449 if (passwordlen > 14)
451 else if (passwordlen == 0)
453 memcpy(AnsiPassLen, &passwordlen, 2);
454 memcpy(Buffer, Password, passwordlen);
457 if (server_specs.SecurityMode == SERVER_SHARE_SECURITY_LEVEL) {
459 memcpy(AnsiPassLen, &passwordlen, 2);
468int smb_SessionSetupAndX(
char *User,
char *Password,
int PasswordType, u32 capabilities)
470 SessionSetupAndXRequest_t *SSR = &SMB_buf.smb.sessionSetupAndXRequest;
471 SessionSetupAndXResponse_t *SSRsp = &SMB_buf.smb.sessionSetupAndXResponse;
472 int r, offset, useUnicode;
474 int AuthType = NTLM_AUTH;
478 ZERO_PKT_ALIGNED(SSR,
sizeof(SessionSetupAndXRequest_t));
480 useUnicode = (server_specs.Capabilities & SERVER_CAP_UNICODE) ? 1 : 0;
482 SSR->smbH.Magic = SMB_MAGIC;
483 SSR->smbH.Cmd = SMB_COM_SESSION_SETUP_ANDX;
484 SSR->smbH.Flags = SMB_FLAGS_CASELESS_PATHNAMES;
485 SSR->smbH.Flags2 = SMB_FLAGS2_KNOWS_LONG_NAMES | SMB_FLAGS2_32BIT_STATUS;
487 SSR->smbH.Flags2 |= SMB_FLAGS2_UNICODE_STRING;
488 SSR->smbWordcount = 13;
489 SSR->smbAndxCmd = SMB_COM_NONE;
490 SSR->MaxBufferSize = CLIENT_MAX_BUFFER_SIZE;
491 SSR->MaxMpxCount = server_specs.MaxMpxCount >= 2 ? 2 : (u16)server_specs.MaxMpxCount;
493 SSR->SessionKey = server_specs.SessionKey;
494 SSR->Capabilities = capabilities;
499 if (server_specs.SecurityMode == SERVER_USER_SECURITY_LEVEL) {
500 passwordlen = AddPassword(Password, PasswordType, AuthType, &SSR->AnsiPasswordLength, &SSR->UnicodePasswordLength, &SSR->ByteField[0]);
501 offset += passwordlen;
504 if ((useUnicode) && (!(passwordlen & 1))) {
505 SSR->ByteField[offset] =
'\0';
510 offset += setStringField((
char *)&SSR->ByteField[offset], User);
513 offset += setStringField((
char *)&SSR->ByteField[offset], server_specs.PrimaryDomainServerName);
516 if (useUnicode && ((offset & 1) != 0)) {
517 SSR->ByteField[offset] =
'\0';
520 offset += setStringField((
char *)&SSR->ByteField[offset],
"PlayStation 2");
523 if (useUnicode && ((offset & 1) != 0)) {
524 SSR->ByteField[offset] =
'\0';
527 offset += setStringField((
char *)&SSR->ByteField[offset],
"SMBMAN");
529 SSR->ByteCount = offset;
531 nb_SetSessionMessage(
sizeof(SessionSetupAndXRequest_t) + offset);
532 r = GetSMBServerReply(0, NULL, 0);
537 if (SSRsp->smbH.Magic != SMB_MAGIC)
541 switch (SSRsp->smbH.Eclass | (SSRsp->smbH.Ecode << 16)) {
544 case STATUS_LOGON_FAILURE:
545 if ((server_specs.SecurityMode == SERVER_USER_SECURITY_LEVEL) && (AuthType == NTLM_AUTH)) {
547 goto lbl_session_setup;
556 return (
int)SSRsp->smbH.UID;
560int smb_TreeConnectAndX(
int UID,
char *ShareName,
char *Password,
int PasswordType)
562 TreeConnectAndXRequest_t *TCR = &SMB_buf.smb.treeConnectAndXRequest;
563 TreeConnectAndXResponse_t *TCRsp = &SMB_buf.smb.treeConnectAndXResponse;
566 int AuthType = NTLM_AUTH;
570 ZERO_PKT_ALIGNED(TCR,
sizeof(TreeConnectAndXRequest_t));
572 TCR->smbH.Magic = SMB_MAGIC;
573 TCR->smbH.Cmd = SMB_COM_TREE_CONNECT_ANDX;
574 TCR->smbH.Flags = SMB_FLAGS_CASELESS_PATHNAMES;
575 TCR->smbH.Flags2 = SMB_FLAGS2_KNOWS_LONG_NAMES | SMB_FLAGS2_32BIT_STATUS;
576 if (server_specs.Capabilities & SERVER_CAP_UNICODE)
577 TCR->smbH.Flags2 |= SMB_FLAGS2_UNICODE_STRING;
579 TCR->smbWordcount = 4;
580 TCR->smbAndxCmd = SMB_COM_NONE;
585 if (server_specs.SecurityMode == SERVER_SHARE_SECURITY_LEVEL)
586 passwordlen = AddPassword(Password, PasswordType, AuthType, &TCR->PasswordLength, &TCR->PasswordLength, &TCR->ByteField[offset]);
589 TCR->PasswordLength = passwordlen;
591 offset += passwordlen;
593 if ((server_specs.Capabilities & SERVER_CAP_UNICODE) && (!(passwordlen & 1))) {
594 TCR->ByteField[offset] =
'\0';
599 offset += setStringField((
char *)&TCR->ByteField[offset], ShareName);
601 memcpy(&TCR->ByteField[offset],
"?????\0", 6);
604 TCR->ByteCount = offset;
606 nb_SetSessionMessage(
sizeof(TreeConnectAndXRequest_t) + offset);
607 r = GetSMBServerReply(0, NULL, 0);
612 if (TCRsp->smbH.Magic != SMB_MAGIC)
616 switch (TCRsp->smbH.Eclass | (TCRsp->smbH.Ecode << 16)) {
619 case STATUS_LOGON_FAILURE:
620 if ((server_specs.SecurityMode == SERVER_USER_SECURITY_LEVEL) && (AuthType == NTLM_AUTH)) {
622 goto lbl_tree_connect;
631 return (
int)TCRsp->smbH.TID;
635int smb_NetShareEnum(
int UID,
int TID,
ShareEntry_t *shareEntries,
int index,
int maxEntries)
639 NetShareEnumRequest_t *NSER = &SMB_buf.smb.netShareEnumRequest;
640 NetShareEnumResponse_t *NSERsp = &SMB_buf.smb.netShareEnumResponse;
642 ZERO_PKT_ALIGNED(NSER,
sizeof(NetShareEnumRequest_t));
644 NSER->smbH.Magic = SMB_MAGIC;
645 NSER->smbH.Cmd = SMB_COM_TRANSACTION;
646 NSER->smbH.UID = (u16)UID;
647 NSER->smbH.TID = (u16)TID;
648 NSER->smbWordcount = 14;
650 NSER->smbTrans.TotalParamCount = NSER->smbTrans.ParamCount = 19;
651 NSER->smbTrans.MaxParamCount = 1024;
652 NSER->smbTrans.MaxDataCount = MAX_SMB_BUF - NSER->smbTrans.MaxParamCount;
653 NSER->smbTrans.ParamOffset = 76;
654 NSER->smbTrans.DataOffset = 95;
656 NSER->ByteCount = 32;
665 memcpy(&NSER->ByteField[0],
"\\PIPE\\LANMAN\0\0\0WrLeh\0B13BWz\0\x01\0\xa0\x1f", 32);
667 nb_SetSessionMessage(
sizeof(NetShareEnumRequest_t) + NSER->ByteCount);
668 r = GetSMBServerReply(0, NULL, 0);
673 if (NSERsp->smbH.Magic != SMB_MAGIC)
676 switch (NSERsp->smbH.Eclass | (NSERsp->smbH.Ecode << 16)) {
681 case STATUS_ACCESS_DENIED:
688 if (SMB_buf.smb.u16buff[NSERsp->smbTrans.ParamOffset /
sizeof(u16)] != 0)
692 int AvailableEntries = SMB_buf.smb.s16buff[(NSERsp->smbTrans.ParamOffset + 6) /
sizeof(s16)];
695 char *data = (
char *)&SMB_buf.smb.u8buff[NSERsp->smbTrans.DataOffset];
698 for (i = 0; i < AvailableEntries; i++) {
701 int padding = (strlen(p) + 1 + 2) % 16 ? 16 - ((strlen(p) + 1) % 16) : 0;
703 if (*((u16 *)&p[strlen(p) + 1 + padding - 2]) == 0) {
704 if (maxEntries > 0) {
705 if ((
count < maxEntries) && (i >= index)) {
707 strncpy(shareEntries->ShareName, p, 256);
708 strncpy(shareEntries->ShareComment, &data[*((u16 *)&p[strlen(p) + 1 + padding])], 256);
714 p += strlen(p) + 1 + padding + 4;
724 QueryInformationDiskRequest_t *QIDR = &SMB_buf.smb.queryInformationDiskRequest;
725 QueryInformationDiskResponse_t *QIDRsp = &SMB_buf.smb.queryInformationDiskResponse;
727 ZERO_PKT_ALIGNED(QIDR,
sizeof(QueryInformationDiskRequest_t));
729 QIDR->smbH.Magic = SMB_MAGIC;
730 QIDR->smbH.Cmd = SMB_COM_QUERY_INFORMATION_DISK;
731 QIDR->smbH.UID = (u16)UID;
732 QIDR->smbH.TID = (u16)TID;
734 nb_SetSessionMessage(
sizeof(QueryInformationDiskRequest_t));
735 r = GetSMBServerReply(0, NULL, 0);
740 if (QIDRsp->smbH.Magic != SMB_MAGIC)
743 switch (QIDRsp->smbH.Eclass | (QIDRsp->smbH.Ecode << 16)) {
748 case STATUS_ACCESS_DENIED:
754 QueryInformationDisk->TotalUnits = QIDRsp->TotalUnits;
755 QueryInformationDisk->BlocksPerUnit = QIDRsp->BlocksPerUnit;
756 QueryInformationDisk->BlockSize = QIDRsp->BlockSize;
757 QueryInformationDisk->FreeUnits = QIDRsp->FreeUnits;
763int smb_QueryPathInformation(
int UID,
int TID,
PathInformation_t *Info,
char *Path)
765 int r, PathLen, queryType;
766 QueryPathInformationRequest_t *QPIR = &SMB_buf.smb.queryPathInformationRequest;
767 QueryPathInformationResponse_t *QPIRsp = &SMB_buf.smb.queryPathInformationResponse;
769 queryType = SMB_QUERY_FILE_BASIC_INFO;
773 ZERO_PKT_ALIGNED(QPIR,
sizeof(QueryPathInformationRequest_t));
775 QPIR->smbH.Magic = SMB_MAGIC;
776 QPIR->smbH.Cmd = SMB_COM_TRANSACTION2;
777 QPIR->smbH.Flags = SMB_FLAGS_CANONICAL_PATHNAMES;
778 QPIR->smbH.Flags2 = SMB_FLAGS2_KNOWS_LONG_NAMES | SMB_FLAGS2_32BIT_STATUS;
779 if (server_specs.Capabilities & SERVER_CAP_UNICODE)
780 QPIR->smbH.Flags2 |= SMB_FLAGS2_UNICODE_STRING;
781 QPIR->smbH.UID = (u16)UID;
782 QPIR->smbH.TID = (u16)TID;
783 QPIR->smbWordcount = 15;
785 QPIR->smbTrans.SetupCount = 1;
786 QPIR->SubCommand = TRANS2_QUERY_PATH_INFORMATION;
788 QPIR->smbTrans.ParamOffset = 68;
789 QPIR->smbTrans.MaxParamCount = 256;
790 QPIR->smbTrans.MaxDataCount = MAX_SMB_BUF - QPIR->smbTrans.MaxParamCount;
792 QueryPathInformationRequestParam_t *QPIRParam = (QueryPathInformationRequestParam_t *)&SMB_buf.smb.u8buff[QPIR->smbTrans.ParamOffset];
794 QPIRParam->LevelOfInterest = queryType;
795 QPIRParam->Reserved = 0;
798 PathLen = setStringField(QPIRParam->FileName, Path);
800 QPIR->smbTrans.TotalParamCount = QPIR->smbTrans.ParamCount = 2 + 4 + PathLen;
802 QPIR->ByteCount = 3 + QPIR->smbTrans.TotalParamCount;
804 QPIR->smbTrans.DataOffset = QPIR->smbTrans.ParamOffset + QPIR->smbTrans.TotalParamCount;
806 nb_SetSessionMessage(QPIR->smbTrans.DataOffset);
807 r = GetSMBServerReply(0, NULL, 0);
812 if (QPIRsp->smbH.Magic != SMB_MAGIC)
816 switch (QPIRsp->smbH.Eclass | (QPIRsp->smbH.Ecode << 16)) {
821 case STATUS_ACCESS_DENIED:
827 if (queryType == SMB_QUERY_FILE_BASIC_INFO) {
829 BasicFileInfo_t *BFI = (BasicFileInfo_t *)&SMB_buf.smb.u8buff[QPIRsp->smbTrans.DataOffset];
831 Info->Created = BFI->Created;
832 Info->LastAccess = BFI->LastAccess;
833 Info->LastWrite = BFI->LastWrite;
834 Info->Change = BFI->Change;
835 Info->FileAttributes = BFI->FileAttributes;
838 queryType = SMB_QUERY_FILE_STANDARD_INFO;
840 }
else if (queryType == SMB_QUERY_FILE_STANDARD_INFO) {
842 StandardFileInfo_t *SFI = (StandardFileInfo_t *)&SMB_buf.smb.u8buff[QPIRsp->smbTrans.DataOffset];
844 Info->AllocationSize = SFI->AllocationSize;
845 Info->EndOfFile = SFI->EndOfFile;
846 Info->LinkCount = SFI->LinkCount;
847 Info->DeletePending = SFI->DeletePending;
848 Info->IsDirectory = SFI->IsDirectory;
855int smb_NTCreateAndX(
int UID,
int TID,
char *filename, s64 *filesize,
int mode)
857 NTCreateAndXRequest_t *NTCR = &SMB_buf.smb.ntCreateAndXRequest;
858 NTCreateAndXResponse_t *NTCRsp = &SMB_buf.smb.ntCreateAndXResponse;
861 ZERO_PKT_ALIGNED(NTCR,
sizeof(NTCreateAndXRequest_t));
863 NTCR->smbH.Magic = SMB_MAGIC;
864 NTCR->smbH.Cmd = SMB_COM_NT_CREATE_ANDX;
865 NTCR->smbH.Flags = SMB_FLAGS_CANONICAL_PATHNAMES;
866 NTCR->smbH.Flags2 = SMB_FLAGS2_KNOWS_LONG_NAMES | SMB_FLAGS2_32BIT_STATUS;
867 if (server_specs.Capabilities & SERVER_CAP_UNICODE)
868 NTCR->smbH.Flags2 |= SMB_FLAGS2_UNICODE_STRING;
869 NTCR->smbH.UID = (u16)UID;
870 NTCR->smbH.TID = (u16)TID;
871 NTCR->smbWordcount = 24;
872 NTCR->smbAndxCmd = SMB_COM_NONE;
873 NTCR->AccessMask = ((mode & O_RDWR) == O_RDWR || (mode & O_WRONLY)) ? 0x2019f : 0x20089;
874 NTCR->FileAttributes = ((mode & O_RDWR) == O_RDWR || (mode & O_WRONLY)) ? EXT_ATTR_NORMAL : EXT_ATTR_READONLY;
875 NTCR->ShareAccess = 0x01;
877 NTCR->CreateDisposition |= 0x02;
879 NTCR->CreateDisposition |= 0x04;
881 NTCR->CreateDisposition |= 0x01;
882 if (NTCR->CreateDisposition == 0x06)
883 NTCR->CreateDisposition = 0x05;
884 NTCR->ImpersonationLevel = 2;
885 NTCR->SecurityFlags = 0x03;
888 if (server_specs.Capabilities & SERVER_CAP_UNICODE) {
889 NTCR->ByteField[offset] =
'\0';
894 NTCR->NameLength = setStringField((
char *)&NTCR->ByteField[offset], filename);
895 offset += NTCR->NameLength;
897 NTCR->ByteCount = offset;
899 nb_SetSessionMessage(
sizeof(NTCreateAndXRequest_t) + offset + 1);
900 r = GetSMBServerReply(0, NULL, 0);
905 if (NTCRsp->smbH.Magic != SMB_MAGIC)
908 switch (NTCRsp->smbH.Eclass | (NTCRsp->smbH.Ecode << 16)) {
913 case STATUS_ACCESS_DENIED:
919 *filesize = NTCRsp->FileSize;
921 return (
int)NTCRsp->FID;
925int smb_OpenAndX(
int UID,
int TID,
char *filename, s64 *filesize,
int mode)
933 OpenAndXRequest_t *OR = &SMB_buf.smb.openAndXRequest;
934 OpenAndXResponse_t *ORsp = &SMB_buf.smb.openAndXResponse;
937 if (server_specs.Capabilities & SERVER_CAP_NT_SMBS)
938 return smb_NTCreateAndX(UID, TID, filename, filesize, mode);
940 ZERO_PKT_ALIGNED(OR,
sizeof(OpenAndXRequest_t));
942 OR->smbH.Magic = SMB_MAGIC;
943 OR->smbH.Cmd = SMB_COM_OPEN_ANDX;
944 OR->smbH.Flags = SMB_FLAGS_CANONICAL_PATHNAMES;
945 OR->smbH.Flags2 = SMB_FLAGS2_KNOWS_LONG_NAMES | SMB_FLAGS2_32BIT_STATUS;
946 if (server_specs.Capabilities & SERVER_CAP_UNICODE)
947 OR->smbH.Flags2 |= SMB_FLAGS2_UNICODE_STRING;
948 OR->smbH.UID = (u16)UID;
949 OR->smbH.TID = (u16)TID;
950 OR->smbWordcount = 15;
951 OR->smbAndxCmd = SMB_COM_NONE;
952 OR->AccessMask = ((mode & O_RDWR) == O_RDWR || (mode & O_WRONLY)) ? 0x02 : 0x00;
953 OR->FileAttributes = ((mode & O_RDWR) == O_RDWR || (mode & O_WRONLY)) ? EXT_ATTR_NORMAL : EXT_ATTR_READONLY;
955 OR->CreateOptions |= 0x10;
957 OR->CreateOptions |= 0x02;
959 OR->CreateOptions |= 0x01;
962 if (server_specs.Capabilities & SERVER_CAP_UNICODE) {
963 OR->ByteField[offset] =
'\0';
968 offset += setStringField((
char *)&OR->ByteField[offset], filename);
969 OR->ByteCount = offset;
971 nb_SetSessionMessage(
sizeof(OpenAndXRequest_t) + offset + 1);
972 r = GetSMBServerReply(0, NULL, 0);
977 if (ORsp->smbH.Magic != SMB_MAGIC)
980 switch (ORsp->smbH.Eclass | (ORsp->smbH.Ecode << 16)) {
985 case STATUS_ACCESS_DENIED:
993 if (smb_QueryPathInformation(UID, TID, &
info, filename) >= 0)
994 *filesize =
info.EndOfFile;
1002int smb_ReadAndX(
int UID,
int TID,
int FID, s64 fileoffset,
void *readbuf,
int nbytes)
1004 ReadAndXRequest_t *RR = &SMB_buf.smb.readAndXRequest;
1005 ReadAndXResponse_t *RRsp = &SMB_buf.smb.readAndXResponse;
1006 int r, padding, DataLength;
1008 ZERO_PKT_ALIGNED(RR,
sizeof(ReadAndXRequest_t));
1010 RR->smbH.Magic = SMB_MAGIC;
1011 RR->smbH.Flags2 = SMB_FLAGS2_32BIT_STATUS;
1012 RR->smbH.Cmd = SMB_COM_READ_ANDX;
1013 RR->smbH.UID = (u16)UID;
1014 RR->smbH.TID = (u16)TID;
1015 RR->smbWordcount = 12;
1016 RR->smbAndxCmd = SMB_COM_NONE;
1018 RR->OffsetLow = (u32)(fileoffset & 0xffffffff);
1019 RR->OffsetHigh = (u32)((fileoffset >> 32) & 0xffffffff);
1020 RR->MaxCountLow = (u16)nbytes;
1021 RR->MaxCountHigh = (u16)(nbytes >> 16);
1023 nb_SetSessionMessage(
sizeof(ReadAndXRequest_t));
1024 r = GetSMBServerReply(0, NULL,
sizeof(ReadAndXResponse_t));
1029 if (RRsp->smbH.Magic != SMB_MAGIC)
1033 if ((RRsp->smbH.Eclass | (RRsp->smbH.Ecode << 16)) != STATUS_SUCCESS)
1037 padding = RRsp->DataOffset -
sizeof(ReadAndXResponse_t);
1039 r = RecvData(main_socket, (
char *)(RRsp + 1), padding, 3000);
1044 DataLength = (int)(((u32)RRsp->DataLengthHigh << 16) | RRsp->DataLengthLow);
1045 if (DataLength > 0) {
1046 r = RecvData(main_socket, readbuf, DataLength, 3000);
1056int smb_ReadFile(
int UID,
int TID,
int FID, s64 fileoffset,
void *readbuf,
int nbytes)
1066 while (remaining > 0) {
1068 toRead = remaining > CLIENT_MAX_XFER_SIZE ? CLIENT_MAX_XFER_SIZE : remaining;
1070 result = smb_ReadAndX(UID, TID, FID, pos, ptr, toRead);
1076 remaining -= result;
1083int smb_WriteAndX(
int UID,
int TID,
int FID, s64 fileoffset,
void *writebuf,
int nbytes)
1086 const int padding = 1;
1087 WriteAndXRequest_t *WR = &SMB_buf.smb.writeAndXRequest;
1088 WriteAndXResponse_t *WRsp = &SMB_buf.smb.writeAndXResponse;
1090 ZERO_PKT_ALIGNED(WR,
sizeof(WriteAndXRequest_t) + padding);
1092 WR->smbH.Magic = SMB_MAGIC;
1093 WR->smbH.Flags2 = SMB_FLAGS2_32BIT_STATUS;
1094 WR->smbH.Cmd = SMB_COM_WRITE_ANDX;
1095 WR->smbH.UID = (u16)UID;
1096 WR->smbH.TID = (u16)TID;
1097 WR->smbWordcount = 14;
1098 WR->smbAndxCmd = SMB_COM_NONE;
1100 WR->OffsetLow = (u32)(fileoffset & 0xffffffff);
1101 WR->OffsetHigh = (u32)((fileoffset >> 32) & 0xffffffff);
1102 WR->WriteMode = 0x0001;
1103 WR->DataOffset =
sizeof(WriteAndXRequest_t) + padding;
1104 WR->Remaining = (u16)nbytes;
1105 WR->DataLengthLow = (u16)nbytes;
1106 WR->DataLengthHigh = (u16)(nbytes >> 16);
1107 WR->ByteCount = (u16)nbytes + padding;
1109 nb_SetSessionMessage(
sizeof(WriteAndXRequest_t) + padding + nbytes);
1110 r = GetSMBServerReply(
sizeof(WriteAndXRequest_t) + padding, writebuf, 0);
1115 if (WRsp->smbH.Magic != SMB_MAGIC)
1119 if ((WRsp->smbH.Eclass | (WRsp->smbH.Ecode << 16)) != STATUS_SUCCESS)
1125int smb_WriteFile(
int UID,
int TID,
int FID, s64 fileoffset,
void *writebuf,
int nbytes)
1135 while (remaining > 0) {
1136 int result, toWrite;
1138 toWrite = remaining > CLIENT_MAX_XFER_SIZE ? CLIENT_MAX_XFER_SIZE : remaining;
1140 result = smb_WriteAndX(UID, TID, FID, pos, ptr, toWrite);
1146 remaining -= result;
1153int smb_Close(
int UID,
int TID,
int FID)
1156 CloseRequest_t *CR = &SMB_buf.smb.closeRequest;
1157 CloseResponse_t *CRsp = &SMB_buf.smb.closeResponse;
1159 ZERO_PKT_ALIGNED(CR,
sizeof(CloseRequest_t));
1161 CR->smbH.Magic = SMB_MAGIC;
1162 CR->smbH.Cmd = SMB_COM_CLOSE;
1163 CR->smbH.Flags = SMB_FLAGS_CANONICAL_PATHNAMES;
1164 CR->smbH.Flags2 = SMB_FLAGS2_KNOWS_LONG_NAMES | SMB_FLAGS2_32BIT_STATUS;
1165 CR->smbH.UID = (u16)UID;
1166 CR->smbH.TID = (u16)TID;
1167 CR->smbWordcount = 3;
1170 nb_SetSessionMessage(
sizeof(CloseRequest_t));
1171 r = GetSMBServerReply(0, NULL, 0);
1176 if (CRsp->smbH.Magic != SMB_MAGIC)
1180 if ((CRsp->smbH.Eclass | (CRsp->smbH.Ecode << 16)) != STATUS_SUCCESS)
1187int smb_Delete(
int UID,
int TID,
char *Path)
1190 DeleteRequest_t *DR = &SMB_buf.smb.deleteRequest;
1191 DeleteResponse_t *DRsp = &SMB_buf.smb.deleteResponse;
1193 ZERO_PKT_ALIGNED(DR,
sizeof(DeleteRequest_t));
1195 DR->smbH.Magic = SMB_MAGIC;
1196 DR->smbH.Cmd = SMB_COM_DELETE;
1197 DR->smbH.Flags = SMB_FLAGS_CANONICAL_PATHNAMES;
1198 DR->smbH.Flags2 = SMB_FLAGS2_KNOWS_LONG_NAMES | SMB_FLAGS2_32BIT_STATUS;
1199 if (server_specs.Capabilities & SERVER_CAP_UNICODE)
1200 DR->smbH.Flags2 |= SMB_FLAGS2_UNICODE_STRING;
1201 DR->smbH.UID = (u16)UID;
1202 DR->smbH.TID = (u16)TID;
1203 DR->smbWordcount = 1;
1204 DR->SearchAttributes = 0;
1205 DR->BufferFormat = 0x04;
1208 PathLen = setStringField(DR->FileName, Path);
1209 DR->ByteCount = PathLen + 1;
1211 nb_SetSessionMessage(
sizeof(DeleteRequest_t) + PathLen);
1212 r = GetSMBServerReply(0, NULL, 0);
1217 if (DRsp->smbH.Magic != SMB_MAGIC)
1221 if ((DRsp->smbH.Eclass | (DRsp->smbH.Ecode << 16)) != STATUS_SUCCESS)
1228int smb_ManageDirectory(
int UID,
int TID,
char *Path,
int cmd)
1231 ManageDirectoryRequest_t *MDR = &SMB_buf.smb.manageDirectoryRequest;
1232 ManageDirectoryResponse_t *MDRsp = &SMB_buf.smb.manageDirectoryResponse;
1234 ZERO_PKT_ALIGNED(MDR,
sizeof(ManageDirectoryRequest_t));
1236 MDR->smbH.Magic = SMB_MAGIC;
1238 MDR->smbH.Cmd = (u8)cmd;
1239 MDR->smbH.Flags = SMB_FLAGS_CANONICAL_PATHNAMES;
1240 MDR->smbH.Flags2 = SMB_FLAGS2_KNOWS_LONG_NAMES | SMB_FLAGS2_32BIT_STATUS;
1241 if (server_specs.Capabilities & SERVER_CAP_UNICODE)
1242 MDR->smbH.Flags2 |= SMB_FLAGS2_UNICODE_STRING;
1243 MDR->smbH.UID = (u16)UID;
1244 MDR->smbH.TID = (u16)TID;
1245 MDR->BufferFormat = 0x04;
1248 PathLen = setStringField(MDR->DirectoryName, Path);
1249 MDR->ByteCount = PathLen + 1;
1251 nb_SetSessionMessage(
sizeof(ManageDirectoryRequest_t) + PathLen);
1252 r = GetSMBServerReply(0, NULL, 0);
1257 if (MDRsp->smbH.Magic != SMB_MAGIC)
1260 switch (MDRsp->smbH.Eclass | (MDRsp->smbH.Ecode << 16)) {
1262 case STATUS_SUCCESS:
1265 case STATUS_ACCESS_DENIED:
1275int smb_Rename(
int UID,
int TID,
char *oldPath,
char *newPath)
1278 RenameRequest_t *RR = &SMB_buf.smb.renameRequest;
1279 RenameResponse_t *RRsp = &SMB_buf.smb.renameResponse;
1281 ZERO_PKT_ALIGNED(RR,
sizeof(RenameRequest_t));
1283 RR->smbH.Magic = SMB_MAGIC;
1284 RR->smbH.Cmd = SMB_COM_RENAME;
1285 RR->smbH.Flags = SMB_FLAGS_CANONICAL_PATHNAMES;
1286 RR->smbH.Flags2 = SMB_FLAGS2_KNOWS_LONG_NAMES | SMB_FLAGS2_32BIT_STATUS;
1287 if (server_specs.Capabilities & SERVER_CAP_UNICODE)
1288 RR->smbH.Flags2 |= SMB_FLAGS2_UNICODE_STRING;
1289 RR->smbH.UID = (u16)UID;
1290 RR->smbH.TID = (u16)TID;
1291 RR->smbWordcount = 1;
1295 RR->SearchAttributes = 0;
1300 RR->ByteField[offset] = 0x04;
1302 offset += setStringField((
char *)&RR->ByteField[offset], oldPath);
1305 RR->ByteField[offset] = 0x04;
1307 if (server_specs.Capabilities & SERVER_CAP_UNICODE) {
1308 RR->ByteField[offset] =
'\0';
1311 offset += setStringField((
char *)&RR->ByteField[offset], newPath);
1313 RR->ByteCount = offset;
1315 nb_SetSessionMessage(
sizeof(RenameRequest_t) + offset);
1316 r = GetSMBServerReply(0, NULL, 0);
1321 if (RRsp->smbH.Magic != SMB_MAGIC)
1325 switch (RRsp->smbH.Eclass | (RRsp->smbH.Ecode << 16)) {
1327 case STATUS_SUCCESS:
1330 case STATUS_ACCESS_DENIED:
1340int smb_FindFirstNext2(
int UID,
int TID,
char *Path,
int cmd,
SearchInfo_t *
info)
1342 int r, PathLen, offset;
1343 FindFirstNext2Request_t *FFNR = &SMB_buf.smb.findFirstNext2Request;
1344 FindFirstNext2Response_t *FFNRsp = &SMB_buf.smb.findFirstNext2Response;
1346 ZERO_PKT_ALIGNED(FFNR,
sizeof(FindFirstNext2Request_t));
1348 FFNR->smbH.Magic = SMB_MAGIC;
1349 FFNR->smbH.Cmd = SMB_COM_TRANSACTION2;
1350 FFNR->smbH.Flags = SMB_FLAGS_CANONICAL_PATHNAMES;
1351 FFNR->smbH.Flags2 = SMB_FLAGS2_KNOWS_LONG_NAMES | SMB_FLAGS2_32BIT_STATUS;
1352 if (server_specs.Capabilities & SERVER_CAP_UNICODE)
1353 FFNR->smbH.Flags2 |= SMB_FLAGS2_UNICODE_STRING;
1354 FFNR->smbH.UID = (u16)UID;
1355 FFNR->smbH.TID = (u16)TID;
1356 FFNR->smbWordcount = 15;
1358 FFNR->smbTrans.SetupCount = 1;
1359 FFNR->SubCommand = (u8)cmd;
1361 FFNR->smbTrans.ParamOffset = (
sizeof(FindFirstNext2Request_t) + 3) & ~3;
1362 FFNR->smbTrans.MaxParamCount = 256;
1363 FFNR->smbTrans.MaxDataCount = MAX_SMB_BUF - FFNR->smbTrans.MaxParamCount;
1366 memset((
void *)(FFNR + 1), 0, FFNR->smbTrans.ParamOffset -
sizeof(FindFirstNext2Request_t));
1368 if (cmd == TRANS2_FIND_FIRST2) {
1369 FindFirst2RequestParam_t *FFRParam = (FindFirst2RequestParam_t *)&SMB_buf.smb.u8buff[FFNR->smbTrans.ParamOffset];
1371 FFRParam->SearchAttributes = ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | ATTR_DIRECTORY | ATTR_ARCHIVE;
1372 FFRParam->SearchCount = 1;
1373 FFRParam->Flags = CLOSE_SEARCH_IF_EOS | RESUME_SEARCH;
1374 FFRParam->LevelOfInterest = SMB_FIND_FILE_BOTH_DIRECTORY_INFO;
1375 FFRParam->StorageType = 0;
1378 PathLen = setStringField(FFRParam->SearchPattern, Path);
1380 FFNR->smbTrans.TotalParamCount = FFNR->smbTrans.ParamCount =
sizeof(FindFirst2RequestParam_t) + PathLen;
1382 FindNext2RequestParam_t *FNRParam = (FindNext2RequestParam_t *)&SMB_buf.smb.u8buff[FFNR->smbTrans.ParamOffset];
1384 FNRParam->SearchID = (u16)
info->SID;
1385 FNRParam->SearchCount = 1;
1386 FNRParam->LevelOfInterest = SMB_FIND_FILE_BOTH_DIRECTORY_INFO;
1387 FNRParam->ResumeKey = 0;
1388 FNRParam->Flags = CLOSE_SEARCH_IF_EOS | RESUME_SEARCH | CONTINUE_SEARCH;
1391 PathLen = setStringField(FNRParam->SearchPattern,
"");
1393 FFNR->smbTrans.TotalParamCount = FFNR->smbTrans.ParamCount =
sizeof(FindNext2RequestParam_t) + PathLen;
1396 FFNR->ByteCount = 3 + FFNR->smbTrans.TotalParamCount;
1397 offset = FFNR->smbTrans.ParamOffset + FFNR->smbTrans.TotalParamCount;
1402 nb_SetSessionMessage(offset);
1403 r = GetSMBServerReply(0, NULL, 0);
1408 if (FFNRsp->smbH.Magic != SMB_MAGIC)
1412 switch (FFNRsp->smbH.Eclass | (FFNRsp->smbH.Ecode << 16)) {
1414 case STATUS_SUCCESS:
1417 case STATUS_ACCESS_DENIED:
1423 FindFirstNext2ResponseParam_t *FFNRspParam;
1425 if (cmd == TRANS2_FIND_FIRST2) {
1426 FFNRspParam = (FindFirstNext2ResponseParam_t *)&SMB_buf.smb.u8buff[FFNRsp->smbTrans.ParamOffset];
1427 info->SID = FFNRspParam->SearchID;
1429 FFNRspParam = (FindFirstNext2ResponseParam_t *)&SMB_buf.smb.u8buff[FFNRsp->smbTrans.ParamOffset - 2];
1431 FindFirst2ResponseData_t *FFRspData = (FindFirst2ResponseData_t *)&SMB_buf.smb.u8buff[FFNRsp->smbTrans.DataOffset];
1433 info->EOS = FFNRspParam->EndOfSearch;
1435 if (FFNRspParam->SearchCount == 0)
1438 info->fileInfo.Created = FFRspData->Created;
1439 info->fileInfo.LastAccess = FFRspData->LastAccess;
1440 info->fileInfo.LastWrite = FFRspData->LastWrite;
1441 info->fileInfo.Change = FFRspData->Change;
1442 info->fileInfo.FileAttributes = FFRspData->FileAttributes;
1443 if (FFRspData->FileAttributes & EXT_ATTR_DIRECTORY)
1444 info->fileInfo.IsDirectory = 1;
1445 info->fileInfo.AllocationSize = FFRspData->AllocationSize;
1446 info->fileInfo.EndOfFile = FFRspData->EndOfFile;
1447 getStringField(
info->FileName, FFRspData->FileName, FFRspData->FileNameLen);
1453int smb_TreeDisconnect(
int UID,
int TID)
1456 TreeDisconnectRequest_t *TDR = &SMB_buf.smb.treeDisconnectRequest;
1457 TreeDisconnectResponse_t *TDRsp = &SMB_buf.smb.treeDisconnectResponse;
1459 ZERO_PKT_ALIGNED(TDR,
sizeof(TreeDisconnectRequest_t));
1461 TDR->smbH.Magic = SMB_MAGIC;
1462 TDR->smbH.Cmd = SMB_COM_TREE_DISCONNECT;
1463 TDR->smbH.UID = (u16)UID;
1464 TDR->smbH.TID = (u16)TID;
1466 nb_SetSessionMessage(
sizeof(TreeDisconnectRequest_t));
1467 r = GetSMBServerReply(0, NULL, 0);
1472 if (TDRsp->smbH.Magic != SMB_MAGIC)
1476 if ((TDRsp->smbH.Eclass | (TDRsp->smbH.Ecode << 16)) != STATUS_SUCCESS)
1483int smb_LogOffAndX(
int UID)
1486 LogOffAndXRequest_t *LR = &SMB_buf.smb.logOffAndXRequest;
1487 LogOffAndXResponse_t *LRsp = &SMB_buf.smb.logOffAndXResponse;
1489 ZERO_PKT_ALIGNED(LR,
sizeof(LogOffAndXRequest_t));
1491 LR->smbH.Magic = SMB_MAGIC;
1492 LR->smbH.Cmd = SMB_COM_LOGOFF_ANDX;
1493 LR->smbH.UID = (u16)UID;
1494 LR->smbWordcount = 2;
1495 LR->smbAndxCmd = SMB_COM_NONE;
1497 nb_SetSessionMessage(
sizeof(LogOffAndXRequest_t));
1498 r = GetSMBServerReply(0, NULL, 0);
1503 if (LRsp->smbH.Magic != SMB_MAGIC)
1507 if ((LRsp->smbH.Eclass | (LRsp->smbH.Ecode << 16)) != STATUS_SUCCESS)
1514int smb_Echo(
void *echo,
int len)
1517 EchoRequest_t *ER = &SMB_buf.smb.echoRequest;
1518 EchoResponse_t *ERsp = &SMB_buf.smb.echoResponse;
1520 ZERO_PKT_ALIGNED(ER,
sizeof(EchoRequest_t));
1522 ER->smbH.Magic = SMB_MAGIC;
1523 ER->smbH.Cmd = SMB_COM_ECHO;
1524 ER->smbWordcount = 1;
1527 memcpy(&ER->ByteField[0], echo, (u16)len);
1528 ER->ByteCount = (u16)len;
1530 nb_SetSessionMessage(
sizeof(EchoRequest_t) + (u16)len);
1531 r = GetSMBServerReply(0, NULL, 0);
1536 if (ERsp->smbH.Magic != SMB_MAGIC)
1540 if ((ERsp->smbH.Eclass | (ERsp->smbH.Ecode << 16)) != STATUS_SUCCESS)
1543 if (memcmp(&ERsp->ByteField[0], echo, len))
1550int smb_Connect(
char *SMBServerIP,
int SMBServerPort)
1555 dst_addr.s_addr = inet_addr(SMBServerIP);
1561 r = OpenTCPSession(dst_addr, SMBServerPort, &main_socket);
1567 strncpy(server_specs.ServerIP, SMBServerIP, 16);
1573int smb_Disconnect(
void)
1577 if (main_socket != -1) {
1579 shutdown(main_socket, SHUT_WR);
1581 while (recv(main_socket, &dummy,
sizeof(dummy), 0) > 0)
1584 lwip_close(main_socket);
u32 count
start sector of fragmented bd/file