.. _cpp_whad_discovery: WHAD Device discovery ===================== When a host computer starts communicating with a WHAD interface, it sends a series of message to discover its characteristics and its supported domains in order to tailor the host features and match the capabilities exposed by the interface. .. _cpp_whad_discovery_cap: Discovery of interface characteristics -------------------------------------- First, the host sends a *DeviceInfoQuery* message to the WHAD interface that is expected to responds with a *DeviceInfoResp* message. This message must provide the following information: - the device type - the device unique ID - the minimum supported version of WHAD protocol - the device maximum communication speed - the author name (limited to 64 characters) - the firmware project URL (linited to 256 characters) - the firmware major version number - the firmware minor version number - the firmware revision number - a list of capabilities To build such a message, we need to define first our capabilities: .. code-block:: c const whad_domain_desc_t CAPABILITIES[] = { { /* We support the Bluetooth Low Energy wireless protocol. */ DOMAIN_BTLE, /* For this protocol, we are able to sniff, inject and emulate central and peripheral roles. */ (whad_capability_t)(CAP_SNIFF | CAP_INJECT | CAP_SIMULATE_ROLE), /* We define the list of supported commands, based on NanoPb command values. */ ( CMD(ble_BleCommand_SniffAdv) | CMD(ble_BleCommand_SniffConnReq) | CMD(ble_BleCommand_SniffActiveConn) | CMD(ble_BleCommand_Start) | CMD(ble_BleCommand_Stop) | CMD(ble_BleCommand_SendRawPDU) | CMD(ble_BleCommand_SendPDU) | CMD(ble_BleCommand_CentralMode) | CMD(ble_BleCommand_PeripheralMode) | CMD(ble_BleCommand_ConnectTo) | CMD(ble_BleCommand_Disconnect) | CMD(ble_BleCommand_PrepareSequence) | CMD(ble_BleCommand_TriggerSequence) | CMD(ble_BleCommand_DeleteSequence) | CMD(ble_BleCommand_ScanMode) ) }, /* End of supported domains, MUST be there to mark the end of this list. */ {DOMAIN_NONE, CAP_NONE, 0x00000000} }; Once our capabilities defined, we can build the response message: .. code-block:: cpp using namespace whad::discovery; DeviceInfoResp( Devices::Butterfly, (uint8_t *)"MyAwesomeDevice", /* Supports WHAD protocol v2 */ 2, /* Max speed for our UART hw */ 115200, /* Firmware author. */ "John Doe = 2) { /* Fill response message with DeviceInfoResp. */ response = new whad::discovery::DeviceInfoResp( query.getDomain(), CAPABILITIES ) } else { /* Client protocol version is too old. */ response = new whad::generic::Error(); } } break; /* DeviceDomainInfoQuery message. */ case whad::discovery::MessageType::DomainInfoQueryMsg: { /* Parse incoming message. */ whad::discovery::DomainInfoQuery query(message); response = new whad::discovery::DomainInfoResp( query.getDomain(), CAPABILITIES ); } break; /* SetTransportSpeed */ case whad::discovery::MessageType::SetSpeedMsg: { /* Send a success result code. */ response = new whad::generic::Success(); whad::send(*response); delete response; /*" * Re-configure communication hardware with new speed: * * 1. Flush current UART buffer * 2. Re-configure UART interface **/ /* Once done and ready, send a DeviceReadyResp to host. */ response = new whad::discovery::ReadyResp(); } break; /* DeviceResetQuery */ case whad::discovery::MessageType::DeviceResetMsg: { /* Reset WHAD interface state. */ interface_reset_state(); /* Send a DeviceReadyResp. */ response = new whad::discovery::ReadyResp(); } break; default: { /* Unsupported command. */ response = whad::generic::Error(); } break; } /* Send response. */ whad::send(*response); delete response; } Discovery API reference ----------------------- .. doxygennamespace:: whad::discovery :members: