void debug_input(unsigned char *buffer, unsigned int recvsize) { netinfo_packed_t *cast; netinfo_packed_net_t *net; netinfo_packed_disk_t *disk; rtinfo_network_legacy_t *read; rtinfo_disk_legacy_t *dev; uint32_t i; char strip[16], devname[64]; dump(buffer, recvsize); cast = (netinfo_packed_t*) buffer; printf("[+] Options : %u\n", be32toh(cast->options)); printf("[+] Hostname : %s\n", cast->hostname); printf("[+] ClientID : %u\n", be32toh(cast->clientid)); // FIXME printf("[+] Version : %u\n\n", be32toh(cast->version)); if(be32toh(cast->options) & QRY_SOCKET) return; if(be32toh(cast->options) & USE_NETWORK) { net = (netinfo_packed_net_t *) cast; printf("[+] Network packet data:\n"); printf("[ ] Interfaces: %d\n", be32toh(net->nbiface)); read = net->net; for(i = 0; i < be32toh(net->nbiface); i++) { if(!inet_ntop(AF_INET, &read->ip, strip, sizeof(strip))) fprintf(stderr, "[-] Cannot extract ip !\n"); if(read->name_length > sizeof(devname)) { fprintf(stderr, "[-] Interface name too long\n"); goto next_read; } strncpy(devname, read->name, read->name_length); devname[read->name_length] = '\0'; printf("[ ] Name : %s [%s]\n", read->name, strip); printf("[ ] Speed: %u\n\n", packed_speed_rtinfo(read->speed)); printf("[ ] Rate : %" PRIu64 " / %" PRIu64 "\n", be64toh(read->up_rate), be64toh(read->down_rate)); printf("[ ] Data : %" PRIu64 " / %" PRIu64 "\n", be64toh(read->current.up), be64toh(read->current.down)); next_read: read = (rtinfo_network_legacy_t*) ( ((char*) read) + read->name_length + sizeof(rtinfo_network_legacy_t) ); } } else if(be32toh(cast->options & USE_SUMMARY)) { printf("[+] Summary packet data:\n"); printf("[ ] CPU Count : %u\n", be32toh(cast->nbcpu)); for(i = 0; i < be32toh(cast->nbcpu); i++) printf("[ ] CPU % 6d : %d\n", i, cast->cpu[i].usage); printf("[ ] Memory RAM : %" PRIu64 " / %" PRIu64 "\n", be64toh(cast->memory.ram_used), be64toh(cast->memory.ram_total)); printf("[ ] Memory SWAP: %" PRIu64 " / %" PRIu64 "\n", be64toh(cast->memory.swap_free), be64toh(cast->memory.swap_total)); printf("[ ] Load Avg. : %.2f / %.2f / %.2f\n", ((float) be32toh(cast->loadavg[0]) / 100), ((float) be32toh(cast->loadavg[1]) / 100), ((float) be32toh(cast->loadavg[2]) / 100)); printf("[ ] Battery : %u / %u / %u / %" PRIu64 "\n", be32toh(cast->battery.charge_full), be32toh(cast->battery.charge_now), cast->battery.load, be64toh(cast->battery.status)); printf("[ ] CPU Temp : %hu / %hu\n", be16toh(cast->temp_cpu.cpu_average), be16toh(cast->temp_cpu.critical)); printf("[ ] HDD Temp : %hu / %hu\n", be16toh(cast->temp_hdd.hdd_average), be16toh(cast->temp_hdd.peak)); printf("[ ] Uptime : %u\n", be32toh(cast->uptime.uptime)); printf("[ ] Timestamp : %u\n\n", be32toh(cast->timestamp)); } else if(be32toh(cast->options) & USE_DISK) { disk = (netinfo_packed_disk_t *) cast; printf("[+] Disk packet data:\n"); printf("[ ] Disks: %d\n", be32toh(disk->nbdisk)); dev = disk->disk; for(i = 0; i < be32toh(disk->nbdisk); i++) { if(dev->name_length > sizeof(devname)) { fprintf(stderr, "[-] Disk name too long\n"); goto next_disk; } strncpy(devname, dev->name, dev->name_length); devname[dev->name_length] = '\0'; printf("[ ] Name : %s\n", dev->name); printf("[ ] Rate : %" PRIu64 " / %" PRIu64 "\n", be64toh(dev->read_speed), be64toh(dev->write_speed)); printf("[ ] Data : %" PRIu64 " / %" PRIu64 "\n", be64toh(dev->bytes_read), be64toh(dev->bytes_written)); printf("[ ] IOPS : %" PRIu64 " \n", be64toh(dev->iops)); next_disk: dev = (rtinfo_disk_legacy_t *) ( ((char*) dev) + dev->name_length + sizeof(rtinfo_disk_legacy_t) ); } } }
/** * This callback is invoked by archive_open(). It returns ARCHIVE_OK * if the underlying file or data source is successfully opened. If * the open fails, it calls archive_set_error() to register an error * code and message and returns ARCHIVE_FATAL. * * -- man 3 archive_read_open. */ static int open_callback(struct archive *archive, void *data_) { CallbackData *data = talloc_get_type_abort(data_, CallbackData); AutoExtractInfo info; struct stat statf; off_t offset; int status; /* Note: data->fd will be closed by close_callback(). */ data->fd = open(data->path, O_RDONLY); if (data->fd < 0) { archive_set_error(archive, errno, "can't open archive"); return ARCHIVE_FATAL; } status = fstat(data->fd, &statf); if (status < 0) { archive_set_error(archive, errno, "can't stat archive"); return ARCHIVE_FATAL; } /* Assume it's a regular archive if it physically can't be a * self-extracting one. */ if (statf.st_size < (off_t) sizeof(AutoExtractInfo)) return ARCHIVE_OK; offset = lseek(data->fd, statf.st_size - sizeof(AutoExtractInfo), SEEK_SET); if (offset == (off_t) -1) { archive_set_error(archive, errno, "can't seek in archive"); return ARCHIVE_FATAL; } status = read(data->fd, &info, sizeof(AutoExtractInfo)); if (status < 0) { archive_set_error(archive, errno, "can't read archive"); return ARCHIVE_FATAL; } if ( status == sizeof(AutoExtractInfo) && strcmp(info.signature, AUTOEXTRACT_SIGNATURE) == 0) { /* This is a self-extracting archive, retrive it's * offset and size. */ data->size = be64toh(info.size); offset = statf.st_size - data->size - sizeof(AutoExtractInfo); note(NULL, INFO, USER, "archive found: offset = %" PRIu64 ", size = %" PRIu64 "", (uint64_t) offset, data->size); } else { /* This is not a self-extracting archive, assume it's * a regular one... */ offset = 0; /* ... unless a self-extracting archive really was * expected. */ if (strcmp(data->path, "/proc/self/exe") == 0) return ARCHIVE_FATAL; } offset = lseek(data->fd, offset, SEEK_SET); if (offset == (off_t) -1) { archive_set_error(archive, errno, "can't seek in archive"); return ARCHIVE_FATAL; } return ARCHIVE_OK; }
// network (big endian) byte order to host byte order uint64_t fast_ntoh(uint64_t value) { return be64toh(value); }
static T network_to_host(T value) { return be64toh(value); }
int main(int argc, char* argv[]) { if(argc<2 || !strcmp(argv[1], "--help")) { fprintf(stderr, "Usage:\n" " fsfs-debug print-index block_size blockgroup_size file.idx [bgstart [bgcount]]\n" " fsfs-debug comp-stats blockgroup_size file.idx\n" " fsfs-debug decompress-block file.dat offset compressed_size > output\n" " fsfs-debug decompress-block2 < input > output\n" " fsfs-debug compress-block < input > output\n" " fsfs-debug compress-block2 < input > output\n" " fsfs-debug calculate-hash < input\n" " fsfs-debug get-length dir name\n" " fsfs-debug read-one-block dir name blocknum\n" ); return 1; } if(!strcmp(argv[1], "print-index")) { int bgsize=1020; int block_size=4096; long long int bgstart = 0; long long int bgcount = -1; assert(argc>=5 && argc<=7); sscanf(argv[2], "%d", &block_size); sscanf(argv[3], "%d", &bgsize); const char* idxfile = argv[4]; if(argc>=6) sscanf(argv[5], "%lld", &bgstart); if(argc>=7) sscanf(argv[6], "%lld", &bgcount); int bglen = bgsize * 2 + 8; FILE* idx = stdin; if(strcmp(argv[2], "-")) idx = fopen(idxfile, "rb"); assert(idx!=NULL); signed short int q; long long int baseoffset; if(bgstart!=0) { int ret = fseek(idx, bgstart*bglen, SEEK_SET); if(ret) { perror("fseek"); return 2;} } while(bgcount!=0) { int ret = fread(&baseoffset, 1, 8, idx); if(ret==0)break; if(ret!=8) { printf("Trimmed index file\n"); return 2; } baseoffset = be64toh(baseoffset); printf("Block group %lld, base offset: 0x%016llX\n", bgstart, baseoffset); int i; int accum = 0; for(i=0; i<bgsize; ++i) { int ret = fread(&q, 1, 2, idx); if(ret!=2) { printf("Trimmed index file\n"); return 2; } q = be16toh(q); printf("block %lld: ", i + bgstart*bgsize); if(q==-0x8000) { printf("zero\n"); } else if(q==-0x7FFF) { printf("uncompressed (%d bytes) at 0x%016llX\n", block_size, baseoffset+accum); accum+=block_size; } else if(q==0) { printf("unallocated\n"); } else if(q>0 && q<0x4444) { printf("compressed (%d bytes) at 0x%016llX\n", q, baseoffset+accum); accum+=q; } else if (q<0 && q >= -64) { printf("reference to %d's dependency\n", (-q)-1); } else { printf("probably invalid (%04X)\n", q); } } fflush(stdout); --bgcount; ++bgstart; } return 0; } else if(!strcmp(argv[1], "comp-stats")) { int bgsize=1020; assert(argc==4); sscanf(argv[2], "%d", &bgsize); const char* idxfile = argv[3]; FILE* idx = stdin; if(strcmp(argv[2], "-")) idx = fopen(idxfile, "rb"); assert(idx!=NULL); long long int baseoffset; signed short int q; unsigned long long int *stats = (unsigned long long int*) malloc(8*32768); unsigned long long int zeroes = 0; unsigned long long int invals = 0; unsigned long long int refs[64]; unsigned long long int total = 0; unsigned long long int uncompressibles = 0; memset(&refs, 0, sizeof(refs)); memset(stats, 0, 8*32768); int i; int trailing_zero_counter=0; for(;;) { int ret = fread(&baseoffset, 1, 8, idx); if(ret!=8)break; baseoffset = be64toh(baseoffset); for(i=0; i<bgsize; ++i) { int ret = fread(&q, 1, 2, idx); if(ret!=2) return 2; q = be16toh(q); if(q>0) { ++stats[q]; }else if(q==-0x7FFF) { ++uncompressibles; }else if(q==-0x8000) { ++zeroes; }else if(q==0) { ++trailing_zero_counter; }else if(q<0 && q>=-64) { ++refs[(-q)-1]; }else{ ++invals; } ++total; } } total-=trailing_zero_counter; long long int running = 0; printf("total: %lld (100%%) ; 0%% \n", total); running+=zeroes; if(zeroes>0)printf("zero: %lld (%g%%) ; %g%%\n", zeroes, 100.0*zeroes/total, 100.0*running/total); for(i=0; i<64; ++i) { running+=refs[i]; if(refs[i]>0)printf("refs[%d]: %lld (%g%%) ; %g%%\n", i, refs[i], 100.0*refs[i]/total, 100.0*running/total); } for(i=0; i<32768; ++i) { running+=stats[i]; if(stats[i]>0)printf("compressed[%d]: %lld (%g%%) ; %g%%\n", i, stats[i], 100.0*stats[i]/total, 100.0*running/total); } running+=uncompressibles; if(uncompressibles>0)printf("uncompressible: %lld (%g%%) ; %g%%\n", uncompressibles, 100.0*uncompressibles/total, 100.0*running/total); running+=invals; if(invals>0)printf("invalid: %lld (%g%%) ; %g%%\n", invals, 100.0*invals/total, 100.0*running/total); free(stats); return 0; } else if(!strcmp(argv[1], "decompress-block")) { assert(argc==5); const char* datfile = argv[2]; long long int offset = 0; int size; sscanf(argv[3], "%lld", &offset); sscanf(argv[4], "%d", &size); FILE* dat = fopen(datfile, "rb"); int ret = fseek(dat, offset, SEEK_SET); assert(ret==0); assert(size<65536); unsigned char chunk[65536]; unsigned char chunk2[65536+2048]; ret = fread(&chunk, 1, size, dat); assert(ret==size); fclose(dat); lzo_uint len = 65536+2048; lzo1x_decompress_safe(chunk, ret, chunk2, &len, NULL); fwrite(chunk2, 1, len, stdout); return 0; } else if(!strcmp(argv[1], "decompress-block2")) { unsigned char chunk[65536]; unsigned char chunk2[65536+2048]; int ret = fread(&chunk, 1, 65536, stdin); lzo_uint len = 65536+2048; lzo1x_decompress_safe(chunk, ret, chunk2, &len, NULL); fwrite(chunk2, 1, len, stdout); return 0; } else if(!strcmp(argv[1], "compress-block")) { unsigned char chunk[65536]; unsigned char chunk2[65536+2048]; int ret = fread(&chunk, 1, 65536, stdin); char tmp[LZO1X_1_MEM_COMPRESS]; lzo_uint len = 65536+2048; lzo1x_1_compress(chunk, ret, chunk2, &len, &tmp); fwrite(chunk2, 1, len, stdout); return 0; } else if(!strcmp(argv[1], "compress-block2")) { unsigned char chunk[65536]; unsigned char chunk2[65536+2048]; int ret = fread(&chunk, 1, 65536, stdin); char tmp[LZO1X_999_MEM_COMPRESS]; lzo_uint len = 65536+2048; lzo1x_999_compress(chunk, ret, chunk2, &len, &tmp); fwrite(chunk2, 1, len, stdout); return 0; } else if(!strcmp(argv[1], "calculate-hash")) { unsigned char chunk[65536]; int ret = fread(&chunk, 1, 65536, stdin); unsigned char c = phash(chunk, ret); printf("%02x\n", c); return 0; } else if(!strcmp(argv[1], "get-length")) { assert(argc==4); const char* dirname = argv[2]; const char* basename = argv[3]; int block_len = storage__get_block_size2(dirname, basename); long long int number_of_blocks = storage__get_number_of_blocks2(dirname, basename); printf("%lld\n", number_of_blocks*block_len); return 0; } else if(!strcmp(argv[1], "read-one-block")) { assert(argc==5); const char* dirname = argv[2]; const char* basename = argv[3]; long long int blocknum; sscanf(argv[4], "%lld", &blocknum); struct storage__file* f = storage__open(dirname, basename); int block_len = storage__get_block_size(f); unsigned char buf[65536]; storage__read_block(f, buf, blocknum); fwrite(buf, 1, block_len, stdout); return 0; } else { fprintf(stderr, "Unknown command %s\n", argv[1]); return 1; } }
int main(int argc, char *argv[]) { struct stream_data stream; struct stream_header hdr; char const *program = "/bin/false"; struct signature_options sigopts = { .min_strength = 0, }; char build_time[8*3 + 2]; char revision[8*3 + 2]; int notify_port = -1; while (1) { int c = getopt_long(argc, argv, "vx:S:", CMDLINE_OPTIONS, NULL); if (c==-1) break; switch (c) { case CMD_HELP : show_help(); case CMD_VERSION : show_version(); case 'x' : program = optarg; break; case 'v' : sigopts.min_strength = 1; break; case 'S': sigopts.min_strength = atoi(optarg); break; case CMD_CAFILE: if (!add_filename(&sigopts.ca_files, optarg)) return EX_OSERR; break; case CMD_CRLFILE: if (!add_filename(&sigopts.crl_files, optarg)) return EX_OSERR; break; case CMD_NOTIFY_PORT: notify_port = atoi(optarg); break; default: fprintf(stderr, "Try --help for more information\n"); return EX_USAGE; } } if (!notification_init(&stream.notify, notify_port)) return EX_OSERR; if (!stream_data_open(&stream, 0)) signal_return(&stream, EX_OSERR); if (!stream_data_read_params(&stream)) signal_return(&stream, EX_DATAERR); if (!stream_data_read(&stream, &hdr, sizeof hdr, false)) signal_return(&stream, EX_DATAERR); if (be32toh(hdr.magic) != STREAM_HEADER_MAGIC) { fprintf(stderr, "bad stream magic\n"); signal_return(&stream, EX_DATAERR); } if (!read_hdr_ext(&stream, be32toh(hdr.version), be32toh(hdr.extra_header))) signal_return(&stream, EX_DATAERR); sprintf(build_time, "%" PRIu64, be64toh(hdr.build_time)); setenv("STREAM_BUILD_TIME", build_time, 1); sprintf(revision, "%" PRIx64, be64toh(stream.revision)); setenv("STREAM_REVISION", revision, 1); notification_send_length(&stream.notify, stream.total_len); if (!stage_transaction(program, "start")) signal_return(&stream, EX_OSERR); for (;;) { struct stream_hunk_header hhdr; struct memory_block_data payload; struct memory_block_signature signature; if (!stream_data_read(&stream, &hhdr, sizeof hhdr, true)) signal_return(&stream, EX_DATAERR); if (stream.is_eos) break; payload.mem.stream = &stream; payload.mem.len = be32toh(hhdr.hunk_len); payload.mem.data = NULL; payload.type = be32toh(hhdr.type); payload.compression = hhdr.compress_type; payload.len = be32toh(hhdr.decompress_len); signature.opts = &sigopts; signature.pre.stream = &stream; signature.pre.len = be32toh(hhdr.prefix_len); signature.pre.data = NULL; signature.mem.stream = &stream; signature.mem.len = be32toh(hhdr.fixed_sign_len); signature.mem.data = NULL; signature.type = hhdr.sign_type; signature.shdr = &hdr; signature.hhdr = &hhdr; if (!process_hunk(program, &stream.notify, &payload, &signature)) signal_return(&stream, EX_DATAERR); } stream_data_close(&stream); free(sigopts.ca_files.names); free(sigopts.crl_files.names); if (!stage_transaction(program, "end")) signal_return(&stream, EX_OSERR); signal_return(&stream, EX_OK); }
double RobotState::ntohd(uint64_t nf) { double x; nf = be64toh(nf); memcpy(&x, &nf, sizeof(x)); return x; }
static void ar5416_decode_txstatus(struct if_ath_alq_payload *a) { struct ar5416_desc txs; /* XXX assumes txs is smaller than PAYLOAD_LEN! */ memcpy(&txs, &a->payload, sizeof(struct ar5416_desc)); printf("[%u.%06u] [%llu] TXSTATUS: TxDone=%d, FrmOk=%d, filt=%d, TS=0x%08x\n", (unsigned int) be32toh(a->hdr.tstamp_sec), (unsigned int) be32toh(a->hdr.tstamp_usec), (unsigned long long) be64toh(a->hdr.threadid), MF(txs.u.tx.status[9], AR_TxDone), MF(txs.u.tx.status[1], AR_FrmXmitOK), MF(txs.u.tx.status[1], AR_Filtered), txs.u.tx.status[2]); /* ds_txstatus0 */ printf(" RX RSSI 0 [%d %d %d]", MS(txs.u.tx.status[0], AR_TxRSSIAnt00), MS(txs.u.tx.status[0], AR_TxRSSIAnt01), MS(txs.u.tx.status[0], AR_TxRSSIAnt02)); /* ds_txstatus5 */ printf(" RX RSSI 1 [%d %d %d] Comb=%d\n", MS(txs.u.tx.status[5], AR_TxRSSIAnt10), MS(txs.u.tx.status[5], AR_TxRSSIAnt11), MS(txs.u.tx.status[5], AR_TxRSSIAnt12), MS(txs.u.tx.status[5], AR_TxRSSICombined)); /* ds_txstatus0 */ printf(" BA Valid=%d", MF(txs.u.tx.status[0], AR_TxBaStatus)); /* ds_txstatus1 */ printf(", Frmok=%d, xretries=%d, fifounderrun=%d, filt=%d\n", MF(txs.u.tx.status[1], AR_FrmXmitOK), MF(txs.u.tx.status[1], AR_ExcessiveRetries), MF(txs.u.tx.status[1], AR_FIFOUnderrun), MF(txs.u.tx.status[1], AR_Filtered)); printf(" DelimUnderrun=%d, DataUnderun=%d, DescCfgErr=%d," " TxTimerExceeded=%d\n", MF(txs.u.tx.status[1], AR_TxDelimUnderrun), MF(txs.u.tx.status[1], AR_TxDataUnderrun), MF(txs.u.tx.status[1], AR_DescCfgErr), MF(txs.u.tx.status[1], AR_TxTimerExpired)); printf(" RTScnt=%d, FailCnt=%d, VRetryCnt=%d\n", MS(txs.u.tx.status[1], AR_RTSFailCnt), MS(txs.u.tx.status[1], AR_DataFailCnt), MS(txs.u.tx.status[1], AR_VirtRetryCnt)); /* ds_txstatus2 */ printf(" TxTimestamp=0x%08x", txs.u.tx.status[2]); /* ds_txstatus3 */ /* ds_txstatus4 */ printf(", BALow=0x%08x", txs.u.tx.status[3]); printf(", BAHigh=0x%08x\n", txs.u.tx.status[4]); /* ds_txstatus6 */ /* ds_txstatus7 */ /* ds_txstatus8 */ printf(" TxEVM[0]=0x%08x, TxEVM[1]=0x%08x, TxEVM[2]=0x%08x\n", txs.u.tx.status[6], txs.u.tx.status[7], txs.u.tx.status[8]); /* ds_txstatus9 */ printf(" TxDone=%d, SeqNum=0x%04x, TxOpExceeded=%d, FinalTsIdx=%d\n", MF(txs.u.tx.status[9], AR_TxDone), MS(txs.u.tx.status[9], AR_SeqNum), MF(txs.u.tx.status[9], AR_TxOpExceeded), MS(txs.u.tx.status[9], AR_FinalTxIdx)); printf(" PowerMgmt=%d, TxTid=%d\n", MF(txs.u.tx.status[9], AR_PowerMgmt), MS(txs.u.tx.status[9], AR_TxTid)); printf("\n ------\n"); }
// Run the UDP receiving thread void PacketChunker::run() { // Define variables for packet augmentation unsigned long _currTime = 0; unsigned _numPackets = 0; // Main processing loop for (unsigned i = 0;; ) { // Fetch next frame and check whether it is available for processing volatile struct tpacket_hdr *header = (struct tpacket_hdr *) _ring[i].iov_base; // Data not available yet, wait until it is // We can just spin lock over here, packets will be available very soon while(!(header -> tp_status & TP_STATUS_USER)) ; // Data is now available, we can process the current frame // NOTE: The data routines will be able to detect whether we're losing packets // Get pointer to frame data unsigned char *frame = (unsigned char *) header + FRAME_OFFSET; // Extract IP information from packet struct iphdr *ip_header = (struct iphdr *) (frame + sizeof(ethhdr)); // TODO: Check whether packet was meant for us // Extract UDP information struct udphdr *udp_header = (struct udphdr *) (((char *) ip_header) + ip_header -> ihl * 4); // Check whether ports match, otherwise skip if (ntohs(udp_header -> dest) != _port) { header -> tp_status = 0; i = ( i == _nframes - 1) ? 0 : i + 1; printf("Invalid packet\n"); continue; } // Get UDP packet contents unsigned char *data = (unsigned char *) (((char *) udp_header) + sizeof(udphdr)); long unsigned data_header = be64toh(((uint64_t *) data)[0]); unsigned long time = data_header >> 26; unsigned short channel = (data_header >> 16) & 0x03FF; // Tackle reordering issue if (channel % 2 == 0) channel /= 2; else channel = 512 + (channel - 1) / 2; float value = 0; for(unsigned j = 0; j < PACKET_DATA_LEN; j++) value += data[PACKET_HEADER_LEN + j]; // Check if we are processing a new heap if (_currTime == 0) _currTime = time; // Check if the time in the header corresponds to the time of the // heap being processed, or if we've advanced one heap if (_currTime != time) { // We have received a packet from the previous buffer if (time < _currTime) fprintf(stderr, "PacketChunker: Received out of place packer, discarding\n"); // We have moved on to a new heap (lost some packets) else { // We are processing a packet from a new heap fprintf(stderr, "We have lost some packets: %d of %d for %ld\n", _numPackets, _npackets, _currTime); // Mark previous heap as finished _heap = _buffer -> writeHeap(1457442095.000001 + (1024 * _currTime) / (40e6/2.0/128.0), 1 / 19531.25); // Copy to new heap memcpy(_heap + channel * _nantennas * _nsamp, data + PACKET_HEADER_LEN, PACKET_DATA_LEN); _numPackets = 1; _currTime = time; } } // Everything OK, process else { // Write packet to disk // FILE *fp = fopen("packet.dat", "wb"); // fwrite(data + PACKET_HEADER_LEN, sizeof(unsigned char), PACKET_DATA_LEN, fp); // fclose(fp); // printf("Written packet to disk\n"); // sleep(60); // exit(0); // Place packet data in circular buffer memcpy(_heap + channel * _nantennas * _nsamp, data + PACKET_HEADER_LEN, PACKET_DATA_LEN); // If we have processed enough packets to form one heap, advance to the next heap _numPackets++; if (_numPackets == _npackets) { // Mark heap as finished _heap = _buffer -> writeHeap(1457442095.000001 + (1024 * _currTime) / (40e6/2.0/128.0), 1 / 19531.25); _currTime = 0; _numPackets = 0; } } // Tell kernel that this packet has been processed header -> tp_status = 0; // Advance to next frame i = ( i == _nframes - 1) ? 0 : i + 1; } }
static void ar5416_decode_txdesc(struct if_ath_alq_payload *a) { struct ar5416_desc txc; /* XXX assumes txs is smaller than PAYLOAD_LEN! */ memcpy(&txc, &a->payload, sizeof(struct ar5416_desc)); printf("[%u.%06u] [%llu] TXD\n", (unsigned int) be32toh(a->hdr.tstamp_sec), (unsigned int) be32toh(a->hdr.tstamp_usec), (unsigned long long) be64toh(a->hdr.threadid)); printf(" link=0x%08x, data=0x%08x\n", txc.ds_link, txc.ds_data); /* ds_ctl0 */ printf(" Frame Len=%d, VMF=%d\n", txc.ds_ctl0 & AR_FrameLen, MF(txc.ds_ctl0, AR_VirtMoreFrag)); printf(" TX power0=%d, RtsEna=%d, Veol=%d, ClrDstMask=%d\n", MS(txc.ds_ctl0, AR_XmitPower), MF(txc.ds_ctl0, AR_RTSEnable), MF(txc.ds_ctl0, AR_VEOL), MF(txc.ds_ctl0, AR_ClrDestMask)); printf(" TxIntrReq=%d, DestIdxValid=%d, CtsEnable=%d\n", MF(txc.ds_ctl0, AR_TxIntrReq), MF(txc.ds_ctl0, AR_DestIdxValid), MF(txc.ds_ctl0, AR_CTSEnable)); /* ds_ctl1 */ printf(" BufLen=%d, TxMore=%d, DestIdx=%d," " FrType=0x%x\n", txc.ds_ctl1 & AR_BufLen, MF(txc.ds_ctl1, AR_TxMore), MS(txc.ds_ctl1, AR_DestIdx), MS(txc.ds_ctl1, AR_FrameType)); printf(" NoAck=%d, InsertTs=%d, CorruptFcs=%d, ExtOnly=%d," " ExtAndCtl=%d\n", MF(txc.ds_ctl1, AR_NoAck), MF(txc.ds_ctl1, AR_InsertTS), MF(txc.ds_ctl1, AR_CorruptFCS), MF(txc.ds_ctl1, AR_ExtOnly), MF(txc.ds_ctl1, AR_ExtAndCtl)); printf(" MoreAggr=%d, IsAggr=%d, MoreRifs=%d\n", MF(txc.ds_ctl1, AR_MoreAggr), MF(txc.ds_ctl1, AR_IsAggr), MF(txc.ds_ctl1, AR_MoreRifs)); /* ds_ctl2 */ printf(" DurUpEna=%d, Burstdur=0x%04x\n", MF(txc.ds_ctl2, AR_DurUpdateEn), MS(txc.ds_ctl2, AR_BurstDur)); printf(" Try0=%d, Try1=%d, Try2=%d, Try3=%d\n", MS(txc.ds_ctl2, AR_XmitDataTries0), MS(txc.ds_ctl2, AR_XmitDataTries1), MS(txc.ds_ctl2, AR_XmitDataTries2), MS(txc.ds_ctl2, AR_XmitDataTries3)); /* ds_ctl3, 4 */ printf(" try 0: Rate=0x%02x, PktDur=%d, RTS/CTS ena=%d\n", MS(txc.ds_ctl3, AR_XmitRate0), MS(txc.ds_ctl4, AR_PacketDur0), MF(txc.ds_ctl4, AR_RTSCTSQual0)); printf(" try 1: Rate=0x%02x, PktDur=%d, RTS/CTS ena=%d\n", MS(txc.ds_ctl3, AR_XmitRate1), MS(txc.ds_ctl4, AR_PacketDur1), MF(txc.ds_ctl4, AR_RTSCTSQual1)); /* ds_ctl3, 5 */ printf(" try 2: Rate=0x%02x, PktDur=%d, RTS/CTS ena=%d\n", MS(txc.ds_ctl3, AR_XmitRate2), MS(txc.ds_ctl5, AR_PacketDur2), MF(txc.ds_ctl5, AR_RTSCTSQual2)); printf(" try 3: Rate=0x%02x, PktDur=%d, RTS/CTS ena=%d\n", MS(txc.ds_ctl3, AR_XmitRate3), MS(txc.ds_ctl5, AR_PacketDur3), MF(txc.ds_ctl5, AR_RTSCTSQual3)); /* ds_ctl6 */ printf(" AggrLen=%d, PadDelim=%d, EncrType=%d\n", MS(txc.ds_ctl6, AR_AggrLen), MS(txc.ds_ctl6, AR_PadDelim), MS(txc.ds_ctl6, AR_EncrType)); /* ds_ctl7 */ printf(" try 0: chainMask=0x%x, GI=%d, 2040=%d, STBC=%d\n", MS(txc.ds_ctl7, AR_ChainSel0), MF(txc.ds_ctl7, AR_GI0), MF(txc.ds_ctl7, AR_2040_0), MF(txc.ds_ctl7, AR_STBC0)); printf(" try 1: chainMask=0x%x, GI=%d, 2040=%d, STBC=%d\n", MS(txc.ds_ctl7, AR_ChainSel1), MF(txc.ds_ctl7, AR_GI1), MF(txc.ds_ctl7, AR_2040_1), MF(txc.ds_ctl7, AR_STBC1)); printf(" try 2: chainMask=0x%x, GI=%d, 2040=%d, STBC=%d\n", MS(txc.ds_ctl7, AR_ChainSel2), MF(txc.ds_ctl7, AR_GI2), MF(txc.ds_ctl7, AR_2040_2), MF(txc.ds_ctl7, AR_STBC2)); printf(" try 3: chainMask=0x%x, GI=%d, 2040=%d, STBC=%d\n", MS(txc.ds_ctl7, AR_ChainSel3), MF(txc.ds_ctl7, AR_GI3), MF(txc.ds_ctl7, AR_2040_3), MF(txc.ds_ctl7, AR_STBC3)); printf(" RTSCtsRate=0x%02x\n", MS(txc.ds_ctl7, AR_RTSCTSRate)); /* ds_ctl8 */ printf(" try 0: ant=0x%08x\n", txc.ds_ctl8 & AR_AntCtl0); /* ds_ctl9 */ printf(" try 1: TxPower=%d, ant=0x%08x\n", MS(txc.ds_ctl9, AR_XmitPower1), txc.ds_ctl9 & AR_AntCtl1); /* ds_ctl10 */ printf(" try 2: TxPower=%d, ant=0x%08x\n", MS(txc.ds_ctl10, AR_XmitPower2), txc.ds_ctl10 & AR_AntCtl2); /* ds_ctl11 */ printf(" try 3: TxPower=%d, ant=0x%08x\n", MS(txc.ds_ctl11, AR_XmitPower3), txc.ds_ctl11 & AR_AntCtl3); printf("\n ------ \n"); }
static void ar5416_decode_rxstatus(struct if_ath_alq_payload *a) { struct ar5416_desc rxs; /* XXX assumes rxs is smaller than PAYLOAD_LEN! */ memcpy(&rxs, &a->payload, sizeof(struct ar5416_desc)); printf("[%u.%06u] [%llu] RXSTATUS: RxDone=%d, RxRate=0x%02x, TS=0x%08x\n", (unsigned int) be32toh(a->hdr.tstamp_sec), (unsigned int) be32toh(a->hdr.tstamp_usec), (unsigned long long) be64toh(a->hdr.threadid), MF(rxs.ds_rxstatus8, AR_RxDone), MS(rxs.ds_rxstatus0, AR_RxRate), rxs.ds_rxstatus2); printf(" link=0x%08x, data=0x%08x, ctl0=0x%08x, ctl2=0x%08x\n", rxs.ds_link, rxs.ds_data, rxs.ds_ctl0, rxs.ds_ctl1); /* status0 */ /* * XXX TODO: For AR9285, the chain 1 and chain 2 RSSI values * acutally contain the RX mixer configuration */ printf(" RSSICtl[0]=%d, RSSICtl[1]=%d, RSSICtl[2]=%d\n", MS(rxs.ds_rxstatus0, AR_RxRSSIAnt00), MS(rxs.ds_rxstatus0, AR_RxRSSIAnt01), MS(rxs.ds_rxstatus0, AR_RxRSSIAnt02)); /* status4 */ printf(" RSSIExt[0]=%d, RSSIExt[1]=%d, RSSIExt[2]=%d, RSSIComb=%d\n", MS(rxs.ds_rxstatus4, AR_RxRSSIAnt10), MS(rxs.ds_rxstatus4, AR_RxRSSIAnt11), MS(rxs.ds_rxstatus4, AR_RxRSSIAnt12), MS(rxs.ds_rxstatus4, AR_RxRSSICombined)); /* status2 */ printf(" RxTimestamp=0x%08x,", rxs.ds_rxstatus2); /* status1 */ printf(" DataLen=%d, RxMore=%d, NumDelim=%d\n", rxs.ds_rxstatus1 & AR_DataLen, MF(rxs.ds_rxstatus1, AR_RxMore), MS(rxs.ds_rxstatus1, AR_NumDelim)); /* status3 - RxRate however is for Owl 2.0 */ printf(" GI=%d, 2040=%d, RxRate=0x%02x, DupFrame=%d, RxAnt=0x%08x\n", MF(rxs.ds_rxstatus3, AR_GI), MF(rxs.ds_rxstatus3, AR_2040), MS(rxs.ds_rxstatus0, AR_RxRate), MF(rxs.ds_rxstatus3, AR_DupFrame), MS(rxs.ds_rxstatus3, AR_RxAntenna)); /* status5 */ /* status6 */ /* status7 */ printf(" RxEvm0=0x%08x, RxEvm1=0x%08x, RxEvm2=0x%08x\n", rxs.ds_rxstatus5, rxs.ds_rxstatus6, rxs.ds_rxstatus7); /* status8 */ printf(" RxDone=%d, RxFrameOk=%d, CrcErr=%d, DecryptCrcErr=%d\n", MF(rxs.ds_rxstatus8, AR_RxDone), MF(rxs.ds_rxstatus8, AR_RxFrameOK), MF(rxs.ds_rxstatus8, AR_CRCErr), MF(rxs.ds_rxstatus8, AR_DecryptCRCErr)); printf(" PhyErr=%d, MichaelErr=%d, PreDelimCRCErr=%d, KeyIdxValid=%d\n", MF(rxs.ds_rxstatus8, AR_PHYErr), MF(rxs.ds_rxstatus8, AR_MichaelErr), MF(rxs.ds_rxstatus8, AR_PreDelimCRCErr), MF(rxs.ds_rxstatus8, AR_RxKeyIdxValid)); printf(" RxMoreAggr=%d, RxAggr=%d, PostDelimCRCErr=%d, HiRxChain=%d\n", MF(rxs.ds_rxstatus8, AR_RxMoreAggr), MF(rxs.ds_rxstatus8, AR_RxAggr), MF(rxs.ds_rxstatus8, AR_PostDelimCRCErr), MF(rxs.ds_rxstatus8, AR_HiRxChain)); /* If PHY error, print that out. Otherwise, the key index */ if (MF(rxs.ds_rxstatus8, AR_PHYErr)) printf(" PhyErrCode=0x%02x", MS(rxs.ds_rxstatus8, AR_PHYErrCode)); else printf(" KeyIdx=0x%02x", MS(rxs.ds_rxstatus8, AR_KeyIdx)); printf(", KeyMiss=%d\n", MF(rxs.ds_rxstatus8, AR_KeyMiss)); printf("\n ------\n"); }
int main(int argc, char **argv) { int rv; int fd = open(argv[1], O_RDWR); struct lead lead; pread(fd, &lead, sizeof(lead), 0); // First header struct header hdr; pread(fd, &hdr, sizeof(hdr), sizeof(lead)); hdr.nindex = be32toh(hdr.nindex); hdr.len = be32toh(hdr.len); long hdrofs = sizeof(struct lead); long idxofs = hdrofs + sizeof(struct header); long storeofs = idxofs + hdr.nindex * sizeof(struct idxentry); printf("== Signatures ==\nHeader offset: 0x%lx\nIndex offset: 0x%lx\n" "Store: 0x%lx - 0x%lx\nIndex entries (%u):\n", hdrofs, idxofs, storeofs, storeofs + hdr.len, hdr.nindex); int i; int64_t remsize = -1; for (i = 0; i < hdr.nindex; i++) { struct idxentry ent; pread(fd, &ent, sizeof(ent), idxofs + i * sizeof(struct idxentry)); ent.tag = be32toh(ent.tag); ent.type = be32toh(ent.type); ent.offset = storeofs + be32toh(ent.offset); ent.count = be32toh(ent.count); if (ent.tag == RPMSIGTAG_LONGSIZE) { assert(ent.type == RPM_INT64_TYPE); assert(ent.count == 1); pread(fd, &remsize, sizeof(remsize), ent.offset); remsize = be64toh(remsize); } else if (ent.tag == RPMSIGTAG_SIZE) { assert(ent.type == RPM_INT32_TYPE); assert(ent.count == 1); uint32_t remsize32 = 0; pread(fd, &remsize32, sizeof(remsize32), ent.offset); remsize = be32toh(remsize32); } const char *name = hdr_tag_name(ent.tag); if (name) printf(" %s: ", name); else printf(" %d: ", ent.tag); print_value(fd, &ent); printf("\n"); if (i == 0) { // Is this what "sealed" means? uint32_t tag = ent.tag; assert(TAG_IS_REGION(tag)); assert(ent.type == RPM_BIN_TYPE); assert(ent.count == 16); pread(fd, &ent, sizeof(ent), ent.offset); ent.tag = be32toh(ent.tag); ent.type = be32toh(ent.type); ent.offset = storeofs + be32toh(ent.offset); ent.count = be32toh(ent.count); assert(ent.tag == tag); assert(ent.type == RPM_BIN_TYPE); assert(ent.count == 16); assert(ent.offset == idxofs); } } printf("\n"); assert(remsize >= 0); // Pad to 8-byte alignment and seek past pad hdrofs = storeofs + hdr.len; hdrofs = ((hdrofs + 7) / 8) * 8; lseek(fd, hdrofs, SEEK_SET); // Second header pread(fd, &hdr, sizeof(hdr), hdrofs); hdr.nindex = be32toh(hdr.nindex); hdr.len = be32toh(hdr.len); idxofs = hdrofs + sizeof(struct header); storeofs = idxofs + hdr.nindex * sizeof(struct idxentry); printf("== Header ==\nTotal filesize: 0x%lx\nHeader offset: 0x%lx\n" "Index offset: 0x%lx\nStore: 0x%lx - 0x%lx\nIndex entries (%u):\n", hdrofs + remsize, hdrofs, idxofs, storeofs, storeofs + hdr.len, hdr.nindex); for (i = 0; i < hdr.nindex; i++) { struct idxentry ent; pread(fd, &ent, sizeof(ent), idxofs + i * sizeof(struct idxentry)); ent.tag = be32toh(ent.tag); ent.type = be32toh(ent.type); ent.offset = storeofs + be32toh(ent.offset); ent.count = be32toh(ent.count); const char *name = sig_tag_name(ent.tag); if (name) printf(" %s: ", name); else printf(" %d: ", ent.tag); print_value(fd, &ent); printf("\n"); } printf("\n"); close(fd); return 0; }
static void print_state(struct pfsync_state *s) { struct pfsync_state_peer *src, *dst; struct pfsync_state_key *sk, *nk; int min, sec; if (s->direction == PF_OUT) { src = &s->src; dst = &s->dst; sk = &s->key[PF_SK_STACK]; nk = &s->key[PF_SK_WIRE]; if (s->proto == IPPROTO_ICMP || s->proto == IPPROTO_ICMPV6) sk->port[0] = nk->port[0]; } else { src = &s->dst; dst = &s->src; sk = &s->key[PF_SK_WIRE]; nk = &s->key[PF_SK_STACK]; if (s->proto == IPPROTO_ICMP || s->proto == IPPROTO_ICMPV6) sk->port[1] = nk->port[1]; } printf("\t%s ", s->ifname); printf("proto %u ", s->proto); print_host(&nk->addr[1], nk->port[1], s->af, NULL); if (PF_ANEQ(&nk->addr[1], &sk->addr[1], s->af) || nk->port[1] != sk->port[1]) { printf(" ("); print_host(&sk->addr[1], sk->port[1], s->af, NULL); printf(")"); } if (s->direction == PF_OUT) printf(" -> "); else printf(" <- "); print_host(&nk->addr[0], nk->port[0], s->af, NULL); if (PF_ANEQ(&nk->addr[0], &sk->addr[0], s->af) || nk->port[0] != sk->port[0]) { printf(" ("); print_host(&sk->addr[0], sk->port[0], s->af, NULL); printf(")"); } print_src_dst(src, dst, s->proto); if (vflag > 1) { uint64_t packets[2]; uint64_t bytes[2]; uint32_t creation = ntohl(s->creation); uint32_t expire = ntohl(s->expire); sec = creation % 60; creation /= 60; min = creation % 60; creation /= 60; printf("\n\tage %.2u:%.2u:%.2u", creation, min, sec); sec = expire % 60; expire /= 60; min = expire % 60; expire /= 60; printf(", expires in %.2u:%.2u:%.2u", expire, min, sec); bcopy(s->packets[0], &packets[0], sizeof(uint64_t)); bcopy(s->packets[1], &packets[1], sizeof(uint64_t)); bcopy(s->bytes[0], &bytes[0], sizeof(uint64_t)); bcopy(s->bytes[1], &bytes[1], sizeof(uint64_t)); printf(", %ju:%ju pkts, %ju:%ju bytes", be64toh(packets[0]), be64toh(packets[1]), be64toh(bytes[0]), be64toh(bytes[1])); if (s->anchor != ntohl(-1)) printf(", anchor %u", ntohl(s->anchor)); if (s->rule != ntohl(-1)) printf(", rule %u", ntohl(s->rule)); } if (vflag > 1) { uint64_t id; bcopy(&s->id, &id, sizeof(uint64_t)); printf("\n\tid: %016jx creatorid: %08x", (uintmax_t )be64toh(id), ntohl(s->creatorid)); } }
static struct g_geom * g_uzip_taste(struct g_class *mp, struct g_provider *pp, int flags) { int error; uint32_t i, total_offsets, offsets_read, blk; void *buf; struct cloop_header *header; struct g_consumer *cp; struct g_geom *gp; struct g_provider *pp2; struct g_uzip_softc *sc; g_trace(G_T_TOPOLOGY, "%s(%s,%s)", __func__, mp->name, pp->name); g_topology_assert(); /* Skip providers that are already open for writing. */ if (pp->acw > 0) return (NULL); buf = NULL; /* * Create geom instance. */ gp = g_new_geomf(mp, "%s.uzip", pp->name); cp = g_new_consumer(gp); error = g_attach(cp, pp); if (error == 0) error = g_access(cp, 1, 0, 0); if (error) { g_detach(cp); g_destroy_consumer(cp); g_destroy_geom(gp); return (NULL); } g_topology_unlock(); /* * Read cloop header, look for CLOOP magic, perform * other validity checks. */ DPRINTF(("%s: media sectorsize %u, mediasize %jd\n", gp->name, pp->sectorsize, (intmax_t)pp->mediasize)); buf = g_read_data(cp, 0, pp->sectorsize, NULL); if (buf == NULL) goto err; header = (struct cloop_header *) buf; if (strncmp(header->magic, CLOOP_MAGIC_START, sizeof(CLOOP_MAGIC_START) - 1) != 0) { DPRINTF(("%s: no CLOOP magic\n", gp->name)); goto err; } if (header->magic[0x0b] != 'V' || header->magic[0x0c] < '2') { DPRINTF(("%s: image version too old\n", gp->name)); goto err; } /* * Initialize softc and read offsets. */ sc = malloc(sizeof(*sc), M_GEOM_UZIP, M_WAITOK | M_ZERO); gp->softc = sc; sc->blksz = ntohl(header->blksz); sc->nblocks = ntohl(header->nblocks); if (sc->blksz % 512 != 0) { printf("%s: block size (%u) should be multiple of 512.\n", gp->name, sc->blksz); goto err; } if (sc->blksz > MAX_BLKSZ) { printf("%s: block size (%u) should not be larger than %d.\n", gp->name, sc->blksz, MAX_BLKSZ); } total_offsets = sc->nblocks + 1; if (sizeof(struct cloop_header) + total_offsets * sizeof(uint64_t) > pp->mediasize) { printf("%s: media too small for %u blocks\n", gp->name, sc->nblocks); goto err; } sc->offsets = malloc( total_offsets * sizeof(uint64_t), M_GEOM_UZIP, M_WAITOK); offsets_read = MIN(total_offsets, (pp->sectorsize - sizeof(*header)) / sizeof(uint64_t)); for (i = 0; i < offsets_read; i++) sc->offsets[i] = be64toh(((uint64_t *) (header + 1))[i]); DPRINTF(("%s: %u offsets in the first sector\n", gp->name, offsets_read)); for (blk = 1; offsets_read < total_offsets; blk++) { uint32_t nread; free(buf, M_GEOM); buf = g_read_data( cp, blk * pp->sectorsize, pp->sectorsize, NULL); if (buf == NULL) goto err; nread = MIN(total_offsets - offsets_read, pp->sectorsize / sizeof(uint64_t)); DPRINTF(("%s: %u offsets read from sector %d\n", gp->name, nread, blk)); for (i = 0; i < nread; i++) { sc->offsets[offsets_read + i] = be64toh(((uint64_t *) buf)[i]); } offsets_read += nread; } free(buf, M_GEOM); DPRINTF(("%s: done reading offsets\n", gp->name)); mtx_init(&sc->last_mtx, "geom_uzip cache", NULL, MTX_DEF); sc->last_blk = -1; sc->last_buf = malloc(sc->blksz, M_GEOM_UZIP, M_WAITOK); sc->req_total = 0; sc->req_cached = 0; g_topology_lock(); pp2 = g_new_providerf(gp, "%s", gp->name); pp2->sectorsize = 512; pp2->mediasize = (off_t)sc->nblocks * sc->blksz; pp2->stripesize = pp->stripesize; pp2->stripeoffset = pp->stripeoffset; g_error_provider(pp2, 0); g_access(cp, -1, 0, 0); DPRINTF(("%s: taste ok (%d, %jd), (%d, %d), %x\n", gp->name, pp2->sectorsize, (intmax_t)pp2->mediasize, pp2->stripeoffset, pp2->stripesize, pp2->flags)); printf("%s: %u x %u blocks\n", gp->name, sc->nblocks, sc->blksz); return (gp); err: g_topology_lock(); g_access(cp, -1, 0, 0); if (buf != NULL) free(buf, M_GEOM); if (gp->softc != NULL) { g_uzip_softc_free(gp->softc, NULL); gp->softc = NULL; } g_detach(cp); g_destroy_consumer(cp); g_destroy_geom(gp); return (NULL); }
void eServiceDVD::loadCuesheet() { FILE* f; { std::string filename = m_ref.path; filename += "/dvd.cuts"; f = fopen(filename.c_str(), "rb"); } if (f == NULL) { char filename[128]; if ( m_ddvd_titlestring[0] != '\0' ) snprintf(filename, sizeof(filename), "/home/root/dvd-%s.cuts", m_ddvd_titlestring); else { struct stat st; if (stat(m_ref.path.c_str(), &st) == 0) { // DVD has no name and cannot be written. Use the mtime to generate something unique... snprintf(filename, 128, "/home/root/dvd-%x.cuts", st.st_mtime); } else { strcpy(filename, "/home/root/dvd-untitled.cuts"); } } eDebug("[eServiceDVD] loadCuesheet filename=%s",filename); f = fopen(filename, "rb"); } if (f) { unsigned long long where; unsigned int what; if (!fread(&where, sizeof(where), 1, f)) return; if (!fread(&what, sizeof(what), 1, f)) return; where = be64toh(where); what = ntohl(what); if (!fread(&m_resume_info, sizeof(struct ddvd_resume), 1, f)) return; if (!fread(&what, sizeof(what), 1, f)) return; what = ntohl(what); if (what != 4 ) return; m_cue_pts = where; fclose(f); } else eDebug("[eServiceDVD] cutfile not found!"); if (m_cue_pts) { m_event((iPlayableService*)this, evCuesheetChanged); eDebug("[eServiceDVD] loadCuesheet pts=%lld",m_cue_pts); } }
static void ar5212_decode_txdesc(struct if_ath_alq_payload *a) { struct ar5212_desc txc; /* XXX assumes txs is smaller than PAYLOAD_LEN! */ memcpy(&txc, &a->payload, sizeof(struct ar5212_desc)); printf("[%u.%06u] [%llu] TXD\n", (unsigned int) be32toh(a->hdr.tstamp_sec), (unsigned int) be32toh(a->hdr.tstamp_usec), (unsigned long long) be64toh(a->hdr.threadid)); printf(" link=0x%08x, data=0x%08x\n", txc.ds_link, txc.ds_data); /* ds_ctl0 */ printf(" Frame Len=%d\n", txc.ds_ctl0 & AR_FrameLen); printf(" TX power0=%d, RtsEna=%d, Veol=%d, ClrDstMask=%d AntModeXmit=0x%02x\n", MS(txc.ds_ctl0, AR_XmitPower), MF(txc.ds_ctl0, AR_RTSCTSEnable), MF(txc.ds_ctl0, AR_VEOL), MF(txc.ds_ctl0, AR_ClearDestMask), MF(txc.ds_ctl0, AR_AntModeXmit)); printf(" TxIntrReq=%d, DestIdxValid=%d, CtsEnable=%d\n", MF(txc.ds_ctl0, AR_TxInterReq), MF(txc.ds_ctl0, AR_DestIdxValid), MF(txc.ds_ctl0, AR_CTSEnable)); /* ds_ctl1 */ printf(" BufLen=%d, TxMore=%d, DestIdx=%d," " FrType=0x%x\n", txc.ds_ctl1 & AR_BufLen, MF(txc.ds_ctl1, AR_More), MS(txc.ds_ctl1, AR_DestIdx), MS(txc.ds_ctl1, AR_FrmType)); printf(" NoAck=%d, CompProc=%d, CompIVLen=%d, CompICVLen=%d\n", MF(txc.ds_ctl1, AR_NoAck), MS(txc.ds_ctl1, AR_CompProc), MS(txc.ds_ctl1, AR_CompIVLen), MS(txc.ds_ctl1, AR_CompICVLen)); /* ds_ctl2 */ printf(" DurUpEna=%d, Burstdur=0x%04x\n", MF(txc.ds_ctl2, AR_DurUpdateEna), MS(txc.ds_ctl2, AR_RTSCTSDuration)); printf(" Try0=%d, Try1=%d, Try2=%d, Try3=%d\n", MS(txc.ds_ctl2, AR_XmitDataTries0), MS(txc.ds_ctl2, AR_XmitDataTries1), MS(txc.ds_ctl2, AR_XmitDataTries2), MS(txc.ds_ctl2, AR_XmitDataTries3)); /* ds_ctl3 */ printf(" rate0=0x%02x, rate1=0x%02x, rate2=0x%02x, rate3=0x%02x\n", MS(txc.ds_ctl3, AR_XmitRate0), MS(txc.ds_ctl3, AR_XmitRate1), MS(txc.ds_ctl3, AR_XmitRate2), MS(txc.ds_ctl3, AR_XmitRate3)); printf(" RtsCtsRate=0x%02x\n", MS(txc.ds_ctl3, AR_RTSCTSRate)); printf("\n ------ \n"); }
static bool read_hdr_ext(struct stream_data *stream, unsigned int version, size_t len) { union { struct stream_header_v1 v1; struct stream_header_v2 v2; } hdr; switch (version) { case 0: /* version 0 streams do not have this field */ len = 0; break; default: /* read extra header as far as possible; we will catch errors * later */ if (!stream_data_read(stream, &hdr, MIN(len, sizeof hdr), false)) return false; break; } /* consume the extra header information of future versions; it is * assumed that they do not contain important information and are * e.g. for statistic purposes only. There must be set senseful * default values */ if (len > sizeof hdr) { size_t sz = len - sizeof hdr; while (sz > 0) { char buf[64]; if (!stream_data_read(stream, buf, MIN(sizeof buf, sz), false)) return false; sz -= sizeof buf; } } switch (version) { case 0: stream->total_len = SIZE_UNSET; stream->extra_salt = NULL; stream->extra_salt_len = 0; stream->revision = 0; break; default: case 1: if (len < sizeof hdr.v1) return false; stream->total_len = be64toh(hdr.v1.total_len); stream->extra_salt = NULL; stream->extra_salt_len = 0; stream->revision = 0; break; case 2: if (len < sizeof hdr.v2) return false; stream->total_len = be64toh(hdr.v2.total_len); /* keep it big-endian; it is used as a salt later */ stream->revision = hdr.v2.revision; stream->extra_salt = &stream->revision; stream->extra_salt_len = sizeof stream->revision; break; } return true; }
void process_fastq_to_sff(char *sff_file) { FILE *sff_fp; if ( (sff_fp = fopen(sff_file, "w")) == NULL ) { fprintf(stderr, "[err] Could not open file '%s' for writing.\n", sff_file); exit(1); } sff_common_header ch; /* sff files are in big endian notation so adjust appropriately */ /* Linux version, not in use any more ch.magic = be32toh(h.magic); ch.index_len = be32toh(h.index_len); ch.header_len = be16toh(h.header_len); ch.key_len = be16toh(h.key_len); ch.flow = h.flow;//ff; ch.flow_len = be16toh(h.flow_len); ch.flowgram_format = h.flowgram_format;//0x01; ch.key = h.key;//"GACT"; char v[4] = {0x00,0x00,0x00,0x01}; //ch.version = ; memcpy(ch.version,v,4); */ ch.magic = ntohl(h.magic); ch.index_len = ntohl(h.index_len); ch.header_len = ntohs(h.header_len); ch.key_len = ntohs(h.key_len); ch.flow = h.flow;//ff; ch.flow_len = ntohs(h.flow_len); ch.flowgram_format = h.flowgram_format;//0x01; ch.key = h.key;//"GACT"; char v[4] = {0x00,0x00,0x00,0x01}; //ch.version = ; memcpy(ch.version,v,4); int header_size = sizeof(ch.magic) + sizeof(*(ch.version))*4 + sizeof(ch.index_offset) + sizeof(ch.index_len) + sizeof(ch.nreads) + sizeof(ch.header_len) + sizeof(ch.key_len) + sizeof(ch.flow_len) + sizeof(ch.flowgram_format) //+ (sizeof(char) * htobe16(ch.flow_len) ) //+ (sizeof(char) * htobe16(ch.key_len) ) ; + (sizeof(char) * htons(ch.flow_len) ) + (sizeof(char) * htons(ch.key_len) ) ; if ( !(header_size % PADDING_SIZE == 0) ) { header_size += PADDING_SIZE - (header_size % PADDING_SIZE); } fseek(sff_fp,header_size,SEEK_SET); ch.nreads = 0; unsigned int numreads = reads.size(); for (unsigned int i = 0; i < numreads; i++) { if(reads[i]->discarded) continue; sff_read_header readHeader; readHeader.nbases = reads[i]->read.length(); readHeader.name = (char*)malloc(sizeof(char)*strlen(reads[i]->readID)); memcpy( readHeader.name, reads[i]->readID, (size_t) strlen(reads[i]->readID) );//This line causes a problem on slarti with sff_extract readHeader.name_len = strlen(reads[i]->readID); /*Working with clip points*/ readHeader.clip_qual_left = reads[i]->lclip; readHeader.clip_qual_right = reads[i]->rclip; readHeader.clip_adapter_left = 0;//reads[i]->lclip; readHeader.clip_adapter_right = 0;//reads[i]->rclip; readHeader.header_len = sizeof(readHeader.header_len) + sizeof(readHeader.name_len) + sizeof(readHeader.nbases) + sizeof(readHeader.clip_qual_left) + sizeof(readHeader.clip_qual_right) + sizeof(readHeader.clip_adapter_left) + sizeof(readHeader.clip_adapter_right) + (sizeof(char) * readHeader.name_len); if ( !( readHeader.header_len % 8 == 0) ) { readHeader.header_len += 8 - (readHeader.header_len % 8); } sff_read_data readData; readData.bases = (char*)reads[i]->read.c_str(); readData.flow_index = reads[i]->flow_index; readData.flowgram = reads[i]->flowgram; readData.quality = (uint8_t*)malloc(sizeof(uint8_t)*(readHeader.nbases)); int j=0; for(j=0; j<readHeader.nbases; ++j) { readData.quality[j] = reads[i]->quality[j] - 33; } //readData.quality[j] = '\0'; write_sff_read_header(sff_fp, &(readHeader)); //write_sff_read_data(sff_fp, &(readData), htobe16(ch.flow_len), htobe32(readHeader.nbases)); write_sff_read_data(sff_fp, &(readData), htons(ch.flow_len), htonl(readHeader.nbases)); //free(rd.bases); free(readData.flow_index); free(readData.flowgram); free(readData.quality); ch.nreads += 1; } /* Linux edition, not in use any more ch.nreads = be32toh(ch.nreads);//be32toh(reads.size()); ch.index_offset = be64toh( ftell(sff_fp) ); */ ch.nreads = ntohl(ch.nreads); ch.index_offset = be64toh( ftell(sff_fp) ); write_manifest(sff_fp); fseek(sff_fp, 0, SEEK_SET); // seek back to beginning of file write_sff_common_header(sff_fp, &ch); fclose(sff_fp); }
int do_test (void) { int result = 0; for (uint64_t i = 0; i < (~UINT64_C (0)) >> 2; i = (i << 1) + 3) { if (i < UINT64_C (65536)) { DIAG_PUSH_NEEDS_COMMENT; DIAG_IGNORE_NEEDS_COMMENT_TAUTOLOGICAL_COMPARE (); if (htobe16 (be16toh (i)) != i) { printf ("htobe16 (be16toh (%" PRIx64 ")) == %" PRIx16 "\n", i, (uint16_t) htobe16 (be16toh (i))); result = 1; } if (htole16 (le16toh (i)) != i) { printf ("htole16 (le16toh (%" PRIx64 ")) == %" PRIx16 "\n", i, (uint16_t) htole16 (le16toh (i))); result = 1; } DIAG_POP_NEEDS_COMMENT; uint16_t n[2]; n[__BYTE_ORDER == __LITTLE_ENDIAN] = bswap_16 (i); n[__BYTE_ORDER == __BIG_ENDIAN] = i; if (htole16 (i) != n[0]) { printf ("htole16 (%" PRIx64 ") == %" PRIx16 " != %" PRIx16 "\n", i, (uint16_t) htole16 (i), n[0]); result = 1; } if (htobe16 (i) != n[1]) { printf ("htobe16 (%" PRIx64 ") == %" PRIx16 " != %" PRIx16 "\n", i, (uint16_t) htobe16 (i), n[1]); result = 1; } } if (i < UINT64_C (4294967296)) { DIAG_PUSH_NEEDS_COMMENT; DIAG_IGNORE_NEEDS_COMMENT_TAUTOLOGICAL_COMPARE (); if (htobe32 (be32toh (i)) != i) { printf ("htobe32 (be32toh (%" PRIx64 ")) == %" PRIx32 "\n", i, (uint32_t) htobe32 (be32toh (i))); result = 1; } if (htole32 (le32toh (i)) != i) { printf ("htole32 (le32toh (%" PRIx64 ")) == %" PRIx32 "\n", i, (uint32_t) htole32 (le32toh (i))); result = 1; } DIAG_POP_NEEDS_COMMENT; uint32_t n[2]; n[__BYTE_ORDER == __LITTLE_ENDIAN] = bswap_32 (i); n[__BYTE_ORDER == __BIG_ENDIAN] = i; if (htole32 (i) != n[0]) { printf ("htole32 (%" PRIx64 ") == %" PRIx32 " != %" PRIx32 "\n", i, (uint32_t) htole32 (i), n[0]); result = 1; } if (htobe32 (i) != n[1]) { printf ("htobe32 (%" PRIx64 ") == %" PRIx32 " != %" PRIx32 "\n", i, (uint32_t) htobe32 (i), n[1]); result = 1; } } DIAG_PUSH_NEEDS_COMMENT; DIAG_IGNORE_NEEDS_COMMENT_TAUTOLOGICAL_COMPARE (); if (htobe64 (be64toh (i)) != i) { printf ("htobe64 (be64toh (%" PRIx64 ")) == %" PRIx64 "\n", i, htobe64 (be64toh (i))); result = 1; } if (htole64 (le64toh (i)) != i) { printf ("htole64 (le64toh (%" PRIx64 ")) == %" PRIx64 "\n", i, htole64 (le64toh (i))); result = 1; } DIAG_POP_NEEDS_COMMENT; uint64_t n[2]; n[__BYTE_ORDER == __LITTLE_ENDIAN] = bswap_64 (i); n[__BYTE_ORDER == __BIG_ENDIAN] = i; if (htole64 (i) != n[0]) { printf ("htole64 (%" PRIx64 ") == %" PRIx64 " != %" PRIx64 "\n", i, htole64 (i), n[0]); result = 1; } if (htobe64 (i) != n[1]) { printf ("htobe64 (%" PRIx64 ") == %" PRIx64 " != %" PRIx64 "\n", i, htobe64 (i), n[1]); result = 1; } } return result; }
int main(int argc, const char *argv[]) { const char *file = argv[1]; int fd; struct if_ath_alq_payload *a; int r; char buf[READBUF_SIZE]; int buflen = 0; if (argc < 2) { printf("usage: %s <ahq log>\n", argv[0]); exit(127); } fd = open(file, O_RDONLY); if (fd < 0) { perror("open"); exit(127); } /* * The payload structure is now no longer a fixed * size. So, hoops are jumped through. Really * terrible, infficient hoops. */ while (1) { if (buflen < 512) { /* XXX Eww */ r = read(fd, buf + buflen, READBUF_SIZE - buflen); if (r <= 0) break; buflen += r; //printf("read %d bytes, buflen now %d\n", r, buflen); } a = (struct if_ath_alq_payload *) &buf[0]; /* * XXX sanity check that len is within the left over * size of buf. */ if (be16toh(a->hdr.len) > buflen) { fprintf(stderr, "%s: len=%d, buf=%d, tsk!\n", argv[0], be16toh(a->hdr.len), buflen); break; } switch (be16toh(a->hdr.op)) { case ATH_ALQ_INIT_STATE: /* XXX should double check length! */ memcpy(&hdr, a->payload, sizeof(hdr)); ath_alq_print_hdr(&hdr); break; case ATH_ALQ_TDMA_BEACON_STATE: ath_tdma_beacon_state(a); break; case ATH_ALQ_TDMA_TIMER_CONFIG: ath_tdma_timer_config(a); break; case ATH_ALQ_TDMA_SLOT_CALC: ath_tdma_slot_calc(a); break; case ATH_ALQ_TDMA_TSF_ADJUST: ath_tdma_tsf_adjust(a); break; case ATH_ALQ_TDMA_TIMER_SET: ath_tdma_timer_set(a); break; case ATH_ALQ_INTR_STATUS: ath_alq_print_intr_status(a); break; default: if (be32toh(hdr.sc_hal_magic) == AR5210_MAGIC) ar5210_alq_payload(a); else if (be32toh(hdr.sc_hal_magic) == AR5211_MAGIC) ar5211_alq_payload(a); else if (be32toh(hdr.sc_hal_magic) == AR5212_MAGIC) ar5212_alq_payload(a); else if (be32toh(hdr.sc_hal_magic) == AR5416_MAGIC) ar5416_alq_payload(a); #if 0 else if (be32toh(hdr.sc_hal_magic) == AR9300_MAGIC) ar9300_alq_payload(a); #endif else printf("[%d.%06d] [%lld] op: %d; len %d\n", be32toh(a->hdr.tstamp_sec), be32toh(a->hdr.tstamp_usec), be64toh(a->hdr.threadid), be16toh(a->hdr.op), be16toh(a->hdr.len)); } /* * a.len is minus the header size, so.. */ buflen -= (be16toh(a->hdr.len) + sizeof(struct if_ath_alq_hdr)); memmove(&buf[0], &buf[be16toh(a->hdr.len) + sizeof(struct if_ath_alq_hdr)], READBUF_SIZE - (be16toh(a->hdr.len) + sizeof(struct if_ath_alq_hdr))); //printf(" buflen is now %d\n", buflen); } close(fd); }
/* * Add stream on the relayd and assign stream handle to the stream_id argument. * * On success return 0 else return ret_code negative value. */ int relayd_add_stream(struct lttcomm_relayd_sock *rsock, const char *channel_name, const char *pathname, uint64_t *stream_id, uint64_t tracefile_size, uint64_t tracefile_count) { int ret; struct lttcomm_relayd_add_stream msg; struct lttcomm_relayd_add_stream_2_2 msg_2_2; struct lttcomm_relayd_status_stream reply; /* Code flow error. Safety net. */ assert(rsock); assert(channel_name); assert(pathname); DBG("Relayd adding stream for channel name %s", channel_name); /* Compat with relayd 2.1 */ if (rsock->minor == 1) { memset(&msg, 0, sizeof(msg)); strncpy(msg.channel_name, channel_name, sizeof(msg.channel_name)); strncpy(msg.pathname, pathname, sizeof(msg.pathname)); /* Send command */ ret = send_command(rsock, RELAYD_ADD_STREAM, (void *) &msg, sizeof(msg), 0); if (ret < 0) { goto error; } } else { memset(&msg_2_2, 0, sizeof(msg_2_2)); /* Compat with relayd 2.2+ */ strncpy(msg_2_2.channel_name, channel_name, sizeof(msg_2_2.channel_name)); strncpy(msg_2_2.pathname, pathname, sizeof(msg_2_2.pathname)); msg_2_2.tracefile_size = htobe64(tracefile_size); msg_2_2.tracefile_count = htobe64(tracefile_count); /* Send command */ ret = send_command(rsock, RELAYD_ADD_STREAM, (void *) &msg_2_2, sizeof(msg_2_2), 0); if (ret < 0) { goto error; } } /* Waiting for reply */ ret = recv_reply(rsock, (void *) &reply, sizeof(reply)); if (ret < 0) { goto error; } /* Back to host bytes order. */ reply.handle = be64toh(reply.handle); reply.ret_code = be32toh(reply.ret_code); /* Return session id or negative ret code. */ if (reply.ret_code != LTTNG_OK) { ret = -1; ERR("Relayd add stream replied error %d", reply.ret_code); } else { /* Success */ ret = 0; *stream_id = reply.handle; } DBG("Relayd stream added successfully with handle %" PRIu64, reply.handle); error: return ret; }
static inline int64_t decode64(const void *ptr) { return be64toh(*(int64_t *)ptr); }
int main() { int sd; struct sockaddr_in laddr,raddr; socklen_t raddr_len; struct msg_st rmsg, smsg; char ipstr[IPSTRSIZE]; printf("NTP server start ...\n"); sd = socket(AF_INET,SOCK_DGRAM,0/*IPPROTO_UDP*/); if(sd < 0) { perror("socket()"); exit(1); } laddr.sin_family = AF_INET; laddr.sin_port = htons(atoi("123")); inet_pton(AF_INET,"0.0.0.0",&laddr.sin_addr); if(bind(sd,(void *)&laddr,sizeof(laddr)) < 0) { perror("bind()"); exit(1); } raddr_len = sizeof(raddr); /*!!*/ memset(&rmsg, 0, sizeof(rmsg)); while(1) { if(recvfrom(sd,(char *)&rmsg,sizeof(rmsg),0,(void *)&raddr,&raddr_len) < 0) { perror("recvfrom()"); exit(1); } /*********************** 接收部分 ************************/ inet_ntop(AF_INET,&raddr.sin_addr,ipstr,IPSTRSIZE); printf("----MESSAGE FROM : %s:%d-----\n",ipstr,ntohs(raddr.sin_port)); rmsg.LI_VN_Mode = ntohl(rmsg.LI_VN_Mode); rmsg.stratum = ntohl(rmsg.stratum); rmsg.poll = ntohl(rmsg.poll); rmsg.precision= ntohl(rmsg.precision); rmsg.rootdelay= ntohl(rmsg.rootdelay); rmsg.rootdisp = ntohl(rmsg.rootdisp); rmsg.refid = ntohl(rmsg.refid); rmsg.reftime = be64toh(rmsg.reftime); rmsg.origtime = be64toh(rmsg.origtime); rmsg.recetime = be64toh(rmsg.recetime); //rmsg.transtime = be64toh(rmsg.transtime); time_t timest = ntohl(rmsg.transtime) - FROM1900TO1970; printf("reftime : %s", ctime((time_t*)(&rmsg.reftime))); printf("origtime : %s", ctime((time_t*)(&rmsg.origtime))); printf("recetime : %s", ctime((time_t*)(&rmsg.recetime))); printf("transtime : %s", ctime(×t)); /*********************** 发送部分 ************************/ smsg.LI_VN_Mode = htonl((LI_00<<30) | (VN<<27) | (MODE4<<24)); smsg.stratum = 4; /* 对本地时钟级别的整体识别 */ smsg.poll = 5; /* 测试间隔 */ smsg.precision = 0; /* 本地时钟精度 */ smsg.reftime = htonl(time(NULL) + FROM1900TO1970); smsg.origtime = rmsg.transtime; smsg.recetime = htonl(time(NULL) + FROM1900TO1970); smsg.transtime = htonl(time(NULL) + FROM1900TO1970); if(sendto(sd,&smsg,sizeof(smsg),0,(void *)&raddr,sizeof(raddr)) < 0) { perror("sendto()"); exit(1); } printf("\n"); memset(&rmsg, 0, sizeof(rmsg)); memset(&smsg, 0, sizeof(smsg)); } close(sd); exit(0); }
template <> inline uint64_t host_from<uint64_t, big_endian>(uint64_t value) { return be64toh(value); }
UInt64 ByteOrder::ntoh64(UInt64 data) { return be64toh(data); }
template <> inline int64_t host_from<int64_t, big_endian>(int64_t value) { return (int64_t)be64toh((uint64_t)value); }
static int reserv_mem_limits_test(fwts_framework *fw) { bool ok = true; char *region_names; const uint64_t *ranges; reserve_region_t *regions; int offset, len, nr_regions, rc, j; plat_config_t configstruct = {0, 0, 0}; get_config(fw, CONFIG_FILENAME, &configstruct); offset = fdt_path_offset(fw->fdt, root_node); if (offset < 0) { fwts_failed(fw, LOG_LEVEL_MEDIUM, "DTNodeMissing", "DT root node %s is missing", root_node); return FWTS_ERROR; } /* Get the number of memory reserved regions */ nr_regions = fwts_dt_stringlist_count(fw, fw->fdt, offset, "reserved-names"); /* Check for the reservd-names property */ region_names = (char *)fdt_getprop(fw->fdt, offset, "reserved-names", &len); if (!region_names) { fwts_failed(fw, LOG_LEVEL_MEDIUM, "DTPropertyMissing", "DT Property reserved-names is missing %s", fdt_strerror(len)); return FWTS_ERROR; } regions = malloc(nr_regions*sizeof(reserve_region_t)); if (!regions) { fwts_skipped(fw, "Unable to allocate memory " "for reserv_region_t structure"); return FWTS_SKIP; } for (j = 0; j < nr_regions; j++) { regions[j].name = strdup(region_names); region_names += strlen(regions[j].name) + 1; } /* Check for the reserved-ranges property */ ranges = fdt_getprop(fw->fdt, offset, "reserved-ranges", &len); if (!ranges) { fwts_failed(fw, LOG_LEVEL_MEDIUM, "DTPropertyMissing", "DT Property reserved-ranges is missing %s", fdt_strerror(len)); rc = FWTS_ERROR; goto out_free_regions; } for (j = 0; j < nr_regions; j++) { regions[j].start = (uint64_t)be64toh(ranges[2 * j]); regions[j].len = (uint64_t)be64toh(ranges[2 * j + 1]); fwts_log_info(fw, "Region name %80s" " start: 0x%08" PRIx64 ", len: 0x%08" PRIx64 "\n", regions[j].name, regions[j].start, regions[j].len); } offset = fdt_path_offset(fw->fdt, reserv_mem_node); if (offset < 0) { fwts_failed(fw, LOG_LEVEL_MEDIUM, "DTNodeMissing", "reserve memory node %s is missing", reserv_mem_node); rc = FWTS_ERROR; goto out_free_regions; } /* Validate different cases */ for (j = 0; j < nr_regions; j++) { char *buf = NULL; /* Check for zero offset's */ if (regions[j].start == 0) { fwts_failed(fw, LOG_LEVEL_MEDIUM, "ZeroStartAddress", "memory region got zero start address"); ok = false; } /* Check for zero region sizes */ if (regions[j].len == 0) { fwts_failed(fw, LOG_LEVEL_MEDIUM, "ZeroRegionSize", "memory region got zero size"); ok = false; } /* Form the reserved-memory sub nodes for all the regions*/ if (!strstr(regions[j].name, "@")) buf = make_message("%s%s@%lx", reserv_mem_node, regions[j].name, regions[j].start); else buf = make_message("/%s/%s", reserv_mem_node, regions[j].name); if (!buf) { fwts_skipped(fw, "Unable to allocate memory for buffer"); rc = FWTS_SKIP; goto out_free_regions; } /* Check all nodes got created for all the sub regions */ offset = fdt_path_offset(fw->fdt, buf); if (offset < 0) { fwts_failed(fw, LOG_LEVEL_MEDIUM, "DTNodeMissing", "reserve memory region node %s is missing", buf); ok = false; } if (skip) continue; /* Validate different Known image fixed sizes here */ if (strstr(regions[j].name, "homer-image")) { if (regions[j].len != configstruct.homer) { fwts_failed(fw, LOG_LEVEL_MEDIUM, "ImageSizeMismatch", "Mismatch in homer-image size, " "expected: 0x%" PRIx64 ", actual: 0x%" PRIx64, configstruct.homer, regions[j].len); ok = false; } else fwts_log_info(fw, "homer-image size is validated"); } if (strstr(regions[j].name, "slw-image")) { if (regions[j].len != configstruct.slw) { fwts_failed(fw, LOG_LEVEL_MEDIUM, "ImageSizeMismatch", "Mismatch in slw-image size, " "expected: 0x%" PRIx64 ", actual: 0x%" PRIx64, configstruct.slw, regions[j].len); ok = false; } else fwts_log_info(fw, "slw-image size is validated"); } if (strstr(regions[j].name, "occ-common-area")) { if (regions[j].len != configstruct.occ_common) { fwts_failed(fw, LOG_LEVEL_MEDIUM, "ImageSizeMismatch", "Mismatch in occ-common-area size, " "expected: 0x%" PRIx64 ", actual: 0x%" PRIx64, configstruct.occ_common, regions[j].len); ok = false; } else fwts_log_info(fw, "occ-common-area size is validated"); } } if (ok) { rc = FWTS_OK; fwts_passed(fw, "Reserved memory validation tests passed"); } else { rc = FWTS_ERROR; fwts_failed(fw, LOG_LEVEL_HIGH, "ReservMemTestFail", "One or few Reserved Memory DT" " validation tests failed"); } out_free_regions: free(regions); return rc; }
std::uint64_t getQuality (uint256 const& uBase) { // VFALCO [base_uint] This assumes a certain storage format return be64toh (((std::uint64_t*) uBase.end ())[-1]); }
int eMPEGStreamInformation::getStructureEntryFirst(off_t &offset, unsigned long long &data) { //eDebug("[eMPEGStreamInformation] {%d} getStructureEntryFirst(offset=%lld)", gettid(), offset); if (m_structure_read_fd < 0) { eDebug("[eMPEGStreamInformation] getStructureEntryFirst failed because of no m_structure_read_fd"); return -1; } if ((m_structure_cache_entries == 0) || (structureCacheOffset(0) > offset) || (structureCacheOffset(m_structure_cache_entries - 1) <= offset)) { int l = ::lseek(m_structure_read_fd, 0, SEEK_END) / entry_size; if (l == 0) { eDebug("[eMPEGStreamInformation] getStructureEntryFirst failed because file size is zero"); return -1; } m_structure_file_entries = l; /* do a binary search */ int count = l; int i = 0; const int structure_cache_size = MAPSIZE / entry_size; while (count > (structure_cache_size/4)) { int step = count >> 1; // Read entry at top end of current range (== i+step-1) ::lseek(m_structure_read_fd, (i + step - 1) * entry_size, SEEK_SET); unsigned long long d; if (::read(m_structure_read_fd, &d, sizeof(d)) < (ssize_t)sizeof(d)) { eDebug("[eMPEGStreamInformation] getStructureEntryFirst read error at entry %d", i+step); return -1; } d = be64toh(d); if (d < (unsigned long long)offset) { // Move start of range to *be* the last test (+1 more may be too high!!) // and remove tested count i += step; count -= step; } else // Keep start of range but change range to that below test count = step; } //eDebug("[eMPEGStreamInformation] getStructureEntryFirst i=%d size=%d count=%d", i, l, count); if (i + structure_cache_size > l) { i = l - structure_cache_size; // Near end of file, just fetch the last } if (i < 0) i = 0; int num = moveCache(i); if ((num < structure_cache_size) && (structureCacheOffset(num - 1) <= offset)) { eDebug("[eMPEGStreamInformation] offset %lld is past EOF of structure file", offset); data = 0; return 1; } }
uint64_t pbe64_to_h(void *v) { uint64_t u; memcpy(&u, v, sizeof(uint64_t)); return be64toh(u); }