@@ -46,9 +46,16 @@ static struct k_thread rx_thread_data;
46
46
static unsigned short bt_dev_index ;
47
47
48
48
#define TCP_ADDR_BUFF_SIZE 16
49
- static bool hci_socket ;
49
+ #define UNIX_ADDR_BUFF_SIZE 4096
50
+ enum hci_connection_type {
51
+ HCI_USERCHAN ,
52
+ HCI_TCP ,
53
+ HCI_UNIX ,
54
+ };
55
+ static enum hci_connection_type conn_type ;
50
56
static char ip_addr [TCP_ADDR_BUFF_SIZE ];
51
57
static unsigned int port ;
58
+ static char socket_path [UNIX_ADDR_BUFF_SIZE ];
52
59
static bool arg_found ;
53
60
54
61
static struct net_buf * get_rx (const uint8_t * buf )
@@ -286,16 +293,19 @@ static int uc_open(const struct device *dev, bt_hci_recv_t recv)
286
293
{
287
294
struct uc_data * uc = dev -> data ;
288
295
289
- if (hci_socket ) {
296
+ switch (conn_type ) {
297
+ case HCI_USERCHAN :
290
298
LOG_DBG ("hci%d" , bt_dev_index );
291
- } else {
292
- LOG_DBG ("hci %s:%d" , ip_addr , port );
293
- }
294
-
295
- if (hci_socket ) {
296
299
uc -> fd = user_chan_socket_open (bt_dev_index );
297
- } else {
300
+ break ;
301
+ case HCI_TCP :
302
+ LOG_DBG ("hci %s:%d" , ip_addr , port );
298
303
uc -> fd = user_chan_net_connect (ip_addr , port );
304
+ break ;
305
+ case HCI_UNIX :
306
+ LOG_DBG ("hci socket %s" , socket_path );
307
+ uc -> fd = user_chan_unix_connect (socket_path );
308
+ break ;
299
309
}
300
310
if (uc -> fd < 0 ) {
301
311
return - nsi_errno_from_mid (- uc -> fd );
@@ -325,7 +335,8 @@ static int uc_init(const struct device *dev)
325
335
{
326
336
if (!arg_found ) {
327
337
posix_print_warning ("Warning: Bluetooth device missing.\n"
328
- "Specify either a local hci interface --bt-dev=hciN\n"
338
+ "Specify either a local hci interface --bt-dev=hciN,\n"
339
+ "a UNIX socket --bt-dev=/tmp/bt-server-bredrle\n"
329
340
"or a valid hci tcp server --bt-dev=ip_address:port\n" );
330
341
return - ENODEV ;
331
342
}
@@ -350,7 +361,7 @@ static void cmd_bt_dev_found(char *argv, int offset)
350
361
351
362
if (arg_hci_idx >= 0 && arg_hci_idx <= USHRT_MAX ) {
352
363
bt_dev_index = arg_hci_idx ;
353
- hci_socket = true ;
364
+ conn_type = HCI_USERCHAN ;
354
365
} else {
355
366
posix_print_error_and_exit ("Invalid argument value for --bt-dev. "
356
367
"hci idx must be within range 0 to 65536.\n" );
@@ -365,9 +376,14 @@ static void cmd_bt_dev_found(char *argv, int offset)
365
376
posix_print_error_and_exit ("Error: IP address for bluetooth "
366
377
"hci tcp server is incorrect.\n" );
367
378
}
379
+
380
+ conn_type = HCI_TCP ;
381
+ } else if (strlen (& argv [offset ]) > 0 && argv [offset ] == '/' ) {
382
+ strncpy (socket_path , & argv [offset ], UNIX_ADDR_BUFF_SIZE - 1 );
383
+ conn_type = HCI_UNIX ;
368
384
} else {
369
385
posix_print_error_and_exit ("Invalid option %s for --bt-dev. "
370
- "An hci interface or hci tcp server is expected.\n" ,
386
+ "An hci interface, absolute UNIX socket path or hci tcp server is expected.\n" ,
371
387
& argv [offset ]);
372
388
}
373
389
}
@@ -385,7 +401,8 @@ static void add_btuserchan_arg(void)
385
401
{ false, true, false,
386
402
"bt-dev" , "hciX" , 's' ,
387
403
NULL , cmd_bt_dev_found ,
388
- "A local HCI device to be used for Bluetooth (e.g. hci0) "
404
+ "A local HCI device to be used for Bluetooth (e.g. hci0), "
405
+ "UNIX socket (absolute path, like /tmp/bt-server-bredrle) "
389
406
"or an HCI TCP Server (e.g. 127.0.0.1:9000)" },
390
407
ARG_TABLE_ENDMARKER
391
408
};
0 commit comments