18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci BNEP protocol definition for Linux Bluetooth stack (BlueZ). 48c2ecf20Sopenharmony_ci Copyright (C) 2002 Maxim Krasnyansky <maxk@qualcomm.com> 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci*/ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#ifndef _BNEP_H 98c2ecf20Sopenharmony_ci#define _BNEP_H 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include <linux/types.h> 128c2ecf20Sopenharmony_ci#include <linux/crc32.h> 138c2ecf20Sopenharmony_ci#include <net/bluetooth/bluetooth.h> 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci/* Limits */ 168c2ecf20Sopenharmony_ci#define BNEP_MAX_PROTO_FILTERS 5 178c2ecf20Sopenharmony_ci#define BNEP_MAX_MULTICAST_FILTERS 20 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci/* UUIDs */ 208c2ecf20Sopenharmony_ci#define BNEP_BASE_UUID 0x0000000000001000800000805F9B34FB 218c2ecf20Sopenharmony_ci#define BNEP_UUID16 0x02 228c2ecf20Sopenharmony_ci#define BNEP_UUID32 0x04 238c2ecf20Sopenharmony_ci#define BNEP_UUID128 0x16 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci#define BNEP_SVC_PANU 0x1115 268c2ecf20Sopenharmony_ci#define BNEP_SVC_NAP 0x1116 278c2ecf20Sopenharmony_ci#define BNEP_SVC_GN 0x1117 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci/* Packet types */ 308c2ecf20Sopenharmony_ci#define BNEP_GENERAL 0x00 318c2ecf20Sopenharmony_ci#define BNEP_CONTROL 0x01 328c2ecf20Sopenharmony_ci#define BNEP_COMPRESSED 0x02 338c2ecf20Sopenharmony_ci#define BNEP_COMPRESSED_SRC_ONLY 0x03 348c2ecf20Sopenharmony_ci#define BNEP_COMPRESSED_DST_ONLY 0x04 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci/* Control types */ 378c2ecf20Sopenharmony_ci#define BNEP_CMD_NOT_UNDERSTOOD 0x00 388c2ecf20Sopenharmony_ci#define BNEP_SETUP_CONN_REQ 0x01 398c2ecf20Sopenharmony_ci#define BNEP_SETUP_CONN_RSP 0x02 408c2ecf20Sopenharmony_ci#define BNEP_FILTER_NET_TYPE_SET 0x03 418c2ecf20Sopenharmony_ci#define BNEP_FILTER_NET_TYPE_RSP 0x04 428c2ecf20Sopenharmony_ci#define BNEP_FILTER_MULTI_ADDR_SET 0x05 438c2ecf20Sopenharmony_ci#define BNEP_FILTER_MULTI_ADDR_RSP 0x06 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci/* Extension types */ 468c2ecf20Sopenharmony_ci#define BNEP_EXT_CONTROL 0x00 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci/* Response messages */ 498c2ecf20Sopenharmony_ci#define BNEP_SUCCESS 0x00 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci#define BNEP_CONN_INVALID_DST 0x01 528c2ecf20Sopenharmony_ci#define BNEP_CONN_INVALID_SRC 0x02 538c2ecf20Sopenharmony_ci#define BNEP_CONN_INVALID_SVC 0x03 548c2ecf20Sopenharmony_ci#define BNEP_CONN_NOT_ALLOWED 0x04 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci#define BNEP_FILTER_UNSUPPORTED_REQ 0x01 578c2ecf20Sopenharmony_ci#define BNEP_FILTER_INVALID_RANGE 0x02 588c2ecf20Sopenharmony_ci#define BNEP_FILTER_INVALID_MCADDR 0x02 598c2ecf20Sopenharmony_ci#define BNEP_FILTER_LIMIT_REACHED 0x03 608c2ecf20Sopenharmony_ci#define BNEP_FILTER_DENIED_SECURITY 0x04 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci/* L2CAP settings */ 638c2ecf20Sopenharmony_ci#define BNEP_MTU 1691 648c2ecf20Sopenharmony_ci#define BNEP_PSM 0x0f 658c2ecf20Sopenharmony_ci#define BNEP_FLUSH_TO 0xffff 668c2ecf20Sopenharmony_ci#define BNEP_CONNECT_TO 15 678c2ecf20Sopenharmony_ci#define BNEP_FILTER_TO 15 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci/* Headers */ 708c2ecf20Sopenharmony_ci#define BNEP_TYPE_MASK 0x7f 718c2ecf20Sopenharmony_ci#define BNEP_EXT_HEADER 0x80 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_cistruct bnep_setup_conn_req { 748c2ecf20Sopenharmony_ci __u8 type; 758c2ecf20Sopenharmony_ci __u8 ctrl; 768c2ecf20Sopenharmony_ci __u8 uuid_size; 778c2ecf20Sopenharmony_ci __u8 service[]; 788c2ecf20Sopenharmony_ci} __packed; 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_cistruct bnep_set_filter_req { 818c2ecf20Sopenharmony_ci __u8 type; 828c2ecf20Sopenharmony_ci __u8 ctrl; 838c2ecf20Sopenharmony_ci __be16 len; 848c2ecf20Sopenharmony_ci __u8 list[]; 858c2ecf20Sopenharmony_ci} __packed; 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_cistruct bnep_control_rsp { 888c2ecf20Sopenharmony_ci __u8 type; 898c2ecf20Sopenharmony_ci __u8 ctrl; 908c2ecf20Sopenharmony_ci __be16 resp; 918c2ecf20Sopenharmony_ci} __packed; 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_cistruct bnep_ext_hdr { 948c2ecf20Sopenharmony_ci __u8 type; 958c2ecf20Sopenharmony_ci __u8 len; 968c2ecf20Sopenharmony_ci __u8 data[]; 978c2ecf20Sopenharmony_ci} __packed; 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci/* BNEP ioctl defines */ 1008c2ecf20Sopenharmony_ci#define BNEPCONNADD _IOW('B', 200, int) 1018c2ecf20Sopenharmony_ci#define BNEPCONNDEL _IOW('B', 201, int) 1028c2ecf20Sopenharmony_ci#define BNEPGETCONNLIST _IOR('B', 210, int) 1038c2ecf20Sopenharmony_ci#define BNEPGETCONNINFO _IOR('B', 211, int) 1048c2ecf20Sopenharmony_ci#define BNEPGETSUPPFEAT _IOR('B', 212, int) 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci#define BNEP_SETUP_RESPONSE 0 1078c2ecf20Sopenharmony_ci#define BNEP_SETUP_RSP_SENT 10 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_cistruct bnep_connadd_req { 1108c2ecf20Sopenharmony_ci int sock; /* Connected socket */ 1118c2ecf20Sopenharmony_ci __u32 flags; 1128c2ecf20Sopenharmony_ci __u16 role; 1138c2ecf20Sopenharmony_ci char device[16]; /* Name of the Ethernet device */ 1148c2ecf20Sopenharmony_ci}; 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_cistruct bnep_conndel_req { 1178c2ecf20Sopenharmony_ci __u32 flags; 1188c2ecf20Sopenharmony_ci __u8 dst[ETH_ALEN]; 1198c2ecf20Sopenharmony_ci}; 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_cistruct bnep_conninfo { 1228c2ecf20Sopenharmony_ci __u32 flags; 1238c2ecf20Sopenharmony_ci __u16 role; 1248c2ecf20Sopenharmony_ci __u16 state; 1258c2ecf20Sopenharmony_ci __u8 dst[ETH_ALEN]; 1268c2ecf20Sopenharmony_ci char device[16]; 1278c2ecf20Sopenharmony_ci}; 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_cistruct bnep_connlist_req { 1308c2ecf20Sopenharmony_ci __u32 cnum; 1318c2ecf20Sopenharmony_ci struct bnep_conninfo __user *ci; 1328c2ecf20Sopenharmony_ci}; 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_cistruct bnep_proto_filter { 1358c2ecf20Sopenharmony_ci __u16 start; 1368c2ecf20Sopenharmony_ci __u16 end; 1378c2ecf20Sopenharmony_ci}; 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ciint bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock); 1408c2ecf20Sopenharmony_ciint bnep_del_connection(struct bnep_conndel_req *req); 1418c2ecf20Sopenharmony_ciint bnep_get_connlist(struct bnep_connlist_req *req); 1428c2ecf20Sopenharmony_ciint bnep_get_conninfo(struct bnep_conninfo *ci); 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci/* BNEP sessions */ 1458c2ecf20Sopenharmony_cistruct bnep_session { 1468c2ecf20Sopenharmony_ci struct list_head list; 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci unsigned int role; 1498c2ecf20Sopenharmony_ci unsigned long state; 1508c2ecf20Sopenharmony_ci unsigned long flags; 1518c2ecf20Sopenharmony_ci atomic_t terminate; 1528c2ecf20Sopenharmony_ci struct task_struct *task; 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_ci struct ethhdr eh; 1558c2ecf20Sopenharmony_ci struct msghdr msg; 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci struct bnep_proto_filter proto_filter[BNEP_MAX_PROTO_FILTERS]; 1588c2ecf20Sopenharmony_ci unsigned long long mc_filter; 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci struct socket *sock; 1618c2ecf20Sopenharmony_ci struct net_device *dev; 1628c2ecf20Sopenharmony_ci}; 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_civoid bnep_net_setup(struct net_device *dev); 1658c2ecf20Sopenharmony_ciint bnep_sock_init(void); 1668c2ecf20Sopenharmony_civoid bnep_sock_cleanup(void); 1678c2ecf20Sopenharmony_ci 1688c2ecf20Sopenharmony_cistatic inline int bnep_mc_hash(__u8 *addr) 1698c2ecf20Sopenharmony_ci{ 1708c2ecf20Sopenharmony_ci return crc32_be(~0, addr, ETH_ALEN) >> 26; 1718c2ecf20Sopenharmony_ci} 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ci#endif 174