About Inquiry_with_RSSI
Carlos Fernández Herranz
cfernandezh at udc.es
Mon Apr 24 09:34:56 UTC 2006
Firsly, the command packets and constants:
#define NG_HCI_EVENT_INQUIRY_RESULT_WITH_RSSI 0x22
*typedef* *struct* {
u_int8_t num_responses; //* number of responses *//
} __attribute__ ((packed)) ng_hci_inquiry_result_with_rssi_ep;
*typedef* *struct* {
bdaddr_t bdaddr;
u_int8_t pagescan_rep_mode;
u_int8_t pagescan_period_mode;
u_int8_t uclass[NG_HCI_CLASS_SIZE];
u_int16_t clock_offset;
char rssi;
} __attribute__ ((packed)) ng_hci_inquiry_response_with_rssi;
#define NG_HCI_OCF_WRITE_INQUIRY_MODE 0x0045
*typedef* *struct* {
u_int8_t mode;
} __attribute__ ((packed)) ng_hci_write_inquiry_mode_cp;
#define NG_HCI_WRITE_INQUIRY_MODE_CP_SIZE 1
*typedef* *struct* {
u_int8_t status;
} __attribute__ ((packed)) ng_hci_write_inquiry_mode_rp;
#define NG_HCI_WRITE_INQUIRY_MODE_RP_SIZE 1
#define NG_HCI_OCF_READ_INQUIRY_MODE 0x0044
*typedef* *struct* {
u_int8_t status;
u_int8_t mode;
} __attribute__ ((packed)) ng_hci_read_inquiry_mode_rp;
#define NG_HCI_READ_INQUIRY_MODE_RP_SIZE 2
To allow the reception of the inquiry results with rssi it's required to
modify the event filter adding this line:
bit_set(filter.event_mask, NG_HCI_EVENT_INQUIRY_RESULT_WITH_RSSI - 1);
You can see here the implementation for the commands:
static int hci_write_inquiry_mode(int s, int mode)
{
ng_hci_write_inquiry_mode_cp cp;
ng_hci_write_inquiry_mode_rp rp;
int n;
int response;
//* parse command parameters *//
*switch* (mode) {
*case* 0:
cp.mode = (uint8_t) mode;
*break*;
*case* 1:
cp.mode = (uint8_t) mode;
*break*;
*default*:
*return* (ERROR);
}
n = *sizeof*(rp);
*if* ((response=hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND,
NG_HCI_OCF_WRITE_INQUIRY_MODE),
(char const *) &cp, *sizeof*(cp),
(char *) &rp, &n)) == ERROR) {
*return* (ERROR);
}
*if* (rp.status != 0x00) {
fprintf(stdout, "Status: %s [%#02x]\n",
hci_status2str(rp.status), rp.status);
*return* (FAILED);
}
*return* (OK);
} //* end hci_write_inquiry_mode *//
static int hci_read_inquiry_mode(int s)
{
ng_hci_read_inquiry_mode_rp rp;
int n;
int response;
n = *sizeof*(rp);
*if* (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_INFO,
NG_HCI_OCF_READ_BDADDR), (char *) &rp, &n) == ERROR)
*return* (ERROR);
*if* ((response=hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND,
NG_HCI_OCF_READ_INQUIRY_MODE),
(char *) &rp, &n)) == ERROR) {
*return* (ERROR);
}
printf("\nInquiry mode: %d\n", rp.mode);
*if* (rp.status != 0x00) {
fprintf(stdout, "Status: %s [%#02x]\n",
hci_status2str(rp.status), rp.status);
*return* (FAILED);
}
*return* (OK);
} //* end hci_read_inquiry_mode *//
You have also to modify the hci_inquiry function to support
inquiry_with_rssi adding support for its events, adding:
*case* NG_HCI_EVENT_INQUIRY_RESULT_WITH_RSSI: {
ng_hci_inquiry_result_with_rssi_ep *ir =
(ng_hci_inquiry_result_with_rssi_ep *)(e + 1);
uint8_t *r = (uint8_t *)(ir + 1);
*for* (n0 = 0; n0 < ir->num_responses; n0++)
hci_inquiry_response_with_rssi(&r);
*goto* wait_for_more;
}
Finally you have to provide an event processor, that is the function:
static void hci_inquiry_response_with_rssi(uint8_t **b)
{
ng_hci_inquiry_response_with_rssi *ir = (ng_hci_inquiry_response_with_rssi *) (*b);
printf("\n btaddr: %s \tRSSI: %d \n", hci_bdaddr2str(&ir->bdaddr), ir->rssi);
} /* end hci_inquiry_response_with_rssi
Hope you opinions.
Maksim Yevmenkin wrote:
> Carlos Fernández Herranz wrote:
>
>> The problem was in my Bluetooth adapter, D-LINK DBT-122 which are
>> said to support Bluetooth 1.2 but it's not true.
>>
>> Now, I've tried with some Conceptronic BT 2.0 and it works well. I've
>> given support for the commands from Bluetooth 1.2:
>>
>> Write_Inquiry_Mode
>> Read_Inquiry_Mode
>>
>> and the reception of Inquiry results with RSSI.
>>
>> I'd like to collaborate providing the solutions I've found. How can I
>> do it? Posting my code in this list or sending it to Maksim?
>
>
> posting patches here for everyone to try/review would be a good start.
> i will be happy to commit them for you (after appropriate testing of
> course).
>
> thanks,
> max
>
Maksim Yevmenkin wrote:
> Carlos Fernández Herranz wrote:
>
>> The problem was in my Bluetooth adapter, D-LINK DBT-122 which are
>> said to support Bluetooth 1.2 but it's not true.
>>
>> Now, I've tried with some Conceptronic BT 2.0 and it works well. I've
>> given support for the commands from Bluetooth 1.2:
>>
>> Write_Inquiry_Mode
>> Read_Inquiry_Mode
>>
>> and the reception of Inquiry results with RSSI.
>>
>> I'd like to collaborate providing the solutions I've found. How can I
>> do it? Posting my code in this list or sending it to Maksim?
>
>
> posting patches here for everyone to try/review would be a good start.
> i will be happy to commit them for you (after appropriate testing of
> course).
>
> thanks,
> max
>
More information about the freebsd-bluetooth
mailing list