小弟刚接触这些东西,各位前辈帮忙看看,谢谢!
linux蓝牙的l2cap层编程,bind()提示Invalid argument,贴了一部分代码,我是交叉编译后在飞思卡尔的imx6上用,编译通过,在板子上运行后提示Invalid argument
int main(int argc, char** argv)
{
int iRel = 0;
int sk = 0;
struct sockaddr_l2 local_addr;
struct sockaddr_l2 remote_addr;
int len;
int nsk = 0;
pthread_t nth = 0;
struct l2cap_options opts;
int optlen = 0;
int slen = 0;
char str[16] = {0};
if(argc < 2)
{
printf("/nUsage:%s psm/n", argv[0]);
exit(0);
}
// create l2cap socket
sk = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP); //发送数据,使用SOCK_SEQPACKET为好
if(sk < 0)
{
perror("/nsocket():");
exit(0);
}
//bind
local_addr.l2_family = PF_BLUETOOTH;//31
local_addr.l2_psm = htobs(atoi(argv[argc -1])); //last psm,转换主机字节序到bluetooth字节序
bacpy(&local_addr.l2_bdaddr, BDADDR_ANY);//内存拷贝<-
iRel = bind(sk, (struct sockaddr *)&local_addr, sizeof(struct sockaddr));
if(iRel < 0)
{
perror("/nbind()");
exit(0);
}
//get opts
// in mtu 和 out mtu.每个包的最大值
memset(&opts, 0, sizeof(opts));
optlen = sizeof(opts);
getsockopt(sk, SOL_L2CAP, L2CAP_OPTIONS, &opts, &optlen);//得到套接口选项
。。。。。
可能是linux内核里面对应的蓝牙协议没有编译进去,,,需要配置一下menuconfig