static int cmp_exact(char *source, int index) { SHA512_CTX ctx; uint64_t *b,*c,crypt_out[8]; int i; SHA512_Init(&ctx); SHA512_Update(&ctx, gkey[index].v, gkey[index].length); SHA512_Final((unsigned char *)(crypt_out), &ctx); b = (uint64_t *)get_binary(source); c = (uint64_t *)crypt_out; for (i = 0; i < 8; i++) { uint64_t t = SWAP64(c[i])-H[i]; c[i] = SWAP64(t); } for (i = 0; i < FULL_BINARY_SIZE / 8; i++) { //examin 512bits if (b[i] != c[i]) return 0; } return 1; }
void GTID::serializeBinaryData(char* binData) const { char* pos = binData; uint64_t prim = SWAP64(_primarySeqNo); memcpy(pos, &prim, sizeof(uint64_t)); pos += sizeof(uint64_t); uint64_t sec = SWAP64(_GTSeqNo); memcpy(pos, &sec, sizeof(uint64_t)); }
GTID::GTID(const char* binData) { const char* pos = binData; uint64_t swappedPrim = *(uint64_t *)pos; pos += sizeof(uint64_t); uint64_t swappedSec = *(uint64_t *)pos; _primarySeqNo = SWAP64(swappedPrim); _GTSeqNo = SWAP64(swappedSec); }
int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id, struct usb_device *udev, gfp_t flags) { struct xhci_virt_device *dev; int i; /* Slot ID 0 is reserved */ if (slot_id == 0 || xhci->devs[slot_id]) { xhci_warn(xhci, "Bad Slot ID %d\n", slot_id); return 0; } xhci->devs[slot_id] = kzalloc(sizeof(*xhci->devs[slot_id]), flags); if (!xhci->devs[slot_id]) return 0; dev = xhci->devs[slot_id]; /* Allocate the (output) device context that will be used in the HC. */ dev->out_ctx = xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_DEVICE, flags); if (!dev->out_ctx) goto fail; xhci_dbg(xhci, "Slot %d output ctx = 0x%llx (dma)\n", slot_id, (unsigned long long)dev->out_ctx->dma); /* Allocate the (input) device context for address device command */ dev->in_ctx = xhci_alloc_container_ctx(xhci, (XHCI_CTX_TYPE_INPUT), flags); if (!dev->in_ctx) goto fail; xhci_dbg(xhci, "Slot %d input ctx = 0x%llx (dma)\n", slot_id, (unsigned long long)dev->in_ctx->dma); /* Initialize the cancellation list for each endpoint */ for (i = 0; i < 31; i++) INIT_LIST_HEAD(&dev->eps[i].cancelled_td_list); /* Allocate endpoint 0 ring */ dev->eps[0].ring = xhci_ring_alloc(xhci, 1, true, flags); if (!dev->eps[0].ring) goto fail; init_completion(&dev->cmd_completion); INIT_LIST_HEAD(&dev->cmd_list); /* Point to output device context in dcbaa. */ xhci->dcbaa->dev_context_ptrs[slot_id] = SWAP64(dev->out_ctx->dma); xhci_dbg(xhci, "Set slot id %d dcbaa entry %p to 0x%llx\n", slot_id, &xhci->dcbaa->dev_context_ptrs[slot_id], SWAP64((unsigned long long) xhci->dcbaa->dev_context_ptrs[slot_id])); return 1; fail: xhci_free_virt_device(xhci, slot_id); return 0; }
double SWAPDOUBLE( double d ) { CR64BitType *ptr = (CR64BitType *) (&d); #ifdef __STDC__ CR64BitType swapped; SWAP64( *ptr ); swapped = *ptr; #else CR64BitType swapped = SWAP64( *ptr ); #endif return *((double *) (&swapped)); }
void __swap_section_64(struct section_64* section_ptr) { SWAP64(section_ptr->addr); SWAP64(section_ptr->size); SWAP32(section_ptr->offset); SWAP32(section_ptr->align); SWAP32(section_ptr->reloff); SWAP32(section_ptr->nreloc); SWAP32(section_ptr->flags); SWAP32(section_ptr->reserved1); SWAP32(section_ptr->reserved2); }
bool HostAddress::match(const HostAddress &netmask, int bits) const { quint64 mask[2]; if (bits == 128) { mask[0] = mask[1] = 0xffffffffffffffffULL; } else if (bits > 64) { mask[0] = 0xffffffffffffffffULL; mask[1] = SWAP64(~((1ULL << (128-bits)) - 1)); } else { mask[0] = SWAP64(~((1ULL << (64-bits)) - 1)); mask[1] = 0ULL; } return ((addr[0] & mask[0]) == (netmask.addr[0] & mask[0])) && ((addr[1] & mask[1]) == (netmask.addr[1] & mask[1])); }
void __swap_segment_command_64(struct segment_command_64* segment) { SWAP32(segment->cmd); SWAP32(segment->cmdsize); SWAP64(segment->vmaddr); SWAP64(segment->vmsize); SWAP64(segment->fileoff); SWAP64(segment->filesize); SWAP32(segment->maxprot); SWAP32(segment->initprot); SWAP32(segment->nsects); SWAP32(segment->flags); }
inline OutputSerializer& OutputSerializer::operator <<(uint64 object) { if ((LOCAL_BUFFER_SIZE - full) < 8) Flush(); *reinterpret_cast<uint64*>(localBuffer + full) = SWAP64(object); full += 8; return *this; }
void uint_64_to_8be(uint64_t num, size_t size, uint8_t* data) { assert(1 <= size && size <= sizeof(uint64_t)); uint64_t num_be = SWAP64(num); memcpy(data, (uint8_t*)(&num_be) + sizeof(uint64_t) - size, size); }
/* ========================================================================== Description: Measurement request action frame sanity check. Parametrs: 1. MLME message containing the received frame 2. message length. 3. Measurement request infomation buffer. Return : None. ========================================================================== */ static BOOLEAN PeerMeasureReqSanity( IN PRTMP_ADAPTER pAd, IN VOID *pMsg, IN ULONG MsgLen, OUT PUINT8 pDialogToken, OUT PMEASURE_REQ_INFO pMeasureReqInfo) { PFRAME_802_11 Fr = (PFRAME_802_11)pMsg; PUCHAR pFramePtr = Fr->Octet; BOOLEAN result = FALSE; PEID_STRUCT eid_ptr; PUCHAR ptr; UINT64 MeasureStartTime; UINT16 MeasureDuration; // skip 802.11 header. MsgLen -= sizeof(HEADER_802_11); // skip category and action code. pFramePtr += 2; MsgLen -= 2; if (pMeasureReqInfo == NULL) return result; NdisMoveMemory(pDialogToken, pFramePtr, 1); pFramePtr += 1; MsgLen -= 1; eid_ptr = (PEID_STRUCT)pFramePtr; while (((UCHAR*)eid_ptr + eid_ptr->Len + 1) < ((PUCHAR)pFramePtr + MsgLen)) { switch(eid_ptr->Eid) { case IE_MEASUREMENT_REQUEST: NdisMoveMemory(&pMeasureReqInfo->Token, eid_ptr->Octet, 1); NdisMoveMemory(&pMeasureReqInfo->ReqMode.word, eid_ptr->Octet + 1, 1); NdisMoveMemory(&pMeasureReqInfo->ReqType, eid_ptr->Octet + 2, 1); ptr = eid_ptr->Octet + 3; NdisMoveMemory(&pMeasureReqInfo->MeasureReq.ChNum, ptr, 1); NdisMoveMemory(&MeasureStartTime, ptr + 1, 8); pMeasureReqInfo->MeasureReq.MeasureStartTime = SWAP64(MeasureStartTime); NdisMoveMemory(&MeasureDuration, ptr + 9, 2); pMeasureReqInfo->MeasureReq.MeasureDuration = SWAP16(MeasureDuration); result = TRUE; break; default: break; } eid_ptr = (PEID_STRUCT)((UCHAR*)eid_ptr + 2 + eid_ptr->Len); } return result; }
void Samurai::IO::Buffer::appendBinary(uint64_t number_, BinaryMode endiannes) { uint64_t number = number_; switch (endiannes) { case LittleEndian: #ifdef SAMURAI_BIGENDIAN number = SWAP64(number); #endif break; case BigEndian: #ifndef SAMURAI_BIGENDIAN number = SWAP64(number); #endif break; case NativeEndian: break; } append((char*) &number, sizeof(number)); }
static void *get_binary(char *ciphertext) { static unsigned char out[FULL_BINARY_SIZE]; char *p = ciphertext; int i; uint64_t *b; for (i = 0; i < sizeof(out); i++) { out[i] = (atoi16[ARCH_INDEX(*p)] << 4) | atoi16[ARCH_INDEX(p[1])]; p += 2; } b = (uint64_t*)out; for (i = 0; i < 8; i++) { uint64_t t = SWAP64(b[i])-H[i]; b[i] = SWAP64(t); } return out; }
bool Samurai::IO::Buffer::popBinary(size_t offset, uint64_t& number, BinaryMode endianness) { number = reinterpret_cast<uint64_t>(&buf[offset]); switch (endianness) { case LittleEndian: #ifdef SAMURAI_BIGENDIAN number = SWAP64(number); #endif break; case BigEndian: #ifndef SAMURAI_BIGENDIAN number = SWAP64(number); #endif break; case NativeEndian: break; } return true; }
void OpenCLMomentumV9::find_collisions(uint8_t* message, collision_struct* collisions, size_t* collision_count) { // temp storage *collision_count = 0; uint32_t ht_size = 1<<HASH_BITS; SHA512_Context c512_avxsse; SHA512_Init(&c512_avxsse); uint8_t midhash[32+4]; memcpy(midhash+4, message, 32); *((uint32_t*)midhash) = 0; SHA512_Update_Simple(&c512_avxsse, midhash, 32+4); SHA512_PreFinal(&c512_avxsse); *(uint32_t *)(&c512_avxsse.buffer.bytes[0]) = 0; uint64_t * swap_helper = (uint64_t*)(&c512_avxsse.buffer.bytes[0]); for (int i = 1; i < 5; i++) { swap_helper[i] = SWAP64(swap_helper[i]); } OpenCLContext *context = OpenCLMain::getInstance().getDevice(device_num)->getContext(); OpenCLProgram *program = context->getProgram(0); OpenCLKernel *kernel = program->getKernel("kernel_sha512"); OpenCLKernel *kernel_cleanup = program->getKernel("kernel_clean_hash_table"); assert(kernel != NULL); //size_t BLOCKSIZE = main.getPlatform(0)->getDevice(0)->getMaxWorkGroupSize(); size_t BLOCKSIZE = kernel->getWorkGroupSize(OpenCLMain::getInstance().getDevice(device_num)); //has to be a power of 2 BLOCKSIZE = 1<<log2(BLOCKSIZE); size_t BLOCKSIZE_CLEAN = kernel_cleanup->getWorkGroupSize(OpenCLMain::getInstance().getDevice(device_num)); BLOCKSIZE_CLEAN = 1<<log2(BLOCKSIZE_CLEAN); // printf("BLOCKSIZE = %ld\n", BLOCKSIZE); // printf("BLOCKSIZE_CLEAN = %ld\n", BLOCKSIZE_CLEAN); // cleans up the hash table queue->enqueueKernel1D(kernel_cleanup, 1<<HASH_BITS, BLOCKSIZE_CLEAN); queue->enqueueWriteBuffer(cl_message, c512_avxsse.buffer.bytes, sizeof(uint8_t)*SHA512_BLOCK_SIZE); queue->enqueueWriteBuffer(temp_collisions_count, collision_count, sizeof(size_t)); queue->enqueueKernel1D(kernel, MAX_MOMENTUM_NONCE/8, BLOCKSIZE); queue->enqueueReadBuffer(temp_collisions_count, collision_count, sizeof(size_t)); queue->enqueueReadBuffer(temp_collisions, collisions, sizeof(collision_struct)*getCollisionCeiling()); queue->finish(); }
/* * Make the prev segment point to the next segment. * * Change the last TRB in the prev segment to be a Link TRB which points to the * DMA address of the next segment. The caller needs to set any Link TRB * related flags, such as End TRB, Toggle Cycle, and no snoop. */ static void xhci_link_segments(struct xhci_hcd *xhci, struct xhci_segment *prev, struct xhci_segment *next, bool link_trbs) { u32 val; if (!prev || !next) return; prev->next = next; if (link_trbs) { prev->trbs[TRBS_PER_SEGMENT-1].link.segment_ptr = SWAP64(next->dma); /* Set the last TRB in the segment to have a TRB type ID of Link TRB */ val = SWAP32(prev->trbs[TRBS_PER_SEGMENT-1].link.control); val &= ~TRB_TYPE_BITMASK; val |= TRB_TYPE(TRB_LINK); /* Always set the chain bit with 0.95 hardware */ if (xhci_link_trb_quirk(xhci)) val |= TRB_CHAIN; prev->trbs[TRBS_PER_SEGMENT-1].link.control = SWAP32(val); } xhci_dbg(xhci, "Linking segment 0x%llx to segment 0x%llx (DMA)\n", (unsigned long long)prev->dma, (unsigned long long)next->dma); }
int xhci_endpoint_init(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev, struct usb_device *udev, struct usb_host_endpoint *ep, gfp_t mem_flags) { unsigned int ep_index; struct xhci_ep_ctx *ep_ctx; struct xhci_ring *ep_ring; unsigned int max_packet; unsigned int max_burst; ep_index = xhci_get_endpoint_index(&ep->desc); ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); /* Set up the endpoint ring */ virt_dev->eps[ep_index].new_ring = xhci_ring_alloc(xhci, 1, true, mem_flags); if (!virt_dev->eps[ep_index].new_ring) return -ENOMEM; ep_ring = virt_dev->eps[ep_index].new_ring; ep_ctx->deq = SWAP64(ep_ring->first_seg->dma | ep_ring->cycle_state); ep_ctx->ep_info = SWAP32(xhci_get_endpoint_interval(udev, ep)); /* FIXME dig Mult and streams info out of ep companion desc */ /* Allow 3 retries for everything but isoc; * error count = 0 means infinite retries. */ if (!usb_endpoint_xfer_isoc(&ep->desc)) ep_ctx->ep_info2 = SWAP32(ERROR_COUNT(3)); else ep_ctx->ep_info2 = SWAP32(ERROR_COUNT(1)); ep_ctx->ep_info2 |= SWAP32(xhci_get_endpoint_type(udev, ep)); /* Set the max packet size and max burst */ switch (udev->speed) { case USB_SPEED_SUPER: max_packet = SWAP16(ep->desc.wMaxPacketSize); ep_ctx->ep_info2 |= SWAP32(MAX_PACKET(max_packet)); /* dig out max burst from ep companion desc */ if (!ep->ss_ep_comp) { xhci_warn(xhci, "WARN no SS endpoint companion descriptor.\n"); max_packet = 0; } else { max_packet = ep->ss_ep_comp->desc.bMaxBurst; } ep_ctx->ep_info2 |= SWAP32(MAX_BURST(max_packet)); break; case USB_SPEED_HIGH: /* bits 11:12 specify the number of additional transaction * opportunities per microframe (USB 2.0, section 9.6.6) */ if (usb_endpoint_xfer_isoc(&ep->desc) || usb_endpoint_xfer_int(&ep->desc)) { max_burst = (SWAP16(ep->desc.wMaxPacketSize) & 0x1800) >> 11; ep_ctx->ep_info2 |= SWAP32(MAX_BURST(max_burst)); } /* Fall through */ case USB_SPEED_FULL: case USB_SPEED_LOW: max_packet = SWAP16(ep->desc.wMaxPacketSize) & 0x3ff; ep_ctx->ep_info2 |= SWAP32(MAX_PACKET(max_packet)); break; default: BUG(); }
/* Setup an xHCI virtual device for a Set Address command */ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *udev) { struct xhci_virt_device *dev; struct xhci_ep_ctx *ep0_ctx; struct usb_device *top_dev; struct xhci_slot_ctx *slot_ctx; struct xhci_input_control_ctx *ctrl_ctx; dev = xhci->devs[udev->slot_id]; /* Slot ID 0 is reserved */ if (udev->slot_id == 0 || !dev) { xhci_warn(xhci, "Slot ID %d is not assigned to this device\n", udev->slot_id); return -EINVAL; } ep0_ctx = xhci_get_ep_ctx(xhci, dev->in_ctx, 0); ctrl_ctx = xhci_get_input_control_ctx(xhci, dev->in_ctx); slot_ctx = xhci_get_slot_ctx(xhci, dev->in_ctx); /* 2) New slot context and endpoint 0 context are valid*/ ctrl_ctx->add_flags = SWAP32(SLOT_FLAG | EP0_FLAG); /* 3) Only the control endpoint is valid - one endpoint context */ slot_ctx->dev_info |= SWAP32(LAST_CTX(1)); slot_ctx->dev_info |= SWAP32((u32) udev->route); switch (udev->speed) { case USB_SPEED_SUPER: slot_ctx->dev_info |= SWAP32((u32) SLOT_SPEED_SS); break; case USB_SPEED_HIGH: slot_ctx->dev_info |= SWAP32((u32) SLOT_SPEED_HS); break; case USB_SPEED_FULL: slot_ctx->dev_info |= SWAP32((u32) SLOT_SPEED_FS); break; case USB_SPEED_LOW: slot_ctx->dev_info |= SWAP32((u32) SLOT_SPEED_LS); break; case USB_SPEED_VARIABLE: xhci_dbg(xhci, "FIXME xHCI doesn't support wireless speeds\n"); return -EINVAL; break; default: /* Speed was set earlier, this shouldn't happen. */ BUG(); } /* Find the root hub port this device is under */ for (top_dev = udev; top_dev->parent && top_dev->parent->parent; top_dev = top_dev->parent) /* Found device below root hub */; slot_ctx->dev_info2 |= SWAP32((u32) ROOT_HUB_PORT(top_dev->portnum)); xhci_dbg(xhci, "Set root hub portnum to %d\n", top_dev->portnum); /* Is this a LS/FS device under a HS hub? */ if ((udev->speed == USB_SPEED_LOW || udev->speed == USB_SPEED_FULL) && udev->tt) { slot_ctx->tt_info = SWAP32(udev->tt->hub->slot_id); slot_ctx->tt_info |= SWAP32(udev->ttport << 8); if (udev->tt->multi) slot_ctx->dev_info |= SWAP32(DEV_MTT); } xhci_dbg(xhci, "udev->tt = %p\n", udev->tt); xhci_dbg(xhci, "udev->ttport = 0x%x\n", udev->ttport); /* Step 4 - ring already allocated */ /* Step 5 */ ep0_ctx->ep_info2 = SWAP32(EP_TYPE(CTRL_EP)); /* * XXX: Not sure about wireless USB devices. */ switch (udev->speed) { case USB_SPEED_SUPER: ep0_ctx->ep_info2 |= SWAP32(MAX_PACKET(512)); break; case USB_SPEED_HIGH: /* USB core guesses at a 64-byte max packet first for FS devices */ case USB_SPEED_FULL: ep0_ctx->ep_info2 |= SWAP32(MAX_PACKET(64)); break; case USB_SPEED_LOW: ep0_ctx->ep_info2 |= SWAP32(MAX_PACKET(8)); break; case USB_SPEED_VARIABLE: xhci_dbg(xhci, "FIXME xHCI doesn't support wireless speeds\n"); return -EINVAL; break; default: /* New speed? */ BUG(); } /* EP 0 can handle "burst" sizes of 1, so Max Burst Size field is 0 */ ep0_ctx->ep_info2 |= SWAP32(MAX_BURST(0)); ep0_ctx->ep_info2 |= SWAP32(ERROR_COUNT(3)); ep0_ctx->deq = SWAP64(dev->eps[0].ring->first_seg->dma); ep0_ctx->deq |= SWAP64(dev->eps[0].ring->cycle_state); /* Steps 7 and 8 were done in xhci_alloc_virt_device() */ return 0; }
void CPacket::Write(qword Data) { *(qword *)(m_Data + m_WritePosition) = SWAP64(Data); m_WritePosition += 8; }
void OpenCLMomentumV8::find_collisions(uint8_t* message, collision_struct* out_buff, size_t* out_count) { // temp storage *out_count = 0; uint32_t ht_size = 1<<HASH_BITS; SHA512_Context c512_avxsse; SHA512_Init(&c512_avxsse); uint8_t midhash[32+4]; memcpy(midhash+4, message, 32); *((uint32_t*)midhash) = 0; SHA512_Update_Simple(&c512_avxsse, midhash, 32+4); SHA512_PreFinal(&c512_avxsse); *(uint32_t *)(&c512_avxsse.buffer.bytes[0]) = 0; uint64_t * swap_helper = (uint64_t*)(&c512_avxsse.buffer.bytes[0]); for (int i = 1; i < 5; i++) { swap_helper[i] = SWAP64(swap_helper[i]); } OpenCLContext *context = OpenCLMain::getInstance().getDevice(device_num)->getContext(); OpenCLProgram *program = context->getProgram(0); OpenCLKernel *kernel_calculate_all_hashes = program->getKernel("calculate_all_hashes"); OpenCLKernel *kernel_fill_table = program->getKernel("fill_table"); OpenCLKernel *kernel_find_collisions = program->getKernel("find_collisions"); OpenCLKernel *kernel_cleanup = program->getKernel("kernel_clean_hash_table"); OpenCLDevice * device = OpenCLMain::getInstance().getDevice(device_num); // cleans up the hash table size_t kc_wgsize = kernel_cleanup->getWorkGroupSize(device); kc_wgsize = 1<<log2(kc_wgsize); queue->enqueueKernel1D(kernel_cleanup, 1<<HASH_BITS, kc_wgsize); // printf("Cleaning the HT\n"); // queue->finish(); queue->enqueueWriteBuffer(cl_message, c512_avxsse.buffer.bytes, sizeof(uint8_t)*SHA512_BLOCK_SIZE); // step 1, calculate hashes size_t kcah_wgsize = kernel_calculate_all_hashes->getWorkGroupSize(device); kcah_wgsize = 1<<log2(kcah_wgsize); queue->enqueueKernel1D(kernel_calculate_all_hashes, MAX_MOMENTUM_NONCE/8, kcah_wgsize); // uint64_t * apa = new uint64_t[MAX_MOMENTUM_NONCE]; // queue->enqueueReadBuffer(hashes, apa, sizeof(uint64_t)*MAX_MOMENTUM_NONCE); // queue->finish(); // // printf("testing hashes\n"); // uint64_t count = 0; // for (int i = 0; i < MAX_MOMENTUM_NONCE; i++) { // if (apa[i] == 0) { // count++; // printf("BAD HASH AT: %d %X\n", i, apa[i]); // } // } // printf("counted %X bad hashes\n", count); // printf("NOW REALLY TEST THEM hashes\n"); // count = 0; // for (uint32_t i = 0; i < MAX_MOMENTUM_NONCE/8; i+=8) { // sph_sha512_context c512_sph; //SPH // sph_sha512_init(&c512_sph); // sph_sha512(&c512_sph, &i, 4); // sph_sha512(&c512_sph, message, 32); // uint64_t out[8]; // sph_sha512_close(&c512_sph, out); // for (int j =0; j < 8; j++) { // if (apa[i+j] != out[j]) { // count++; // uint64_t xxx = apa[i+j]; // printf("BAD HASH AT: %d => %X != %X\n", i, apa[i+j], out[j]); // } // } // } // printf("counted %X bad hashes\n", count); // step 2, populate hashtable size_t kft_wgsize = kernel_fill_table->getWorkGroupSize(device); kft_wgsize = 1<<log2(kft_wgsize); queue->enqueueKernel1D(kernel_fill_table, MAX_MOMENTUM_NONCE, kft_wgsize); // printf("step 2, populate hashtable\n"); // queue->finish(); queue->enqueueWriteBuffer(collisions_count, out_count, sizeof(size_t)); // step 3, find collisions size_t kfc_wgsize = kernel_find_collisions->getWorkGroupSize(device); kfc_wgsize = 1<<log2(kfc_wgsize); queue->enqueueKernel1D(kernel_find_collisions, MAX_MOMENTUM_NONCE, kfc_wgsize); // printf("step 3, find collisions\n"); // queue->finish(); queue->enqueueReadBuffer(collisions_count, out_count, sizeof(size_t)); queue->enqueueReadBuffer(collisions, out_buff, sizeof(collision_struct)*getCollisionCeiling()); // printf("step 4, copy output\n"); queue->finish(); #ifdef DEBUG printf("Collision Count = %d\n", (*out_count)); #endif }
qword CPacket::ReadLong() { qword Data = *(qword *)(m_Data + m_ReadPosition); m_ReadPosition += 8; return SWAP64(Data); }
void ProtoshareOpenCL::protoshare_process(minerProtosharesBlock_t* block) { #ifdef MEASURE_TIME uint32 overhead = getTimeMilliseconds(); #endif block->nonce = 0; uint32 target = *(uint32*)(block->targetShare + 28); // OpenCLDevice* device = OpenCLMain::getInstance().getDevice(device_num); uint32 midHash[8]; // midHash = sha256(sha256(block)) sha256_ctx c256; sha256_init(&c256); sha256_update(&c256, (unsigned char*)block, 80); sha256_final(&c256, (unsigned char*)midHash); sha256_init(&c256); sha256_update(&c256, (unsigned char*)midHash, 32); sha256_final(&c256, (unsigned char*)midHash); union { cl_ulong b64[16]; cl_uint b32[32]; } hash_state; hash_state.b32[0] = 0; // Reserved for nonce hash_state.b32[1] = midHash[0]; hash_state.b32[2] = midHash[1]; hash_state.b32[3] = midHash[2]; hash_state.b32[4] = midHash[3]; hash_state.b32[5] = midHash[4]; hash_state.b32[6] = midHash[5]; hash_state.b32[7] = midHash[6]; hash_state.b32[8] = midHash[7]; hash_state.b32[9] = 0x80; // High 1 bit to mark end of input // Swap the non-zero b64's except the first (so we can mix in the nonce later) for (uint8 i = 1; i < 5; ++i) { hash_state.b64[i] = SWAP64(hash_state.b64[i]); } #ifdef MEASURE_TIME printf("Hashing...\n"); uint32 begin = getTimeMilliseconds(); #endif // Calculate all hashes kernel_hash->resetArgs(); kernel_hash->addScalarULong(hash_state.b64[0]); kernel_hash->addScalarULong(hash_state.b64[1]); kernel_hash->addScalarULong(hash_state.b64[2]); kernel_hash->addScalarULong(hash_state.b64[3]); kernel_hash->addScalarULong(hash_state.b64[4]); kernel_hash->addGlobalArg(hash_list); kernel_hash->addGlobalArg(index_list); q->enqueueWriteBuffer(mid_hash, hash_state.b32, 10 * sizeof(cl_uint)); q->enqueueKernel1D(kernel_hash, MAX_MOMENTUM_NONCE / BIRTHDAYS_PER_HASH / vect_type, wgs); #ifdef MEASURE_TIME q->finish(); printf("Resetting...\n"); uint32 hash_end = getTimeMilliseconds(); #endif // Reset index list and find collisions cl_uint result_qty = 0; cl_uint result_a[256]; cl_uint result_b[256]; kernel_reset->resetArgs(); kernel_reset->addGlobalArg(hash_list); kernel_reset->addGlobalArg(index_list); kernel_reset->addGlobalArg(nonce_a); kernel_reset->addGlobalArg(nonce_b); kernel_reset->addGlobalArg(nonce_qty); q->enqueueWriteBuffer(nonce_qty, &result_qty, sizeof(cl_uint)); q->enqueueKernel1D(kernel_reset, (1 << buckets_log2), wgs); q->enqueueReadBuffer(nonce_a, result_a, sizeof(cl_uint) * 256); q->enqueueReadBuffer(nonce_b, result_b, sizeof(cl_uint) * 256); q->enqueueReadBuffer(nonce_qty, &result_qty, sizeof(cl_uint)); q->finish(); #ifdef MEASURE_TIME uint32 end = getTimeMilliseconds(); uint32 warmup_skips = 3; if (totalTableCount > warmup_skips) { // Allow some warmup time totalOverhead += (begin - overhead); totalHashTime += (hash_end - begin); totalResetTime += (end - hash_end); } printf("Found %2d collisions in %4d ms (Hash: %4d ms, Reset: %4d ms, Overhead: %4d)\n", result_qty * 2, (end - begin), (hash_end - begin), (end - hash_end), (begin - overhead)); if (totalTableCount > 0 && totalTableCount % 10 == 0) { printf("\nAVG TIMES - Total: %4d, Hash: %4d, Reset: %4d, Overhead: %4d\n\n", (totalHashTime + totalResetTime) / (totalTableCount - warmup_skips), totalHashTime / (totalTableCount - warmup_skips), totalResetTime / (totalTableCount - warmup_skips), totalOverhead / (totalTableCount - warmup_skips)); } #endif for (uint32 i = 0; i < result_qty; i++) { protoshares_revalidateCollision(block, (uint8 *)midHash, result_a[i], result_b[i]); } totalTableCount++; }
/* Defined in IEEE 802.11AC Appeared in Beacon, (Re)AssocReq, (Re)AssocResp, ProbReq/Resp frames */ INT build_vht_cap_ie(RTMP_ADAPTER *pAd, UCHAR *buf) { VHT_CAP_IE vht_cap_ie; #ifdef RT_BIG_ENDIAN UINT32 tmp_1; UINT64 tmp_2; #endif /*RT_BIG_ENDIAN*/ NdisZeroMemory((UCHAR *)&vht_cap_ie, sizeof(VHT_CAP_IE)); vht_cap_ie.vht_cap.max_mpdu_len = 0; // TODO: Ask Jerry about hardware limitation. vht_cap_ie.vht_cap.ch_width = 0; /* not support 160 or 80 + 80 MHz */ vht_cap_ie.vht_cap.sgi_80M = pAd->CommonCfg.vht_sgi_80; vht_cap_ie.vht_cap.htc_vht_cap = 1; vht_cap_ie.vht_cap.max_ampdu_exp = 3; // TODO: Ask Jerry about the hardware limitation, currently set as 64K vht_cap_ie.vht_cap.tx_stbc = 0; vht_cap_ie.vht_cap.rx_stbc = 0; if (pAd->CommonCfg.vht_stbc) { if (pAd->CommonCfg.TxStream >= 2) vht_cap_ie.vht_cap.tx_stbc = 1; else vht_cap_ie.vht_cap.tx_stbc = 0; if (pAd->CommonCfg.RxStream >= 1) vht_cap_ie.vht_cap.rx_stbc = 1; // TODO: is it depends on the number of our antennas? else vht_cap_ie.vht_cap.rx_stbc = 0; } vht_cap_ie.vht_cap.tx_ant_consistency = 1; vht_cap_ie.vht_cap.rx_ant_consistency = 1; vht_cap_ie.mcs_set.rx_mcs_map.mcs_ss1 = VHT_MCS_CAP_NA; vht_cap_ie.mcs_set.rx_mcs_map.mcs_ss2 = VHT_MCS_CAP_NA; vht_cap_ie.mcs_set.rx_mcs_map.mcs_ss3 = VHT_MCS_CAP_NA; vht_cap_ie.mcs_set.rx_mcs_map.mcs_ss4 = VHT_MCS_CAP_NA; vht_cap_ie.mcs_set.rx_mcs_map.mcs_ss5 = VHT_MCS_CAP_NA; vht_cap_ie.mcs_set.rx_mcs_map.mcs_ss6 = VHT_MCS_CAP_NA; vht_cap_ie.mcs_set.rx_mcs_map.mcs_ss7 = VHT_MCS_CAP_NA; vht_cap_ie.mcs_set.rx_mcs_map.mcs_ss8 = VHT_MCS_CAP_NA; vht_cap_ie.mcs_set.tx_mcs_map.mcs_ss1 = VHT_MCS_CAP_NA; vht_cap_ie.mcs_set.tx_mcs_map.mcs_ss2 = VHT_MCS_CAP_NA; vht_cap_ie.mcs_set.tx_mcs_map.mcs_ss3 = VHT_MCS_CAP_NA; vht_cap_ie.mcs_set.tx_mcs_map.mcs_ss4 = VHT_MCS_CAP_NA; vht_cap_ie.mcs_set.tx_mcs_map.mcs_ss5 = VHT_MCS_CAP_NA; vht_cap_ie.mcs_set.tx_mcs_map.mcs_ss6 = VHT_MCS_CAP_NA; vht_cap_ie.mcs_set.tx_mcs_map.mcs_ss7 = VHT_MCS_CAP_NA; vht_cap_ie.mcs_set.tx_mcs_map.mcs_ss8 = VHT_MCS_CAP_NA; switch (pAd->CommonCfg.RxStream) { case 1: vht_cap_ie.mcs_set.rx_high_rate = 292; #ifdef MT76x0 if (IS_MT76x0(pAd)) { /* MT7650E2 support VHT_MCS8 & VHT_MCS9. */ vht_cap_ie.mcs_set.rx_mcs_map.mcs_ss1 = VHT_MCS_CAP_9; } else #endif /* MT76x0 */ vht_cap_ie.mcs_set.rx_mcs_map.mcs_ss1 = VHT_MCS_CAP_7; break; case 2: vht_cap_ie.mcs_set.rx_high_rate = 585; vht_cap_ie.mcs_set.rx_mcs_map.mcs_ss1 = VHT_MCS_CAP_7; vht_cap_ie.mcs_set.rx_mcs_map.mcs_ss2 = VHT_MCS_CAP_7; break; default: vht_cap_ie.mcs_set.rx_high_rate = 0; break; } switch (pAd->CommonCfg.TxStream) { case 1: vht_cap_ie.mcs_set.tx_high_rate = 292; #ifdef MT76x0 if (IS_MT76x0(pAd)) { /* MT7650E2 support VHT_MCS8 & VHT_MCS9. */ vht_cap_ie.mcs_set.tx_mcs_map.mcs_ss1 = VHT_MCS_CAP_9; } else #endif /* MT76x0 */ vht_cap_ie.mcs_set.tx_mcs_map.mcs_ss1 = VHT_MCS_CAP_7; break; case 2: vht_cap_ie.mcs_set.tx_high_rate = 585; vht_cap_ie.mcs_set.tx_mcs_map.mcs_ss1 = VHT_MCS_CAP_7; vht_cap_ie.mcs_set.tx_mcs_map.mcs_ss2 = VHT_MCS_CAP_7; break; default: vht_cap_ie.mcs_set.tx_high_rate = 0; break; } #ifdef RT_BIG_ENDIAN NdisCopyMemory(&tmp_1,&vht_cap_ie.vht_cap, 4); tmp_1 = SWAP32(tmp_1); NdisCopyMemory(&vht_cap_ie.vht_cap,&tmp_1, 4); NdisCopyMemory(&tmp_2,&vht_cap_ie.mcs_set, 8); tmp_2=SWAP64(tmp_2); NdisCopyMemory(&vht_cap_ie.mcs_set,&tmp_2, 8); //hex_dump("&vht_cap_ie", &vht_cap_ie, sizeof(VHT_CAP_IE)); //SWAP32((UINT32)vht_cap_ie.vht_cap); //SWAP32((UINT32)vht_cap_ie.mcs_set); #endif /* RT_BIG_ENDIAN */ NdisMoveMemory(buf, (UCHAR *)&vht_cap_ie, sizeof(VHT_CAP_IE)); return sizeof(VHT_CAP_IE); }
MEXP(cm_pe_t) cm_pe_load(const char* filename) { cm_pe_t pe; cm_pe_header_t* header; cm_pe_optional_header_t* opt_header; cm_pe_windows_header_t* win_header; long pe_offset = 0; //size_t i; size_t count; pe = (cm_pe_t) malloc(sizeof(struct cm_pe)); if (!pe) return (cm_pe_t) 0; memset(pe, 0, sizeof(struct cm_pe)); pe->f = fopen(filename, "r"); if (!pe->f) { free(pe); return (cm_pe_t) 0; } if (fseek(pe->f, 0x3CL, SEEK_SET) == -1) goto err_trap; if (fread(&pe_offset, 4, 1, pe->f) != 1) goto err_trap; #if BIG_ENDIAN pe_offset = LSB4(pe_offset); #endif if (fseek(pe->f, pe_offset, SEEK_SET) == -1) goto err_trap; if (fread(&pe->header, sizeof(cm_pe_header_t), 1, pe->f) != 1) goto err_trap; header = &pe->header; #if BIGENDIAN /* Without regular expressions, this would've sucked. */ header->signature = SWAP32(header->signature); header->machine = SWAP16(header->machine); header->section_count = SWAP16(header->section_count); header->timestamp = SWAP32(header->timestamp); header->symbol_table_offset = SWAP32(header->symbol_table_offset); header->symbol_count = SWAP32(header->symbol_count); header->optional_header_size = SWAP16(header->optional_header_size); header->characteristics = SWAP16(header->characteristics); #endif if (header->optional_header_size > 0) { if (fread(&pe->optional_header, PE_OPTIONAL_HEADER_MIN_SIZE, 1, pe->f) != 1) { goto err_trap; } opt_header = &pe->optional_header; win_header = &pe->windows_header; #if BIGENDIAN opt_header->magic = SWAP16(opt_header->magic); #endif if (opt_header->magic == IMAGE_FORMAT_PE32) { if (fread(&opt_header->data_base, 4, 1, pe->f) != 1) goto err_trap; if (fread(&win_header->image_base, 4, 1, pe->f) != 1) goto err_trap; // The 40 is not a typo. if (fread(&win_header->section_alignment, 40, 1, pe->f) != 1) goto err_trap; if (fread(&win_header->stack_reserve_size, 4, 1, pe->f) != 1) goto err_trap; if (fread(&win_header->stack_commit_size, 4, 1, pe->f) != 1) goto err_trap; if (fread(&win_header->heap_reserve_size, 4, 1, pe->f) != 1) goto err_trap; if (fread(&win_header->heap_commit_size, 4, 1, pe->f) != 1) goto err_trap; if (fread(&win_header->loader_flags, 4, 1, pe->f) != 1) goto err_trap; if (fread(&win_header->data_directory_count, 4, 1, pe->f) != 1) goto err_trap; } else if (opt_header->magic == IMAGE_FORMAT_PE32_PLUS) { if (fread(win_header, sizeof(cm_pe_windows_header_t), 1, pe->f)!= 1) goto err_trap; } else { goto err_trap; } #if BIGENDIAN opt_header->code_section_size = SWAP32(opt_header->code_section_size); opt_header->initialized_data_size = SWAP32(opt_header->initialized_data_size); opt_header->uninitialized_data_size = SWAP32(opt_header->uninitialized_data_size); opt_header->entry_point = SWAP32(opt_header->entry_point); opt_header->code_base = SWAP32(opt_header->code_base); opt_header->data_base = SWAP32(opt_header->data_base); win_header->image_base = SWAP64(win_header->image_base); win_header->section_alignment = SWAP32(win_header->section_alignment); win_header->file_alignment = SWAP32(win_header->file_alignment); win_header->major_os_version = SWAP16(win_header->major_os_version); win_header->minor_os_version = SWAP16(win_header->minor_os_version); win_header->major_image_version = SWAP16(win_header->major_image_version); win_header->minor_image_version = SWAP16(win_header->minor_image_version); win_header->major_subsystem_version = SWAP16(win_header->major_subsystem_version); win_header->minor_subsystem_version = SWAP16(win_header->minor_subsystem_version); win_header->reserved = SWAP32(win_header->reserved); win_header->image_size = SWAP32(win_header->image_size); win_header->headers_size = SWAP32(win_header->headers_size); win_header->checksum = SWAP32(win_header->checksum); win_header->subsystem = SWAP16(win_header->subsystem); win_header->dll_characteristics = SWAP16(win_header->dll_characteristics); win_header->stack_reserve_size = SWAP64(win_header->stack_reserve_size); win_header->stack_commit_size = SWAP64(win_header->stack_commit_size); win_header->heap_reserve_size = SWAP64(win_header->heap_reserve_size); win_header->heap_commit_size = SWAP64(win_header->heap_commit_size); win_header->loader_flags = SWAP32(win_header->loader_flags); win_header->data_directory_count = SWAP32(win_header->data_directory_count); #endif if (win_header->data_directory_count > 0) { count = win_header->data_directory_count; pe->data_directories = (cm_pe_data_directory_t*) calloc(sizeof(cm_pe_data_directory_t), count); if (!pe->data_directories) goto err_trap; if (fread(pe->data_directories, sizeof(cm_pe_data_directory_t), count, pe->f) != count) { goto dir_err_trap; } #if BIGENDIAN for (i = 0; i < count; i++) { pe->data_directories[i].rva = SWAP32(pe->data_directories[i].rva); pe->data_directories[i].size = SWAP32(pe->data_directories[i].size); } #endif } count = (size_t) header->section_count; if (count) { pe->sections = (cm_pe_section_t*) calloc(sizeof(cm_pe_section_t), count); if (!pe->sections) goto dir_err_trap; if (fread(pe->sections, sizeof(cm_pe_section_t), count, pe->f) != count) { goto sect_err_trap; } } #if BIGENDIAN for (i = 0; i < count; i++) { pe->sections[i].virtual_size = SWAP32(pe->sections[i].virtual_size); pe->sections[i].virtual_address = SWAP32(pe->sections[i].virtual_address); pe->sections[i].raw_data_size = SWAP32(pe->sections[i].raw_data_size); pe->sections[i].raw_data_offset = SWAP32(pe->sections[i].raw_data_offset); pe->sections[i].relocations_offset = SWAP32(pe->sections[i].relocations_offset); pe->sections[i].line_numbers_offset = SWAP32(pe->sections[i].line_numbers_offset); pe->sections[i].relocation_count = SWAP16(pe->sections[i].relocation_count); pe->sections[i].line_number_count = SWAP16(pe->sections[i].line_number_count); pe->sections[i].characteristics = SWAP32(pe->sections[i].characteristics); } #endif } return pe; sect_err_trap: free(pe->sections); dir_err_trap: free(pe->data_directories); err_trap: fclose(pe->f); free(pe); return (cm_pe_t) 0; }
/* Defined in IEEE 802.11AC Appeared in Beacon, (Re)AssocReq, (Re)AssocResp, ProbReq/Resp frames */ INT build_vht_cap_ie(RTMP_ADAPTER *pAd, UCHAR *buf) { VHT_CAP_IE vht_cap_ie; INT rx_nss, tx_nss, mcs_cap; #ifdef RT_BIG_ENDIAN UINT32 tmp_1; UINT64 tmp_2; #endif /*RT_BIG_ENDIAN*/ NdisZeroMemory((UCHAR *)&vht_cap_ie, sizeof(VHT_CAP_IE)); vht_cap_ie.vht_cap.max_mpdu_len = 0; // TODO: Ask Jerry about hardware limitation. vht_cap_ie.vht_cap.ch_width = 0; /* not support 160 or 80 + 80 MHz */ if (pAd->CommonCfg.vht_ldpc && (pAd->chipCap.phy_caps & fPHY_CAP_LDPC)) vht_cap_ie.vht_cap.rx_ldpc = 1; else vht_cap_ie.vht_cap.rx_ldpc = 0; vht_cap_ie.vht_cap.sgi_80M = pAd->CommonCfg.vht_sgi_80; vht_cap_ie.vht_cap.htc_vht_cap = 1; vht_cap_ie.vht_cap.max_ampdu_exp = 3; // TODO: Ask Jerry about the hardware limitation, currently set as 64K vht_cap_ie.vht_cap.tx_stbc = 0; vht_cap_ie.vht_cap.rx_stbc = 0; if (pAd->CommonCfg.vht_stbc) { if (pAd->CommonCfg.TxStream >= 2) vht_cap_ie.vht_cap.tx_stbc = 1; else vht_cap_ie.vht_cap.tx_stbc = 0; if (pAd->CommonCfg.RxStream >= 1) vht_cap_ie.vht_cap.rx_stbc = 1; // TODO: is it depends on the number of our antennas? else vht_cap_ie.vht_cap.rx_stbc = 0; } vht_cap_ie.vht_cap.tx_ant_consistency = 1; vht_cap_ie.vht_cap.rx_ant_consistency = 1; vht_cap_ie.mcs_set.rx_mcs_map.mcs_ss1 = VHT_MCS_CAP_NA; vht_cap_ie.mcs_set.rx_mcs_map.mcs_ss2 = VHT_MCS_CAP_NA; vht_cap_ie.mcs_set.rx_mcs_map.mcs_ss3 = VHT_MCS_CAP_NA; vht_cap_ie.mcs_set.rx_mcs_map.mcs_ss4 = VHT_MCS_CAP_NA; vht_cap_ie.mcs_set.rx_mcs_map.mcs_ss5 = VHT_MCS_CAP_NA; vht_cap_ie.mcs_set.rx_mcs_map.mcs_ss6 = VHT_MCS_CAP_NA; vht_cap_ie.mcs_set.rx_mcs_map.mcs_ss7 = VHT_MCS_CAP_NA; vht_cap_ie.mcs_set.rx_mcs_map.mcs_ss8 = VHT_MCS_CAP_NA; vht_cap_ie.mcs_set.tx_mcs_map.mcs_ss1 = VHT_MCS_CAP_NA; vht_cap_ie.mcs_set.tx_mcs_map.mcs_ss2 = VHT_MCS_CAP_NA; vht_cap_ie.mcs_set.tx_mcs_map.mcs_ss3 = VHT_MCS_CAP_NA; vht_cap_ie.mcs_set.tx_mcs_map.mcs_ss4 = VHT_MCS_CAP_NA; vht_cap_ie.mcs_set.tx_mcs_map.mcs_ss5 = VHT_MCS_CAP_NA; vht_cap_ie.mcs_set.tx_mcs_map.mcs_ss6 = VHT_MCS_CAP_NA; vht_cap_ie.mcs_set.tx_mcs_map.mcs_ss7 = VHT_MCS_CAP_NA; vht_cap_ie.mcs_set.tx_mcs_map.mcs_ss8 = VHT_MCS_CAP_NA; mcs_cap = pAd->chipCap.max_vht_mcs; rx_nss = pAd->CommonCfg.RxStream; tx_nss = pAd->CommonCfg.TxStream; #ifdef WFA_VHT_PF if ((pAd->CommonCfg.vht_nss_cap > 0) && (pAd->CommonCfg.vht_nss_cap < pAd->CommonCfg.RxStream)) rx_nss = pAd->CommonCfg.vht_nss_cap; if ((pAd->CommonCfg.vht_nss_cap > 0) && (pAd->CommonCfg.vht_nss_cap < pAd->CommonCfg.TxStream)) tx_nss = pAd->CommonCfg.vht_nss_cap; if (pAd->CommonCfg.vht_mcs_cap <pAd->chipCap.max_vht_mcs) mcs_cap = pAd->CommonCfg.vht_mcs_cap; #endif /* WFA_VHT_PF */ switch (rx_nss) { case 1: vht_cap_ie.mcs_set.rx_high_rate = 292; vht_cap_ie.mcs_set.rx_mcs_map.mcs_ss1 = mcs_cap; break; case 2: if (mcs_cap == VHT_MCS_CAP_9) vht_cap_ie.mcs_set.rx_high_rate = 780; else vht_cap_ie.mcs_set.rx_high_rate = 585; vht_cap_ie.mcs_set.rx_mcs_map.mcs_ss1 = mcs_cap; vht_cap_ie.mcs_set.rx_mcs_map.mcs_ss2 = mcs_cap; break; default: vht_cap_ie.mcs_set.rx_high_rate = 0; break; } switch (tx_nss) { case 1: vht_cap_ie.mcs_set.tx_high_rate = 292; vht_cap_ie.mcs_set.tx_mcs_map.mcs_ss1 = mcs_cap; break; case 2: if (mcs_cap == VHT_MCS_CAP_9) vht_cap_ie.mcs_set.tx_high_rate = 780; else vht_cap_ie.mcs_set.tx_high_rate = 585; vht_cap_ie.mcs_set.tx_mcs_map.mcs_ss1 = mcs_cap; vht_cap_ie.mcs_set.tx_mcs_map.mcs_ss2 = mcs_cap; break; default: vht_cap_ie.mcs_set.tx_high_rate = 0; break; } #ifdef RT_BIG_ENDIAN NdisCopyMemory(&tmp_1,&vht_cap_ie.vht_cap, 4); tmp_1 = SWAP32(tmp_1); NdisCopyMemory(&vht_cap_ie.vht_cap,&tmp_1, 4); NdisCopyMemory(&tmp_2,&vht_cap_ie.mcs_set, 8); tmp_2 = SWAP64(tmp_2); NdisCopyMemory(&vht_cap_ie.mcs_set,&tmp_2, 8); //hex_dump("&vht_cap_ie", &vht_cap_ie, sizeof(VHT_CAP_IE)); //SWAP32((UINT32)vht_cap_ie.vht_cap); //SWAP32((UINT32)vht_cap_ie.mcs_set); #endif /* RT_BIG_ENDIAN */ #ifdef VHT_TXBF_SUPPORT if ((pAd->chipCap.FlgHwTxBfCap) && (pAd->BeaconSndDimensionFlag == 0)) { vht_cap_ie.vht_cap.num_snd_dimension = pAd->CommonCfg.vht_cap_ie.vht_cap.num_snd_dimension; vht_cap_ie.vht_cap.cmp_st_num_bfer= pAd->CommonCfg.vht_cap_ie.vht_cap.cmp_st_num_bfer; vht_cap_ie.vht_cap.bfee_cap_su=pAd->CommonCfg.vht_cap_ie.vht_cap.bfee_cap_su; vht_cap_ie.vht_cap.bfer_cap_su=pAd->CommonCfg.vht_cap_ie.vht_cap.bfer_cap_su; } pAd->BeaconSndDimensionFlag =0; #endif NdisMoveMemory(buf, (UCHAR *)&vht_cap_ie, sizeof(VHT_CAP_IE)); return sizeof(VHT_CAP_IE); }
/** * This function converts (swaps) an array of EVIO composite type data * between IEEE (big endian) and DECS (little endian) in place. This * data does <b>NOT</b> include the composite type's beginning tagsegment and * the format string it contains. It also does <b>NOT</b> include the data's * bank header words. * * Converts the data of array (iarr[i], i=0...nwrd-1) * using the format code (ifmt[j], j=0...nfmt-1) . * * <p> * Algorithm description:<p> * Data processed inside while (ib < nwrd) * loop, where 'ib' is iarr[] index; * loop breaks when 'ib' reaches the number of elements in iarr[] * * * @param iarr pointer to data to be swapped * @param nwrd number of data words (32-bit ints) to be swapped * @param ifmt unsigned char array holding translated format * @param nfmt length of unsigned char array, ifmt, in # of chars * @param tolocal if 0 data is of same endian as local host, * else data is of opposite endian * * @return 0 if success * @return -1 if nwrd or nfmt arg(s) < 0 */ int eviofmtswap(int32_t *iarr, int nwrd, unsigned char *ifmt, int nfmt, int tolocal) { int imt, ncnf, kcnf, lev, iterm; int64_t *b64, *b64end; int32_t *b32, *b32end; int16_t *b16, *b16end; int8_t *b8, *b8end; LV lv[10]; if (nwrd <= 0 || nfmt <= 0) return(-1); imt = 0; /* ifmt[] index */ lev = 0; /* parenthesis level */ ncnf = 0; /* how many times must repeat a format */ iterm = 0; b8 = (int8_t *)&iarr[0]; /* beginning of data */ b8end = (int8_t *)&iarr[nwrd]; /* end of data + 1 */ #ifdef DEBUG printf("\n======== eviofmtswap ==========\n"); #endif while (b8 < b8end) { #ifdef DEBUG printf("+++ begin = 0x%08x, end = 0x%08x\n", b8, b8end); #endif /* get next format code */ while (1) { imt++; /* end of format statement reached, back to iterm - last parenthesis or format begining */ if (imt > nfmt) { imt = iterm; #ifdef DEBUG printf("1\n"); #endif } /* meet right parenthesis, so we're finished processing format(s) in parenthesis */ else if (ifmt[imt-1] == 0) { /* increment counter */ lv[lev-1].irepeat ++; /* if format in parenthesis was processed */ if (lv[lev-1].irepeat >= lv[lev-1].nrepeat) { /* required number of times */ /* store left parenthesis index minus 1 (if will meet end of format, will start from format index imt=iterm; by default we continue from the beginning of the format (iterm=0)) */ iterm = lv[lev-1].left - 1; lev--; /* done with this level - decrease parenthesis level */ #ifdef DEBUG printf("2\n"); #endif } /* go for another round of processing by setting 'imt' to the left parenthesis */ else { /* points ifmt[] index to the left parenthesis from the same level 'lev' */ imt = lv[lev-1].left; #ifdef DEBUG printf("3\n"); #endif } } else { /* how many times to repeat format code */ ncnf = ifmt[imt-1]/16; /* format code */ kcnf = ifmt[imt-1] - 16*ncnf; /* left parenthesis, SPECIAL case: # of repeats must be taken from data */ if (kcnf == 15) { /* set it to regular left parenthesis code */ kcnf = 0; /* get # of repeats from data (watch out for endianness) */ b32 = (int32_t *)b8; if (!tolocal) ncnf = *b32; *b32 = SWAP32(*b32); if (tolocal) ncnf = *b32; b8 += 4; #ifdef DEBUG printf("\n*1 ncnf from data = %#10.8x, b8 = 0x%08x\n",ncnf, b8); #endif } /* left parenthesis - set new lv[] */ if (kcnf == 0) { /* store ifmt[] index */ lv[lev].left = imt; /* how many time will repeat format code inside parenthesis */ lv[lev].nrepeat = ncnf; /* cleanup place for the right parenthesis (do not get it yet) */ lv[lev].irepeat = 0; /* increase parenthesis level */ lev++; #ifdef DEBUG printf("4\n"); #endif } /* format F or I or ... */ else { /* there are no parenthesis, just simple format, go to processing */ if (lev == 0) { #ifdef DEBUG printf("51\n"); #endif } /* have parenthesis, NOT the pre-last format element (last assumed ')' ?) */ else if (imt != (nfmt-1)) { #ifdef DEBUG printf("52: %d %d\n",imt,nfmt-1); #endif } /* have parenthesis, NOT the first format after the left parenthesis */ else if (imt != lv[lev-1].left+1) { #ifdef DEBUG printf("53: %d %d\n",imt,nfmt-1); #endif } /* if none of above, we are in the end of format */ else { /* set format repeat to the big number */ ncnf = 999999999; #ifdef DEBUG printf("54\n"); #endif } break; } } } /* while(1) */ if (ncnf == 0) { /* get # of repeats from data (watch out for endianness) */ b32 = (int32_t *)b8; if (!tolocal) ncnf = *b32; *b32 = SWAP32(*b32); if (tolocal) ncnf = *b32; b8 += 4; #ifdef DEBUG printf("\n*2 ncnf from data = %d\n",ncnf); #endif } /* At this point we are ready to process next piece of data. We have following entry info: kcnf - format type ncnf - how many times format repeated b8 - starting data pointer (it comes from previously processed piece) */ /* Convert data in according to type kcnf */ /* 64-bits */ if (kcnf == 8 || kcnf == 9 || kcnf == 10) { b64 = (int64_t *)b8; b64end = b64 + ncnf; if (b64end > (int64_t *)b8end) b64end = (int64_t *)b8end; while (b64 < b64end) *b64++ = SWAP64(*b64); b8 = (int8_t *)b64; #ifdef DEBUG printf("64bit: %d elements\n",ncnf); #endif } /* 32-bits */ else if ( kcnf == 1 || kcnf == 2 || kcnf == 11 || kcnf == 12) { b32 = (int32_t *)b8; b32end = b32 + ncnf; if (b32end > (int32_t *)b8end) b32end = (int32_t *)b8end; while (b32 < b32end) *b32++ = SWAP32(*b32); b8 = (int8_t *)b32; #ifdef DEBUG printf("32bit: %d elements, b8 = 0x%08x\n",ncnf, b8); #endif } /* 16 bits */ else if ( kcnf == 4 || kcnf == 5) { b16 = (int16_t *)b8; b16end = b16 + ncnf; if (b16end > (int16_t *)b8end) b16end = (int16_t *)b8end; while (b16 < b16end) *b16++ = SWAP16(*b16); b8 = (int8_t *)b16; #ifdef DEBUG printf("16bit: %d elements\n",ncnf); #endif } /* 8 bits */ else if ( kcnf == 6 || kcnf == 7 || kcnf == 3) { /* do nothing for characters */ b8 += ncnf; #ifdef DEBUG printf("8bit: %d elements\n",ncnf); #endif } } /* while(b8 < b8end) */ return(0); }