ios - L2CAP IOS + Linux (Bluez)
<p><p>我正在尝试在 IOS 和 Linux PC 之间进行简单的 L2CAP Socket 通信。</p>
<p>我已经能够:</p>
<ul>
<li>在两台 Linux 机器之间创建 L2CAP 连接(使用 <a href="https://github.com/atwilc3000/sample/tree/master/Bluetooth" rel="noreferrer noopener nofollow">https://github.com/atwilc3000/sample/tree/master/Bluetooth</a> 中的示例代码)</li>
<li>在两部 Iphone 之间创建 L2CAP 连接(使用 <a href="https://github.com/github-deden/iOS_L2Cap" rel="noreferrer noopener nofollow">https://github.com/github-deden/iOS_L2Cap</a> 中的示例代码)</li>
</ul>
<p>在那个 IOS 示例中,他们使用一些 PSM 广告来为 L2CAPchannel 选择正确的 PSM。在集成上,我在两边都设置了一个固定的 PSM。 Iphone 正在连接到 Linux 机器固定 PSM。我已经尝试了多个 PSM (0x1001, 0x25)。</p>
<p>问题是,我无法连接,也无法获得有关广播中正在发生的事情的任何信息。</p>
<p>我的问题是,我是否需要在 Linux 应用程序上实现动态/广告 PSM?我需要选择特定的 PSM 吗?你能完成这项工作吗?你有什么建议吗?</p>
<p>提前致谢!</p>
<p>服务器代码:</p>
<pre><code>#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/l2cap.h>
#include "l2cap_socket.h"
int main(int argc, char **argv)
{
struct sockaddr_l2 loc_addr = { 0 }, rem_addr = { 0 };
char buf = { 0 };
int server_socket, client_socket, bytes_read;
unsigned int opt = sizeof(rem_addr);
printf("Start Bluetooth L2CAP server...\n");
/* allocate socket */
server_socket = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP);
/* bind socket to the local bluetooth adapter */
loc_addr.l2_family = AF_BLUETOOTH; /* Addressing family, always AF_BLUETOOTH */
bacpy(&loc_addr.l2_bdaddr, BDADDR_ANY); /* Bluetooth address of local bluetooth adapter */
loc_addr.l2_psm = htobs(L2CAP_SERVER_PORT_NUM); /* port number of local bluetooth adapter */
printf("binding\n");
if(bind(server_socket, (struct sockaddr *)&loc_addr, sizeof(loc_addr)) < 0) {
perror("failed to bind");
exit(1);
}
printf("listening\n");
/* put socket into listening mode */
listen(server_socket, 1);
/* accept one connection */
client_socket = accept(server_socket, (struct sockaddr *)&rem_addr, &opt);/* return new socket for connection with a client */
ba2str( &rem_addr.l2_bdaddr, buf );
printf("connected from %s\n", buf);
/* read data from the client */
memset(buf, 0, sizeof(buf));
bytes_read = recv(client_socket, buf, sizeof(buf), 0);
if( bytes_read > 0 ) {
printf("received [%s]\n", buf);
}
/* close connection */
close(client_socket);
close(server_socket);
return 0;
}
</code></pre>
<p>客户端基于(来自 <a href="https://github.com/bluekitchen/CBL2CAPChannel-Demo" rel="noreferrer noopener nofollow">https://github.com/bluekitchen/CBL2CAPChannel-Demo</a>)。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我现在有一个基于 <a href="https://github.com/bluekitchen/btstack" rel="noreferrer noopener nofollow">https://github.com/bluekitchen/btstack</a> 的工作版本</p>
<p>在 iOS 端我一直在使用 <a href="https://github.com/bluekitchen/CBL2CAPChannel-Demo" rel="noreferrer noopener nofollow">https://github.com/bluekitchen/CBL2CAPChannel-Demo</a>
服务器端<a href="https://github.com/bluekitchen/btstack/blob/master/example/le_data_channel_server.c" rel="noreferrer noopener nofollow">le_data_channel_server</a> .</p></p>
<p style="font-size: 20px;">关于ios - L2CAP IOS + Linux (Bluez),我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/55608145/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/55608145/
</a>
</p>
页:
[1]