[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bluetooth-dev] Inquiry command
I would like to expand the capabilities of the inquiry facility. This
will make it easier to make front ends for the stack.
Here are the changes I propose:
1) We need to save the results of the inquiry command inside the stack.
Here is a struct for that (put in btcommon.h)
typedef struct inquiry_rsp_struct
{
int id; /* For now the same as the index in the response array */
unsigned char bd_addr[6];
unsigned int psrm, pspm, psm;
unsigned char cod[3];
unsigned char offset[2];
int valid;
} inquiry_rsp_struct;
2) And make a global array of these in hci.c:
#define MAX_INQUIRY_RESPONSES 50
inquiry_rsp_struct inquiry_rsp[MAX_INQUIRY_RESPONSES];
3) Expand the code for inquiry responses to handle all the info returned:
case INQUIRY_RESULT:
{
s32 i, j;
u8 tmp_bd[6];
D_REC(FNC"INQUIRY_RESULT\n");
if (len != (buf[0] * 14 + 1)){
D_REC(FNC"INQUIRY_RESULT packet wrong size!\n");
break;
}
if (buf[0] > MAX_INQUIRY_RESPONSES){
D_REC(FNC"INQUIRY_RESULT too many responses\n");
break;
}
for (i = 0; i <MAX_INQUIRY_RESPONSES; i++){
inquiry_rsp[i].valid=0;
}
for(i = 1; i < (buf[0] * 14) + 1; i += 14) {
printk("BD addr %d\n", i % 14);
for (j = 0; j < 6; j++) {
tmp_bd[5-j] = buf[i + j];
}
print_data("BD",tmp_bd, 6);
memcpy(inquiry_rsp[i-1].bd_addr, tmp_bd, 6);
inquiry_rsp[i-1].id=i-1;
inquiry_rsp[i-1].valid=1;
inquiry_rsp[i-1].psrm=buf[i+6];
inquiry_rsp[i-1].pspm=buf[i+7];
inquiry_rsp[i-1].psm=buf[i+8];
memcpy(inquiry_rsp[i-1].cod, buf+i+9, 3);
memcpy(inquiry_rsp[i-1].offset, buf+i+12, 2);
}
break;
}
4) Provide a minimal facility for searching for a response in hci.c:
inquiry_rsp_struct*
get_inquiry_rsp(inquiry_rsp_struct* response)
{
if (response->id > MAX_INQUIRY_RESPONSES)
return NULL;
if (!inquiry_rsp[response->id].valid)
return NULL;
return(&inquiry_rsp[response->id]);
}
5) Add two ioctl's to bluetooth.c to start and search for responses:
case BTINQUIRYSCAN:
BT_DRIVER("starting inquiry scan\n");
if (size != 5){
BT_DRIVER("incorrect inquiry scan parameter
size\n");
break;
}
copy_from_user(&lap, (u8*)arg, 3);
copy_from_user(&inq_len, (u8*)(arg + 3), 1);
copy_from_user(&num_resp, (u8*)(arg + 4), 1);
hci_inquiry(lap, inq_len, num_resp);
break;
case BTGETINQUIRYRESULT:
BT_DRIVER("retreving inquiry result\n");
response_in = kmalloc(sizeof(inquiry_rsp_struct), GFP_KERNEL);
copy_from_user(response_in, (inquiry_rsp_struct*)arg,
sizeof(inquiry_rsp_struct));
response_out = get_inquiry_rsp(response_in);
kfree(response_in);
if (response_out != NULL)
copy_to_user((inquiry_rsp_struct*) arg,
response_out,
sizeof(inquiry_rsp_struct));
else return -1;
break;
6) And the corresponding defines to btcommon.h:
#define BTINQUIRYSCAN _IOW(BT_IOC_MAGIC, 0x12, u8[5])
#define BTGETINQUIRYRESULT _IOR(BT_IOC_MAGIC, 0x12, inquiry_rsp_struct)
Sound good?
----
Mark Douglas Corner
mcorner@xxxxxxx.edu