static int _vlsctlc_pack_cmd(struct vlsctlc* lsctlc, void* buf, int len) { struct vlsctlc_pack_cmd_desc* desc = lsctlc_pack_cmd_desc; void* len_addr = NULL; int ret = 0; int tsz = 0; int bsz = 0; vassert(lsctlc); vassert(buf); vassert(len > 0); set_uint8(buf + tsz, VLSCTL_VERSION); tsz += sizeof(uint8_t); set_uint8(buf + tsz, (uint8_t)lsctlc->type); tsz += sizeof(uint8_t); set_uint16(len_addr = buf + tsz, 0); tsz += sizeof(uint16_t); set_uint32(buf + tsz, VLSCTL_MAGIC); tsz += sizeof(uint32_t); for (; desc->cmd; desc++) { ret = desc->cmd(lsctlc, buf + tsz, len - tsz); if (ret < 0) { return -1; } bsz += ret; tsz += ret; } *(uint16_t*)len_addr = (uint16_t)bsz; return tsz; }
static void test_util_format_unaligned_accessors(void *ignored) { (void)ignored; char buf[9] = "onionsoup"; // 6f6e696f6e736f7570 tt_u64_op(get_uint64(buf+1), OP_EQ, htonll(U64_LITERAL(0x6e696f6e736f7570))); tt_uint_op(get_uint32(buf+1), OP_EQ, htonl(0x6e696f6e)); tt_uint_op(get_uint16(buf+1), OP_EQ, htons(0x6e69)); tt_uint_op(get_uint8(buf+1), OP_EQ, 0x6e); set_uint8(buf+7, 0x61); tt_mem_op(buf, OP_EQ, "onionsoap", 9); set_uint16(buf+6, htons(0x746f)); tt_mem_op(buf, OP_EQ, "onionstop", 9); set_uint32(buf+1, htonl(0x78696465)); tt_mem_op(buf, OP_EQ, "oxidestop", 9); set_uint64(buf+1, htonll(U64_LITERAL(0x6266757363617465))); tt_mem_op(buf, OP_EQ, "obfuscate", 9); done: ; }
void HCI_SET_EVENT_FILTER_T_PDU::set_filter_condition_type ( uint8 type ) { uint8 ft = get_filter_type(); uint16 size = 4; // basic, 3 header + 1 FT switch ( ft ) { case 0: return; case 1: // must have FCT. size++; break; case 2: // must have FCT and AAF size += 2; break; default: return; } switch ( type ) { case 0: // nothing break; case 1: // COD and COD mask size += 6; break; case 2: // BDA size += 6; break; default: return; } resize ( size ); set_uint8 ( HCI_SET_EVENT_FILTER_T_filter_condition_type , type ); }
bool HCI_SET_EVENT_FILTER_T_PDU::set_condition ( uint8 auto_accept_flag ) { bool ok = (get_filter_type() == 2); if ( ok ) { switch ( get_filter_condition_type() ) { case 0: set_uint8 ( HCI_SET_EVENT_FILTER_T_AAF_all , auto_accept_flag ); break; case 1: set_uint8 ( HCI_SET_EVENT_FILTER_T_AAF_COD , auto_accept_flag ); break; case 2: set_uint8 ( HCI_SET_EVENT_FILTER_T_AAF_BDA , auto_accept_flag ); break; default: ok = false; break; } } return ok; }
void HCIEventPDU::set_parameter_length() { /* the first 2 bytes in an event are header */ set_uint8(1,size()-2) ; }
void HCIEventPDU::set_event_code(uint8 code) { set_uint8(0,code) ; }
void HCI_WRITE_CURRENT_IAC_LAP_T_PDU::set_num_current_iac(uint8 val) { set_uint8(HCI_WRITE_CURRENT_IAC_LAP_T_num_current_iac,val) ; }
void HCI_SET_EVENT_FILTER_T_PDU::set_filter_type ( uint8 type ) { if ( type == 0 ) resize ( HCI_SET_EVENT_FILTER_T_filter_condition_type ); set_uint8 ( HCI_SET_EVENT_FILTER_T_filter_type , type ); }
void HCI_WRITE_STORED_LINK_KEY_T_PDU::set_number_keys(uint8 val) { // HCI bdaddr size = 6, link key size = 16 resize ( HCI_WRITE_STORED_LINK_KEY_T_pduSize + val * (6+16) ); set_uint8(HCI_WRITE_STORED_LINK_KEY_T_number_keys,val) ; }
void HCI_HOST_NUM_COMPLETED_PACKETS_T_PDU::set_num_handles(uint8 val) { resize(HCI_HOST_NUM_COMPLETED_PACKETS_T_pduSize + val * 4); set_uint8(HCI_HOST_NUM_COMPLETED_PACKETS_T_num_handles,val) ; }
void BNEP_HCI_SWITCH_ROLE_RSP_T_PDU::set_role( uint8 value ) { set_uint8 ( BNEP_HCI_SWITCH_ROLE_RSP_T_role , value ); }
void BNEP_HCI_SWITCH_ROLE_RSP_T_PDU::set_status( uint8 value ) { set_uint8 ( BNEP_HCI_SWITCH_ROLE_RSP_T_status , value ); }
void HCIPDU::set_BluetoothDeviceAddress ( uint16 offset , const BluetoothDeviceAddress& addr) { set_uint24 ( offset , addr.get_lap() ); set_uint8 ( offset + 3 , addr.get_uap() ); set_uint16 ( offset + 4 , addr.get_nap() ); }