static int adv_consistent(const unsigned char *p) { int i; uint32_t csum; if (get_32((uint32_t *) p) != ADV_MAGIC1 || get_32((uint32_t *) (p + ADV_SIZE - 4)) != ADV_MAGIC3) return 0; csum = 0; for (i = 4; i < ADV_SIZE - 4; i += 4) csum += get_32((uint32_t *) (p + i)); return csum == ADV_MAGIC2; }
uint64_t FileAccess::get_64() const { uint64_t res; uint32_t a, b; a = get_32(); b = get_32(); if (endian_swap) { SWAP(a, b); } res = b; res <<= 32; res |= a; return res; }
Variant StreamPeer::get_var() { int len = get_32(); Vector<uint8_t> var; var.resize(len); get_data(var.ptr(), len); Variant ret; decode_variant(ret, var.ptr(), len); return ret; }
String FileAccess::get_pascal_string() { uint32_t sl = get_32(); CharString cs; cs.resize(sl + 1); get_buffer((uint8_t *)cs.ptr(), sl); cs[sl] = 0; String ret; ret.parse_utf8(cs.ptr()); return ret; };
Variant StreamPeer::get_var() { int len = get_32(); Vector<uint8_t> var; Error err = var.resize(len); ERR_FAIL_COND_V(err != OK, Variant()); err = get_data(var.ptr(), len); ERR_FAIL_COND_V(err != OK, Variant()); Variant ret; decode_variant(ret, var.ptr(), len); return ret; }
Variant _File::get_var() const { ERR_FAIL_COND_V(!f,Variant()); uint32_t len = get_32(); DVector<uint8_t> buff = get_buffer(len); ERR_FAIL_COND_V(buff.size() != len, Variant()); DVector<uint8_t>::Read r = buff.read(); Variant v; Error err = decode_variant(v,&r[0],len); ERR_FAIL_COND_V( err!=OK, Variant() ); return v; }
static void cleanup_adv(unsigned char *advbuf) { int i; uint32_t csum; /* Make sure both copies agree, and update the checksum */ set_32((uint32_t *) advbuf, ADV_MAGIC1); csum = ADV_MAGIC2; for (i = 8; i < ADV_SIZE - 4; i += 4) csum -= get_32((uint32_t *) (advbuf + i)); set_32((uint32_t *) (advbuf + 4), csum); set_32((uint32_t *) (advbuf + ADV_SIZE - 4), ADV_MAGIC3); memcpy(advbuf + ADV_SIZE, advbuf, ADV_SIZE); }
static void get_answer (int s) { char data[BUF_SIZE]; int command = 0x1b; while (command == 0x1b) { int len; len = recv (s, data, BUF_SIZE, 0) ; if (!len) { mp_tmsg(MSGT_NETWORK,MSGL_ERR,"\nAlert! EOF\n"); return; } command = get_32 (data, 36) & 0xFFFF; if (command == 0x1b) send_command (s, 0x1b, 0, 0, 0, data); } }
Error FileAccessNetworkClient::connect(const String& p_host,int p_port,const String& p_password) { IP_Address ip; if (p_host.is_valid_ip_address()) { ip=p_host; } else { ip=IP::get_singleton()->resolve_hostname(p_host); } DEBUG_PRINT("IP: "+String(ip)+" port "+itos(p_port)); Error err = client->connect(ip,p_port); ERR_FAIL_COND_V(err,err); while(client->get_status()==StreamPeerTCP::STATUS_CONNECTING) { //DEBUG_PRINT("trying to connect...."); OS::get_singleton()->delay_usec(1000); } if (client->get_status()!=StreamPeerTCP::STATUS_CONNECTED) { return ERR_CANT_CONNECT; } CharString cs = p_password.utf8(); put_32(cs.length()); client->put_data((const uint8_t*)cs.ptr(),cs.length()); int e = get_32(); if (e!=OK) { return ERR_INVALID_PARAMETER; } thread = Thread::create(_thread_func,this); return OK; }
/* * Check to see that what we got was indeed an MS-DOS boot sector/superblock; * Return NULL if OK and otherwise an error message; */ const char *syslinux_check_bootsect(const void *bs) { int veryold; int sectorsize; long long sectors, fatsectors, dsectors; long long clusters; int rootdirents, clustersize; const struct boot_sector *sectbuf = bs; veryold = 0; /* Must be 0xF0 or 0xF8..0xFF */ if (get_8(§buf->bsMedia) != 0xF0 && get_8(§buf->bsMedia) < 0xF8) return "invalid media signature (not a FAT filesystem?)"; sectorsize = get_16(§buf->bsBytesPerSec); if (sectorsize == SECTOR_SIZE) ; /* ok */ else if (sectorsize >= 512 && sectorsize <= 4096 && (sectorsize & (sectorsize - 1)) == 0) return "unsupported sectors size"; else return "impossible sector size"; clustersize = get_8(§buf->bsSecPerClust); if (clustersize == 0 || (clustersize & (clustersize - 1))) return "impossible cluster size"; sectors = get_16(§buf->bsSectors); sectors = sectors ? sectors : get_32(§buf->bsHugeSectors); dsectors = sectors - get_16(§buf->bsResSectors); fatsectors = get_16(§buf->bsFATsecs); fatsectors = fatsectors ? fatsectors : get_32(§buf->bs32.FATSz32); fatsectors *= get_8(§buf->bsFATs); dsectors -= fatsectors; rootdirents = get_16(§buf->bsRootDirEnts); dsectors -= (rootdirents + sectorsize / 32 - 1) / sectorsize; if (dsectors < 0) return "negative number of data sectors"; if (fatsectors == 0) return "zero FAT sectors"; clusters = dsectors / clustersize; if (clusters < 0xFFF5) { /* FAT12 or FAT16 */ if (!get_16(§buf->bsFATsecs)) return "zero FAT sectors (FAT12/16)"; if (get_8(§buf->bs16.BootSignature) == 0x29) { if (!memcmp(§buf->bs16.FileSysType, "FAT12 ", 8)) { if (clusters >= 0xFF5) return "more than 4084 clusters but claims FAT12"; } else if (!memcmp(§buf->bs16.FileSysType, "FAT16 ", 8)) { if (clusters < 0xFF5) return "less than 4084 clusters but claims FAT16"; } else if (!memcmp(§buf->bs16.FileSysType, "FAT32 ", 8)) { return "less than 65525 clusters but claims FAT32"; } else if (memcmp(§buf->bs16.FileSysType, "FAT ", 8)) { static char fserr[] = "filesystem type \"????????\" not supported"; memcpy(fserr + 17, §buf->bs16.FileSysType, 8); return fserr; } } } else if (clusters < 0x0FFFFFF5) { /* * FAT32... * * Moving the FileSysType and BootSignature was a lovely stroke * of M$ idiocy... */ if (get_8(§buf->bs32.BootSignature) != 0x29 || memcmp(§buf->bs32.FileSysType, "FAT32 ", 8)) return "missing FAT32 signature"; } else { return "impossibly large number of clusters"; } return NULL; }
static int get_media_packet (int s, int padding, streaming_ctrl_t *stream_ctrl) { unsigned char pre_header[8]; char data[BUF_SIZE]; if (!get_data (s, pre_header, 8)) { mp_tmsg(MSGT_NETWORK,MSGL_ERR,"pre-header read failed\n"); return 0; } // for (i=0; i<8; i++) // mp_msg(MSGT_NETWORK,MSGL_INFO,"pre_header[%d] = %02x (%d)\n", // i, pre_header[i], pre_header[i]); if (pre_header[4] == 0x04) { int packet_len; packet_len = (pre_header[7] << 8 | pre_header[6]) - 8; // mp_msg(MSGT_NETWORK,MSGL_INFO,"asf media packet detected, len=%d\n", packet_len); if (packet_len < 0 || packet_len > BUF_SIZE) { mp_tmsg(MSGT_NETWORK, MSGL_FATAL, "Invalid RTSP packet size, giving up.\n"); return 0; } if (!get_data (s, data, packet_len)) { mp_tmsg(MSGT_NETWORK,MSGL_ERR,"Media data read failed.\n"); return 0; } streaming_bufferize(stream_ctrl, data, padding); } else { int32_t packet_len; int command; if (!get_data (s, (char*)&packet_len, 4)) { mp_tmsg(MSGT_NETWORK,MSGL_ERR,"packet_len read failed.\n"); return 0; } packet_len = get_32 ((unsigned char*)&packet_len, 0) + 4; if (packet_len < 0 || packet_len > BUF_SIZE) { mp_tmsg(MSGT_NETWORK,MSGL_FATAL,"Invalid RTSP packet size, giving up.\n"); return 0; } if (!get_data (s, data, packet_len)) { mp_tmsg(MSGT_NETWORK,MSGL_ERR,"Command data read failed.\n"); return 0; } if ( (pre_header[7] != 0xb0) || (pre_header[6] != 0x0b) || (pre_header[5] != 0xfa) || (pre_header[4] != 0xce) ) { mp_tmsg(MSGT_NETWORK,MSGL_ERR,"missing signature\n"); return -1; } command = get_32 (data, 24) & 0xFFFF; // mp_msg(MSGT_NETWORK,MSGL_INFO,"\ncommand packet detected, len=%d cmd=0x%X\n", packet_len, command); if (command == 0x1b) send_command (s, 0x1b, 0, 0, 0, data); else if (command == 0x1e) { mp_tmsg(MSGT_NETWORK,MSGL_INFO,"Everything done. Thank you for downloading a media file containing proprietary and patented technology.\n"); return 0; } else if (command == 0x21 ) { // Looks like it's new in WMS9 // Unknown command, but ignoring it seems to work. return 0; } else if (command != 0x05) { mp_tmsg(MSGT_NETWORK,MSGL_ERR,"unknown command %02x\n",command); return -1; } } // mp_msg(MSGT_NETWORK,MSGL_INFO,"get media packet succ\n"); return 1; }
static int interp_header (uint8_t *header, int header_len) { int i; int packet_length=-1; /* * parse header */ i = 30; while (i<header_len) { uint64_t guid_1, guid_2, length; guid_2 = (uint64_t)header[i] | ((uint64_t)header[i+1]<<8) | ((uint64_t)header[i+2]<<16) | ((uint64_t)header[i+3]<<24) | ((uint64_t)header[i+4]<<32) | ((uint64_t)header[i+5]<<40) | ((uint64_t)header[i+6]<<48) | ((uint64_t)header[i+7]<<56); i += 8; guid_1 = (uint64_t)header[i] | ((uint64_t)header[i+1]<<8) | ((uint64_t)header[i+2]<<16) | ((uint64_t)header[i+3]<<24) | ((uint64_t)header[i+4]<<32) | ((uint64_t)header[i+5]<<40) | ((uint64_t)header[i+6]<<48) | ((uint64_t)header[i+7]<<56); i += 8; // mp_msg(MSGT_NETWORK,MSGL_INFO,"guid found: %016llx%016llx\n", guid_1, guid_2); length = (uint64_t)header[i] | ((uint64_t)header[i+1]<<8) | ((uint64_t)header[i+2]<<16) | ((uint64_t)header[i+3]<<24) | ((uint64_t)header[i+4]<<32) | ((uint64_t)header[i+5]<<40) | ((uint64_t)header[i+6]<<48) | ((uint64_t)header[i+7]<<56); i += 8; if ( (guid_1 == 0x6cce6200aa00d9a6ULL) && (guid_2 == 0x11cf668e75b22630ULL) ) { mp_tmsg(MSGT_NETWORK,MSGL_INFO,"header object\n"); } else if ((guid_1 == 0x6cce6200aa00d9a6ULL) && (guid_2 == 0x11cf668e75b22636ULL)) { mp_tmsg(MSGT_NETWORK,MSGL_INFO,"data object\n"); } else if ((guid_1 == 0x6553200cc000e48eULL) && (guid_2 == 0x11cfa9478cabdca1ULL)) { packet_length = get_32(header, i+92-24); mp_tmsg(MSGT_NETWORK,MSGL_INFO,"file object, packet length = %d (%d)\n", packet_length, get_32(header, i+96-24)); } else if ((guid_1 == 0x6553200cc000e68eULL) && (guid_2 == 0x11cfa9b7b7dc0791ULL)) { int stream_id = header[i+48] | header[i+49] << 8; mp_tmsg(MSGT_NETWORK,MSGL_INFO,"stream object, stream ID: %d\n", stream_id); if (num_stream_ids < MAX_STREAMS) { stream_ids[num_stream_ids] = stream_id; num_stream_ids++; } else { mp_tmsg(MSGT_NETWORK,MSGL_ERR,"Too many IDs, stream skipped."); } } else { #if 0 int b = i; printf ("unknown object (guid: %016llx, %016llx, len: %lld)\n", guid_1, guid_2, length); for (; b < length; b++) { if (isascii(header[b]) || isalpha(header[b])) printf("%c ", header[b]); else printf("%x ", header[b]); } printf("\n"); #else mp_tmsg(MSGT_NETWORK,MSGL_WARN,"unknown object\n"); #endif } // mp_msg(MSGT_NETWORK,MSGL_INFO,"length : %lld\n", length); i += length-24; } return packet_length; }
static int get_header (int s, uint8_t *header, streaming_ctrl_t *streaming_ctrl) { unsigned char pre_header[8]; int header_len; header_len = 0; while (1) { if (!get_data (s, pre_header, 8)) { mp_tmsg(MSGT_NETWORK,MSGL_ERR,"pre-header read failed\n"); return 0; } if (pre_header[4] == 0x02) { int packet_len; packet_len = (pre_header[7] << 8 | pre_header[6]) - 8; // mp_msg(MSGT_NETWORK,MSGL_INFO,"asf header packet detected, len=%d\n", packet_len); if (packet_len < 0 || packet_len > HDR_BUF_SIZE - header_len) { mp_tmsg(MSGT_NETWORK, MSGL_FATAL, "Invalid header size, giving up.\n"); return 0; } if (!get_data (s, &header[header_len], packet_len)) { mp_tmsg(MSGT_NETWORK,MSGL_ERR,"Header data read failed.\n"); return 0; } header_len += packet_len; if ( (header[header_len-1] == 1) && (header[header_len-2]==1)) { if( streaming_bufferize( streaming_ctrl, header, header_len )<0 ) { return -1; } // mp_msg(MSGT_NETWORK,MSGL_INFO,"get header packet finished\n"); return header_len; } } else { int32_t packet_len; int command; char data[BUF_SIZE]; if (!get_data (s, (char*)&packet_len, 4)) { mp_tmsg(MSGT_NETWORK,MSGL_ERR,"packet_len read failed.\n"); return 0; } packet_len = get_32 ((unsigned char*)&packet_len, 0) + 4; // mp_msg(MSGT_NETWORK,MSGL_INFO,"command packet detected, len=%d\n", packet_len); if (packet_len < 0 || packet_len > BUF_SIZE) { mp_tmsg(MSGT_NETWORK, MSGL_FATAL, "Invalid RTSP packet size, giving up.\n"); return 0; } if (!get_data (s, data, packet_len)) { mp_tmsg(MSGT_NETWORK,MSGL_ERR,"Command data read failed.\n"); return 0; } command = get_32 (data, 24) & 0xFFFF; // mp_msg(MSGT_NETWORK,MSGL_INFO,"command: %02x\n", command); if (command == 0x1b) send_command (s, 0x1b, 0, 0, 0, data); } // mp_msg(MSGT_NETWORK,MSGL_INFO,"get header packet succ\n"); } }
static const char *check_fat_bootsect(const void *bs, int *fs_type) { int sectorsize; const struct fat_boot_sector *sectbuf = bs; long long sectors, fatsectors, dsectors; long long clusters; int rootdirents, clustersize; sectorsize = get_16(§buf->bsBytesPerSec); clustersize = get_8(§buf->bsSecPerClust); if (clustersize == 0 || (clustersize & (clustersize - 1))) return "impossible cluster size on an FAT volume"; sectors = get_16(§buf->bsSectors); sectors = sectors ? sectors : get_32(§buf->bsHugeSectors); dsectors = sectors - get_16(§buf->bsResSectors); fatsectors = get_16(§buf->bsFATsecs); fatsectors = fatsectors ? fatsectors : get_32(§buf->bs32.FATSz32); fatsectors *= get_8(§buf->bsFATs); dsectors -= fatsectors; rootdirents = get_16(§buf->bsRootDirEnts); dsectors -= (rootdirents + sectorsize / 32 - 1) / sectorsize; if (dsectors < 0) return "negative number of data sectors on an FAT volume"; clusters = dsectors / clustersize; fatsectors = get_16(§buf->bsFATsecs); fatsectors = fatsectors ? fatsectors : get_32(§buf->bs32.FATSz32); fatsectors *= get_8(§buf->bsFATs); if (!fatsectors) return "zero FAT sectors"; if (clusters < 0xFFF5) { /* FAT12 or FAT16 */ if (!get_16(§buf->bsFATsecs)) return "zero FAT sectors (FAT12/16)"; if (get_8(§buf->bs16.BootSignature) == 0x29) { if (!memcmp(§buf->bs16.FileSysType, "FAT12 ", 8)) { if (clusters >= 0xFF5) return "more than 4084 clusters but claims FAT12"; } else if (!memcmp(§buf->bs16.FileSysType, "FAT16 ", 8)) { if (clusters < 0xFF5) return "less than 4084 clusters but claims FAT16"; } else if (!memcmp(§buf->bs16.FileSysType, "FAT32 ", 8)) { return "less than 65525 clusters but claims FAT32"; } else if (memcmp(§buf->bs16.FileSysType, "FAT ", 8)) { static char fserr[] = "filesystem type \"????????\" not " "supported"; memcpy(fserr + 17, §buf->bs16.FileSysType, 8); return fserr; } } } else if (clusters < 0x0FFFFFF5) { /* * FAT32... * * Moving the FileSysType and BootSignature was a lovely stroke * of M$ idiocy... */ if (get_8(§buf->bs32.BootSignature) != 0x29 || memcmp(§buf->bs32.FileSysType, "FAT32 ", 8)) return "missing FAT32 signature"; } else { return "impossibly large number of clusters on an FAT volume"; } if (fs_type) *fs_type = VFAT; return NULL; }
static int get_media_packet (int s, int padding, streaming_ctrl_t *stream_ctrl) { unsigned char pre_header[8]; char data[BUF_SIZE]; if (!get_data (s, pre_header, 8)) { mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_MMST_PreHeaderReadFailed); return 0; } // for (i=0; i<8; i++) // mp_msg(MSGT_NETWORK,MSGL_INFO,"pre_header[%d] = %02x (%d)\n", // i, pre_header[i], pre_header[i]); if (pre_header[4] == 0x04) { int packet_len; packet_len = (pre_header[7] << 8 | pre_header[6]) - 8; // mp_msg(MSGT_NETWORK,MSGL_INFO,"asf media packet detected, len=%d\n", packet_len); if (packet_len < 0 || packet_len > BUF_SIZE) { mp_msg(MSGT_NETWORK, MSGL_FATAL, MSGTR_MPDEMUX_MMST_InvalidRTSPPacketSize); return 0; } if (!get_data (s, data, packet_len)) { mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_MMST_MediaDataReadFailed); return 0; } streaming_bufferize(stream_ctrl, data, padding); } else { int32_t packet_len; int command; if (!get_data (s, (char*)&packet_len, 4)) { mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_MMST_packet_lenReadFailed); return 0; } packet_len = get_32 ((unsigned char*)&packet_len, 0) + 4; if (packet_len < 0 || packet_len > BUF_SIZE) { mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MPDEMUX_MMST_InvalidRTSPPacketSize); return 0; } if (!get_data (s, data, packet_len)) { mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_MMST_CmdDataReadFailed); return 0; } if ( (pre_header[7] != 0xb0) || (pre_header[6] != 0x0b) || (pre_header[5] != 0xfa) || (pre_header[4] != 0xce) ) { mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_MMST_MissingSignature); return -1; } command = get_32 (data, 24) & 0xFFFF; // mp_msg(MSGT_NETWORK,MSGL_INFO,"\ncommand packet detected, len=%d cmd=0x%X\n", packet_len, command); if (command == 0x1b) send_command (s, 0x1b, 0, 0, 0, data); else if (command == 0x1e) { mp_msg(MSGT_NETWORK,MSGL_INFO,MSGTR_MPDEMUX_MMST_PatentedTechnologyJoke); return 0; } else if (command == 0x21 ) { // Looks like it's new in WMS9 // Unknown command, but ignoring it seems to work. return 0; } else if (command != 0x05) { mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_MMST_UnknownCmd,command); return -1; } } // mp_msg(MSGT_NETWORK,MSGL_INFO,"get media packet succ\n"); return 1; }
void SpOpenRec(void) { char fname[MAX_SLICE_LENGTH+1]; int namelen; int fileorg; int filemode; int filetype; int format; long mrs; long fileid; FILE *fd; struct FILE_INFO *info; #ifdef VMS struct RAB *rab; RecInfo *rinfo; unsigned int rfm,rat; #endif /* VMS */ dbgmsg("SP.OPENREC"); InBuf = &Tbuf[3]; OutBuf = &Tbuf[2]; OutCount = 0; namelen = get_slice((unsigned char *) fname); fname[namelen] = '\0'; fileorg = (int) get_8(); filemode = (int) get_8(); filetype = (int) get_8(); format = (int) get_8(); mrs = get_32(); dbgmsg("file=\"%s\" %d:%d:%d:%d %ld", fname, fileorg, filemode, filetype, format, mrs); /* Validate request */ if ((strlen(fname) == 0) || (fileorg < 3) || (fileorg > 4) || (filetype < 0) || (filetype > 2) || (filemode < 1) || (filemode > 6) || (format < 0) || (format > 1)) { SpFail(ER_ERROR); return; } if (filetype == TYPE_DONTCARE) filetype = TYPE_RECORD; #ifdef VMS if (fileorg == ORG_VARIABLE) rfm = FAB$C_VAR; rfm = (fileorg == ORG_VARIABLE)?FAB$C_VAR:FAB$C_FIX; rat = (filetype == TYPE_RECORD)?FAB$M_FTN:0; /* FTN:FAB$M_CR */ /* We ignore format under VMS */ /* decide whether to open or create file */ if ((filemode == 1) || (filemode == 4)) rab = vmsopen(fname, rfm, rat); else rab = vmscreate(fname, rfm, rat, rfm); if (rab == (struct RAB *) NULL) { SpFail(ER_NOFILE); return; } rinfo = newinfo(); if (rinfo == (RecInfo *) NULL) { vmsclose(rab); SpFail(ER_ERROR); } else { rinfo->baserec = 0; rinfo->prev = (FilePos *) NULL; rinfo->next = (FilePos *) NULL; } fd = stdout; /* Must be something ! */ #else fd = fopen(fname, OpenModes[fileorg-1][filemode-1]); if (fd == NULL) { SpFail(ER_NOFILE); return; } #endif /* VMS */ /* File opened OK */ fileid = RememberFile(fd, fileorg); if (fileid == NO_SLOT) { SpFail(ER_NORESOURCE); return; } /* Things are looking good Houston....beep */ info = &FileInfo[fileid]; info->buff = (unsigned char *) malloc((int) mrs+3); /* Room for CR, NL, EOS */ if (info->buff == (unsigned char *) NULL) { ForgetFile(fileid); SpFail(ER_NORESOURCE); return; } info->mrs = mrs; info->recordsize = -1; info->format = format; info->type = filetype; info->recno = 0; info->lastop = FIOP_NONE; info->pasteof = false; #ifdef VMS info->rab = rab; info->poslist = rinfo; #else if (fileorg == ORG_VARIABLE) { info->putfn = (format == FMT_FORMATTED)?form_seq_write_rec:unform_seq_write_rec; info->getfn = (format == FMT_FORMATTED)?form_seq_read_rec:unform_seq_read_rec; /* Need to allocate a read-ahead buffer for formatted files */ if (format == FMT_FORMATTED) { info->llbuff = (unsigned char *) malloc(LL_BUF_SIZE); info->llind = LL_BUF_SIZE; if (info->llbuff == (unsigned char *) NULL) { free(info->buff); ForgetFile(fileid); SpFail(ER_NORESOURCE); return; } } else { info->llbuff = NULL; info->llind = 0; } } else { info->putfn = direct_write_rec; info->getfn = direct_read_rec; info->llbuff = NULL; info->llind = 0; } #endif /* VMS */ put_8(ER_SUCCESS); put_32(mrs); put_32(fileid); put_32(filetype); put_count(OutCount); }
void SpGetRec(void) { long fileid; FILE *fd; int chunksize; long offset; bool doread=false; struct FILE_INFO *info; int res=ER_SUCCESS; dbgmsg("SP.GETREC"); InBuf = &Tbuf[3]; OutBuf = &Tbuf[2]; OutCount = 0; fileid = get_32(); chunksize = get_16(); offset = get_32(); if (get_8()) doread = true; dbgmsg("fileid=%d, chunksize=%d, offset=%ld, doread=%d", fileid, chunksize, offset, doread); if ((fileid < 0) || (fileid > MAX_FILES)) { put_8(ER_BADID); put_count(OutCount); return; } info = &FileInfo[fileid]; if (info->lastop == FIOP_WRITE) { put_8(ER_NOPOSN); put_count(OutCount); return; } if ((offset > info->mrs) || (offset < 0)) { put_8(ER_ERROR); put_count(OutCount); return; } if (doread == true) { info->recno++; #ifdef VMS res = vmsget(info); vmssavepos(info); #else res = info->getfn(info); #endif } dbgmsg("res=%d", res); if ((offset + (long)chunksize) > info->recordsize) chunksize = info->recordsize - offset; dbgmsg("recsiz=%ld, offset=%ld, chunksize=%d", info->recordsize, offset, chunksize); info->lastop = FIOP_READ; put_8(res); if (res == ER_SUCCESS) { put_32(info->recordsize); put_slice(chunksize, &(info->buff[offset])); } put_count(OutCount); }
void SpPutRec(void) { long fileid; FILE *fd; long recordsize; int chunksize; long offset; bool dowrite=false; struct FILE_INFO *info; int res; dbgmsg("SP.PUTREC"); InBuf = &Tbuf[3]; OutBuf = &Tbuf[2]; OutCount = 0; fileid = get_32(); recordsize = get_32(); chunksize = get_16(); offset = get_32(); if (get_8()) dowrite = true; dbgmsg("fileid=%ld, recordsize=%ld, chunksize=%d, offset=%ld, write=%d", fileid, recordsize, chunksize, offset, dowrite); if ((fileid < 0) || (fileid > MAX_FILES)) { put_8(ER_BADID); put_count(OutCount); return; } info = &FileInfo[fileid]; if (info->fd == NULL) { put_8(ER_BADID); put_count(OutCount); return; } if (info->lastop == FIOP_READ) { put_8(ER_NOPOSN); put_count(OutCount); return; } if (info->recordsize == -1) info->recordsize = recordsize; dbgmsg("recordsize=%ld, info->recordsize=%ld", recordsize, info->recordsize); dbgmsg("info->mrs=%ld", info->mrs); if ((recordsize > info->recordsize) || (recordsize > info->mrs) || (offset+(long)chunksize > info->mrs)) { dbgmsg("ER_ERROR: recordsize screwup"); put_8(ER_ERROR); put_count(OutCount); return; } get_slice(&(info->buff[offset])); info->dirty = true; if (dowrite == true) { info->recno++; #ifdef VMS res = vmsput(info->rab, info->buff, (int) recordsize); vmssavepos(info); #else res = info->putfn(info->fd, info->buff, recordsize); #endif /* VMS */ info->dirty = false; info->recordsize = -1; } else res = ER_SUCCESS; info->lastop = FIOP_WRITE; info->pasteof = false; put_8(res); put_count(OutCount); }
/* byte 1 and 2 is the port number to write * and at byte 3 the value to write starts. * I assume that there are and- and or- masks * here when HPEE_PORT_INIT_MASK is set but I have * not yet encountered this. */ static int configure_port_init(const unsigned char *buf) { int len=0; u_int8_t c; while (len<HPEE_PORT_INIT_MAX_LEN) { int s=0; c = get_8(buf+len); switch (c & HPEE_PORT_INIT_WIDTH_MASK) { case HPEE_PORT_INIT_WIDTH_BYTE: s=1; if (c & HPEE_PORT_INIT_MASK) { printk("\n" KERN_WARNING "port_init: unverified mask attribute\n"); outb((inb(get_16(buf+len+1) & get_8(buf+len+3)) | get_8(buf+len+4)), get_16(buf+len+1)); } else { outb(get_8(buf+len+3), get_16(buf+len+1)); } break; case HPEE_PORT_INIT_WIDTH_WORD: s=2; if (c & HPEE_PORT_INIT_MASK) { printk(KERN_WARNING "port_init: unverified mask attribute\n"); outw((inw(get_16(buf+len+1)) & get_16(buf+len+3)) | get_16(buf+len+5), get_16(buf+len+1)); } else { outw(cpu_to_le16(get_16(buf+len+3)), get_16(buf+len+1)); } break; case HPEE_PORT_INIT_WIDTH_DWORD: s=4; if (c & HPEE_PORT_INIT_MASK) { printk("\n" KERN_WARNING "port_init: unverified mask attribute\n"); outl((inl(get_16(buf+len+1) & get_32(buf+len+3)) | get_32(buf+len+7)), get_16(buf+len+1)); } else { outl(cpu_to_le32(get_32(buf+len+3)), get_16(buf+len+1)); } break; default: printk("\n" KERN_ERR "Invalid port init word %02x\n", c); return 0; } if (c & HPEE_PORT_INIT_MASK) { s*=2; } len+=s+3; if (!(c & HPEE_PORT_INIT_MORE)) { break; } } return len; }
float FileAccess::get_float() const { MarshallFloat m; m.i = get_32(); return m.f; };
signed long get_s32( void ) { return get_32(); }
void FileAccessNetworkClient::_thread_func() { client->set_nodelay(true); while(!quit) { DEBUG_PRINT("SEM WAIT - "+itos(sem->get())); Error err = sem->wait(); DEBUG_TIME("sem_unlock"); //DEBUG_PRINT("semwait returned "+itos(werr)); DEBUG_PRINT("MUTEX LOCK "+itos(lockcount)); DEBUG_PRINT("POPO"); DEBUG_PRINT("PEPE"); lock_mutex(); DEBUG_PRINT("MUTEX PASS"); blockrequest_mutex->lock(); while(block_requests.size()) { put_32(block_requests.front()->get().id); put_32(FileAccessNetwork::COMMAND_READ_BLOCK); put_64(block_requests.front()->get().offset); put_32(block_requests.front()->get().size); block_requests.pop_front(); } blockrequest_mutex->unlock(); DEBUG_PRINT("THREAD ITER"); DEBUG_TIME("sem_read"); int id = get_32(); int response = get_32(); DEBUG_PRINT("GET RESPONSE: "+itos(response)); FileAccessNetwork *fa=NULL; if (response!=FileAccessNetwork::RESPONSE_DATA) { ERR_FAIL_COND(!accesses.has(id)); } if (accesses.has(id)) fa=accesses[id]; switch(response) { case FileAccessNetwork::RESPONSE_OPEN: { DEBUG_TIME("sem_open"); int status = get_32(); if (status!=OK) { fa->_respond(0,Error(status)); } else { uint64_t len = get_64(); fa->_respond(len,Error(status)); } fa->sem->post(); } break; case FileAccessNetwork::RESPONSE_DATA: { int64_t offset = get_64(); uint32_t len = get_32(); Vector<uint8_t> block; block.resize(len); client->get_data(block.ptr(),len); if (fa) //may have been queued fa->_set_block(offset,block); } break; case FileAccessNetwork::RESPONSE_FILE_EXISTS: { int status = get_32(); fa->exists_modtime=status!=0; fa->sem->post(); } break; case FileAccessNetwork::RESPONSE_GET_MODTIME: { uint64_t status = get_64(); fa->exists_modtime=status; fa->sem->post(); } break; } unlock_mutex(); } }
/* * Process FW debug, FW event and FW log messages * Read the payload and process accordingly. * */ void process_cnss_diag_msg(tAniNlHdr *wnl) { uint8_t *dbgbuf; uint8_t *eventbuf = (uint8_t *)NLMSG_DATA(wnl); uint16_t diag_type = 0; uint32_t event_id = 0; uint16_t length = 0; struct dbglog_slot *slot; uint32_t dropped = 0; dbgbuf = eventbuf; diag_type = *(uint16_t *)eventbuf; eventbuf += sizeof(uint16_t); length = *(uint16_t *)eventbuf; eventbuf += sizeof(uint16_t); if (wnl->nlh.nlmsg_type == WLAN_NL_MSG_CNSS_HOST_MSG && (wnl->wmsg.type == ANI_NL_MSG_LOG_HOST_MSG_TYPE)) { process_cnss_host_message(wnl, optionflag, log_out, &record, max_records); } else if (wnl->nlh.nlmsg_type == WLAN_NL_MSG_CNSS_HOST_EVENT_LOG && (wnl->wmsg.type == ANI_NL_MSG_LOG_HOST_EVENT_LOG_TYPE)) { process_cnss_host_diag_events_log((char *)((char *)&wnl->wmsg.length + sizeof(wnl->wmsg.length)), optionflag); } else { if (diag_type == DIAG_TYPE_FW_EVENT) { eventbuf += sizeof(uint32_t); event_id = *(uint32_t *)eventbuf; eventbuf += sizeof(uint32_t); if (optionflag & QXDM_FLAG) { if (length) event_report_payload(event_id, length, eventbuf); else event_report(event_id); } } else if (diag_type == DIAG_TYPE_FW_LOG) { /* Do nothing for now */ } else if (diag_type == DIAG_TYPE_FW_DEBUG_MSG) { slot =(struct dbglog_slot *)dbgbuf; length = get_le32((uint8_t *)&slot->length); dropped = get_le32((uint8_t *)&slot->dropped); if (optionflag & LOGFILE_FLAG) process_cnss_log_file(dbgbuf); else if (optionflag & (CONSOLE_FLAG | QXDM_FLAG)) dbglog_parse_debug_logs(&slot->payload[0], length, dropped); } else if (diag_type == DIAG_TYPE_FW_MSG) { uint32_t version = 0; slot = (struct dbglog_slot *)dbgbuf; length = get_32((uint8_t *)&slot->length); version = get_le32((uint8_t *)&slot->dropped); process_diagfw_msg(&slot->payload[0], length, optionflag, log_out, &record, max_records, version, sock_fd); } else if (diag_type == DIAG_TYPE_HOST_MSG) { slot = (struct dbglog_slot *)dbgbuf; length = get_32((uint8_t *)&slot->length); process_diaghost_msg(slot->payload, length); } else { /* Do nothing for now */ } } }