Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 24 Apr 2006 11:34:50 +0200
From:      =?ISO-8859-1?Q?Carlos_Fern=E1ndez_Herranz?= <cfernandezh@udc.es>
To:        Maksim Yevmenkin <maksim.yevmenkin@savvis.net>
Cc:        freebsd-bluetooth@freebsd.org
Subject:   Re: About Inquiry_with_RSSI
Message-ID:  <444C9BBA.4010206@udc.es>
In-Reply-To: <4447BB29.906@savvis.net>
References:  <4423D096.2010205@udc.es> <44248823.3040907@savvis.net> <44291782.8010003@udc.es> <1143546159.980113.1641.nullmailer@galant.ukfsn.org> <44292470.5020803@udc.es> <1143547703.630752.2338.nullmailer@galant.ukfsn.org> <44294D1D.4010901@udc.es> <1143558548.478651.3242.nullmailer@galant.ukfsn.org> <4447A36C.8070201@udc.es> <4447BB29.906@savvis.net>

next in thread | previous in thread | raw e-mail | index | archive | help
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
>




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?444C9BBA.4010206>