2018-04-02 18:47:17 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* apps/wireless/bluetooth/btsak/btsak.h
|
|
|
|
*
|
2021-06-09 16:39:27 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2018-04-02 18:47:17 +02:00
|
|
|
*
|
2021-06-09 16:39:27 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2018-04-02 18:47:17 +02:00
|
|
|
*
|
2021-06-09 16:39:27 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2018-04-02 18:47:17 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-06-09 16:39:27 +02:00
|
|
|
/* Based loosely on the i8sak IEEE 802.15.4 program by Anthony Merlino and
|
|
|
|
* Sebastien Lorquet. Commands inspired from btshell example in the
|
|
|
|
* Intel/Zephyr Arduino 101 package (BSD license).
|
|
|
|
*/
|
|
|
|
|
2022-01-16 03:31:55 +01:00
|
|
|
#ifndef __APPS_WIRELESS_BLUETOOTH_BTSAK_BTSAK_H
|
|
|
|
#define __APPS_WIRELESS_BLUETOOTH_BTSAK_BTSAK_H
|
2018-04-02 18:47:17 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netpacket/bluetooth.h>
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#define BTSAK_MAX_IFNAME 12
|
|
|
|
#define BTSAK_DAEMONNAME_FMT "btsak_%s"
|
|
|
|
#define BTSAK_DAEMONNAME_PREFIX_LEN 6
|
|
|
|
#define BTSAK_MAX_DAEMONNAME BTSAK_DAEMONNAME_PREFIX_LEN + BTSAK_MAX_IFNAME
|
|
|
|
#define BTSAK_DEFAULT_EPADDR {0x00, 0x11, 0x22, 0x33, 0x44, 0x55}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
struct btsak_s
|
|
|
|
{
|
|
|
|
FAR char *progname; /* Program name */
|
|
|
|
FAR char *ifname; /* Interface name */
|
|
|
|
bt_addr_t ep_btaddr; /* Blue tooth address */
|
|
|
|
#if defined(CONFIG_NET_BLUETOOTH)
|
2020-08-29 19:44:24 +02:00
|
|
|
struct sockaddr_l2 ep_sockaddr; /* AF_BLUETOOTH endpoint address */
|
2018-04-02 18:47:17 +02:00
|
|
|
#elif defined(CONFIG_NET_6LOWPAN)
|
|
|
|
struct sockaddr_in6 ep_sockaddr; /* IPv6 endpoint address */
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Inline Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_6LOWPAN
|
|
|
|
static inline void btsak_update_ipv6addr(FAR struct btsak_s *btsak)
|
|
|
|
{ dev->d_ipv6addr[0] = HTONS(0xfe80);
|
|
|
|
dev->d_ipv6addr[1] = 0;
|
|
|
|
dev->d_ipv6addr[2] = 0;
|
|
|
|
dev->d_ipv6addr[3] = 0;
|
|
|
|
dev->d_ipv6addr[4] = HTONS(0x0200);
|
|
|
|
dev->d_ipv6addr[5] = (uint16_t)addr[0] << 8 | (uint16_t)addr[1];
|
|
|
|
dev->d_ipv6addr[6] = (uint16_t)addr[2] << 8 | (uint16_t)addr[3];
|
|
|
|
dev->d_ipv6addr[7] = (uint16_t)addr[4] << 8 | (uint16_t)addr[5];
|
|
|
|
|
|
|
|
btsak->ep_in6addr.sin6_addr.in6_u.u6_addr16[0] = HTONS(0xfe80);
|
|
|
|
btsak->ep_in6addr.sin6_addr.in6_u.u6_addr16[1] = 0;
|
|
|
|
btsak->ep_in6addr.sin6_addr.in6_u.u6_addr16[2] = 0;
|
|
|
|
btsak->ep_in6addr.sin6_addr.in6_u.u6_addr16[3] = 0;
|
|
|
|
btsak->ep_in6addr.sin6_addr.in6_u.u6_addr16[4] = HTONS(0x0200);
|
|
|
|
btsak->ep_in6addr.sin6_addr.in6_u.u6_addr16[5] =
|
2020-08-29 21:39:56 +02:00
|
|
|
((uint16_t)btsak->ep_btaddr.val[0] << 8 |
|
|
|
|
(uint16_t)btsak->ep_btaddr.val[1]);
|
2018-04-02 18:47:17 +02:00
|
|
|
btsak->ep_in6addr.sin6_addr.in6_u.u6_addr16[6] =
|
2020-08-29 21:39:56 +02:00
|
|
|
((uint16_t)btsak->ep_btaddr.val[2] << 8 |
|
|
|
|
(uint16_t)btsak->ep_btaddr.val[3]);
|
2018-04-02 18:47:17 +02:00
|
|
|
btsak->ep_in6addr.sin6_addr.in6_u.u6_addr16[7] =
|
2020-08-29 21:39:56 +02:00
|
|
|
((uint16_t)btsak->ep_btaddr.val[4] << 8 |
|
|
|
|
(uint16_t)btsak->ep_btaddr.val[5]);
|
2018-04-02 18:47:17 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: btsak_char2nibble
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Convert an hexadecimal character to a 4-bit nibble.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-04-03 01:40:41 +02:00
|
|
|
int btsak_char2nibble(char ch);
|
2018-04-02 18:47:17 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: btsak_str2long
|
|
|
|
*
|
|
|
|
* Description:
|
2018-04-21 17:45:50 +02:00
|
|
|
* Convert a numeric string to an long value
|
2018-04-02 18:47:17 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
long btsak_str2long(FAR const char *str);
|
|
|
|
|
|
|
|
/****************************************************************************
|
2018-04-21 17:45:50 +02:00
|
|
|
* Name: btsak_str2uint8
|
2018-04-02 18:47:17 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2018-04-21 17:45:50 +02:00
|
|
|
* Convert a numeric string to an uint8_t value
|
2018-04-02 18:47:17 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-04-21 17:45:50 +02:00
|
|
|
uint8_t btsak_str2uint8(FAR const char *str);
|
2018-04-02 18:47:17 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
2018-04-19 21:02:20 +02:00
|
|
|
* Name: btsak_str2uint16
|
2018-04-02 18:47:17 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2018-04-21 17:45:50 +02:00
|
|
|
* Convert a numeric string to an uint16_t value
|
2018-04-02 18:47:17 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-04-19 21:02:20 +02:00
|
|
|
uint16_t btsak_str2uint16(FAR const char *str);
|
2018-04-02 18:47:17 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: btsak_str2bool
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Convert a boolean name to a boolean value.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
bool btsak_str2bool(FAR const char *str);
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name : btsak_str2payload
|
|
|
|
*
|
|
|
|
* Description :
|
|
|
|
* Parse string to get buffer of data. Buf is expected to be of size
|
|
|
|
* BLUETOOTH_SMP_MTU or larger.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* Positive length value of frame payload
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int btsak_str2payload(FAR const char *str, FAR uint8_t *buf);
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: btsak_str2addr
|
|
|
|
*
|
|
|
|
* Description:
|
2018-04-03 01:40:41 +02:00
|
|
|
* Convert a string of the form "xx:xx:xx:xx:xx:xx" 6-byte Bluetooth
|
|
|
|
* address (where xx is a one or two character hexadecimal number sub-
|
|
|
|
* string)
|
2018-04-02 18:47:17 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-04-03 01:40:41 +02:00
|
|
|
int btsak_str2addr(FAR const char *str, FAR uint8_t *addr);
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: btsak_str2addrtype
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Convert a string to an address type. String options are "public" or
|
|
|
|
* "private".
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int btsak_str2addrtype(FAR const char *str, FAR uint8_t *addrtype);
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: btsak_str2seclevel
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Convert a string to a security level. String options are "low",
|
|
|
|
* "medium", "high", or "fips"
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int btsak_str2seclevel(FAR const char *str, FAR enum bt_security_e *level);
|
2018-04-02 18:47:17 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: btsak_socket
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Create a socket on the selected device.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int btsak_socket(FAR struct btsak_s *btsak);
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: btsak_showusage
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Show program usage.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void btsak_showusage(FAR const char *progname, int exitcode);
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: btsak_gatt_showusage
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Show gatt command usage.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void btsak_gatt_showusage(FAR const char *progname, FAR const char *cmd,
|
|
|
|
int exitcode);
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Command handlers
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-04-06 18:40:35 +02:00
|
|
|
void btsak_cmd_info(FAR struct btsak_s *btsak, int argc, FAR char *argv[]);
|
2018-04-07 00:24:05 +02:00
|
|
|
void btsak_cmd_features(FAR struct btsak_s *btsak, int argc,
|
|
|
|
FAR char *argv[]);
|
2018-04-02 18:47:17 +02:00
|
|
|
void btsak_cmd_scan(FAR struct btsak_s *btsak, int argc, FAR char *argv[]);
|
|
|
|
void btsak_cmd_advertise(FAR struct btsak_s *btsak, int argc,
|
|
|
|
FAR char *argv[]);
|
|
|
|
void btsak_cmd_security(FAR struct btsak_s *btsak, int argc,
|
|
|
|
FAR char *argv[]);
|
|
|
|
void btsak_cmd_gatt_exchange_mtu(FAR struct btsak_s *btsak, int argc,
|
|
|
|
FAR char *argv[]);
|
2018-12-02 18:01:28 +01:00
|
|
|
void btsak_cmd_connect(FAR struct btsak_s *btsak, int argc,
|
|
|
|
FAR char *argv[]);
|
|
|
|
void btsak_cmd_disconnect(FAR struct btsak_s *btsak, int argc,
|
|
|
|
FAR char *argv[]);
|
2018-04-02 18:47:17 +02:00
|
|
|
void btsak_cmd_discover(FAR struct btsak_s *btsak, int argc,
|
|
|
|
FAR char *argv[]);
|
2018-04-03 16:16:34 +02:00
|
|
|
void btsak_cmd_gatt_discover_characteristic(FAR struct btsak_s *btsak,
|
2018-04-02 18:47:17 +02:00
|
|
|
int argc, FAR char *argv[]);
|
2018-04-21 18:23:02 +02:00
|
|
|
void btsak_cmd_gatt_discover_descriptor(FAR struct btsak_s *btsak,
|
2018-04-02 18:47:17 +02:00
|
|
|
int argc, FAR char *argv[]);
|
|
|
|
void btsak_cmd_gatt_read(FAR struct btsak_s *btsak, int argc,
|
|
|
|
FAR char *argv[]);
|
|
|
|
void btsak_cmd_gatt_read_multiple(FAR struct btsak_s *btsak, int argc,
|
|
|
|
FAR char *argv[]);
|
|
|
|
void btsak_cmd_gatt_write(FAR struct btsak_s *btsak, int argc,
|
|
|
|
FAR char *argv[]);
|
|
|
|
|
2022-01-16 03:31:55 +01:00
|
|
|
#endif /* __APPS_WIRELESS_BLUETOOTH_BTSAK_BTSAK_H */
|