30 */ 31 32#include <sys/param.h> 33#include <sys/systm.h> 34#include <sys/bitstring.h> 35#include <sys/errno.h> 36#include <sys/domain.h> 37#include <sys/kernel.h> 38#include <sys/lock.h> 39#include <sys/mbuf.h> 40#include <sys/mutex.h> 41#include <sys/protosw.h> 42#include <sys/socket.h> 43#include <sys/socketvar.h> 44#include <sys/sysctl.h> 45#include <sys/taskqueue.h> 46#include <netgraph/ng_message.h> 47#include <netgraph/netgraph.h> 48#include <netgraph/bluetooth/include/ng_bluetooth.h> 49#include <netgraph/bluetooth/include/ng_hci.h> 50#include <netgraph/bluetooth/include/ng_l2cap.h> 51#include <netgraph/bluetooth/include/ng_btsocket.h> 52#include <netgraph/bluetooth/include/ng_btsocket_hci_raw.h> 53#include <netgraph/bluetooth/include/ng_btsocket_l2cap.h> 54#include <netgraph/bluetooth/include/ng_btsocket_rfcomm.h> 55 56static int ng_btsocket_modevent (module_t, int, void *); 57extern struct domain ng_btsocket_domain; 58 59/* 60 * Bluetooth raw HCI sockets 61 */ 62 63static struct pr_usrreqs ng_btsocket_hci_raw_usrreqs = { 64 .pru_abort = ng_btsocket_hci_raw_abort, 65 .pru_attach = ng_btsocket_hci_raw_attach, 66 .pru_bind = ng_btsocket_hci_raw_bind, 67 .pru_connect = ng_btsocket_hci_raw_connect, 68 .pru_control = ng_btsocket_hci_raw_control, 69 .pru_detach = ng_btsocket_hci_raw_detach, 70 .pru_disconnect = ng_btsocket_hci_raw_disconnect, 71 .pru_peeraddr = ng_btsocket_hci_raw_peeraddr, 72 .pru_send = ng_btsocket_hci_raw_send, 73 .pru_shutdown = NULL, 74 .pru_sockaddr = ng_btsocket_hci_raw_sockaddr, 75}; 76 77/* 78 * Bluetooth raw L2CAP sockets 79 */ 80 81static struct pr_usrreqs ng_btsocket_l2cap_raw_usrreqs = { 82 .pru_abort = ng_btsocket_l2cap_raw_abort, 83 .pru_attach = ng_btsocket_l2cap_raw_attach, 84 .pru_bind = ng_btsocket_l2cap_raw_bind, 85 .pru_connect = ng_btsocket_l2cap_raw_connect, 86 .pru_control = ng_btsocket_l2cap_raw_control, 87 .pru_detach = ng_btsocket_l2cap_raw_detach, 88 .pru_disconnect = ng_btsocket_l2cap_raw_disconnect, 89 .pru_peeraddr = ng_btsocket_l2cap_raw_peeraddr, 90 .pru_send = ng_btsocket_l2cap_raw_send, 91 .pru_shutdown = NULL, 92 .pru_sockaddr = ng_btsocket_l2cap_raw_sockaddr, 93}; 94 95/* 96 * Bluetooth SEQPACKET L2CAP sockets 97 */ 98 99static struct pr_usrreqs ng_btsocket_l2cap_usrreqs = { 100 .pru_abort = ng_btsocket_l2cap_abort, 101 .pru_accept = ng_btsocket_l2cap_accept, 102 .pru_attach = ng_btsocket_l2cap_attach, 103 .pru_bind = ng_btsocket_l2cap_bind, 104 .pru_connect = ng_btsocket_l2cap_connect, 105 .pru_control = ng_btsocket_l2cap_control, 106 .pru_detach = ng_btsocket_l2cap_detach, 107 .pru_disconnect = ng_btsocket_l2cap_disconnect, 108 .pru_listen = ng_btsocket_l2cap_listen, 109 .pru_peeraddr = ng_btsocket_l2cap_peeraddr, 110 .pru_send = ng_btsocket_l2cap_send, 111 .pru_shutdown = NULL, 112 .pru_sockaddr = ng_btsocket_l2cap_sockaddr, 113}; 114 115/* 116 * Bluetooth STREAM RFCOMM sockets 117 */ 118 119static struct pr_usrreqs ng_btsocket_rfcomm_usrreqs = { 120 .pru_abort = ng_btsocket_rfcomm_abort, 121 .pru_accept = ng_btsocket_rfcomm_accept, 122 .pru_attach = ng_btsocket_rfcomm_attach, 123 .pru_bind = ng_btsocket_rfcomm_bind, 124 .pru_connect = ng_btsocket_rfcomm_connect, 125 .pru_control = ng_btsocket_rfcomm_control, 126 .pru_detach = ng_btsocket_rfcomm_detach, 127 .pru_disconnect = ng_btsocket_rfcomm_disconnect, 128 .pru_listen = ng_btsocket_rfcomm_listen, 129 .pru_peeraddr = ng_btsocket_rfcomm_peeraddr, 130 .pru_send = ng_btsocket_rfcomm_send, 131 .pru_shutdown = NULL, 132 .pru_sockaddr = ng_btsocket_rfcomm_sockaddr, 133}; 134 135/* 136 * Definitions of protocols supported in the BLUETOOTH domain 137 */ 138 139static struct protosw ng_btsocket_protosw[] = { 140{ 141 SOCK_RAW, /* protocol type */ 142 &ng_btsocket_domain, /* backpointer to domain */ 143 BLUETOOTH_PROTO_HCI, /* protocol */ 144 PR_ATOMIC | PR_ADDR, /* flags */ 145 NULL, NULL, NULL, /* input, output, ctlinput */ 146 ng_btsocket_hci_raw_ctloutput, /* ctloutput */ 147 NULL, /* ousrreq() */ 148 ng_btsocket_hci_raw_init, /* init */ 149 NULL, NULL, NULL, /* fasttimeo, slowtimo, drain */ 150 &ng_btsocket_hci_raw_usrreqs, /* usrreq table (above) */ 151 /* { NULL } */ /* pfh (protocol filter head?) */ 152}, 153{ 154 SOCK_RAW, /* protocol type */ 155 &ng_btsocket_domain, /* backpointer to domain */ 156 BLUETOOTH_PROTO_L2CAP, /* protocol */ 157 PR_ATOMIC | PR_ADDR, /* flags */ 158 NULL, NULL, NULL, /* input, output, ctlinput */ 159 NULL, /* ctloutput */ 160 NULL, /* ousrreq() */ 161 ng_btsocket_l2cap_raw_init, /* init */ 162 NULL, NULL, NULL, /* fasttimeo, slowtimo, drain */ 163 &ng_btsocket_l2cap_raw_usrreqs, /* usrreq table (above) */ 164 /* { NULL } */ /* pfh (protocol filter head?) */ 165}, 166{ 167 SOCK_SEQPACKET, /* protocol type */ 168 &ng_btsocket_domain, /* backpointer to domain */ 169 BLUETOOTH_PROTO_L2CAP, /* protocol */ 170 PR_ATOMIC | PR_CONNREQUIRED, /* flags */ 171 NULL, NULL, NULL, /* input, output, ctlinput */ 172 ng_btsocket_l2cap_ctloutput, /* ctloutput */ 173 NULL, /* ousrreq() */ 174 ng_btsocket_l2cap_init, /* init */ 175 NULL, NULL, NULL, /* fasttimeo, slowtimo, drain */ 176 &ng_btsocket_l2cap_usrreqs, /* usrreq table (above) */ 177 /* { NULL } */ /* pfh (protocol filter head?) */ 178}, 179{ 180 SOCK_STREAM, /* protocol type */ 181 &ng_btsocket_domain, /* backpointer to domain */ 182 BLUETOOTH_PROTO_RFCOMM, /* protocol */ 183 PR_ATOMIC | PR_CONNREQUIRED, /* flags */ 184 NULL, NULL, NULL, /* input, output, ctlinput */ 185 ng_btsocket_rfcomm_ctloutput, /* ctloutput */ 186 NULL, /* ousrreq() */ 187 ng_btsocket_rfcomm_init, /* init */ 188 NULL, NULL, NULL, /* fasttimeo, slowtimo, drain */ 189 &ng_btsocket_rfcomm_usrreqs, /* usrreq table (above) */ 190 /* { NULL } */ /* pfh (protocol filter head?) */ 191} 192}; 193#define ng_btsocket_protosw_size \ 194 (sizeof(ng_btsocket_protosw)/sizeof(ng_btsocket_protosw[0])) 195#define ng_btsocket_protosw_end \ 196 &ng_btsocket_protosw[ng_btsocket_protosw_size] 197 198/* 199 * BLUETOOTH domain 200 */ 201 202struct domain ng_btsocket_domain = { 203 AF_BLUETOOTH, /* family */ 204 "bluetooth", /* domain name */ 205 NULL, /* init() */ 206 NULL, /* externalize() */ 207 NULL, /* dispose() */ 208 ng_btsocket_protosw, /* protosw entry */ 209 ng_btsocket_protosw_end, /* end of protosw entries */ 210 NULL, /* next domain in list */ 211 NULL, /* rtattach() */ 212 0, /* arg to rtattach in bits */ 213 0 /* maxrtkey */ 214}; 215 216/* 217 * Socket sysctl tree 218 */ 219 220SYSCTL_NODE(_net_bluetooth_hci, OID_AUTO, sockets, CTLFLAG_RW, 221 0, "Bluetooth HCI sockets family"); 222SYSCTL_NODE(_net_bluetooth_l2cap, OID_AUTO, sockets, CTLFLAG_RW, 223 0, "Bluetooth L2CAP sockets family"); 224SYSCTL_NODE(_net_bluetooth_rfcomm, OID_AUTO, sockets, CTLFLAG_RW, 225 0, "Bluetooth RFCOMM sockets family"); 226 227/* 228 * Module 229 */ 230 231static moduledata_t ng_btsocket_mod = { 232 "ng_btsocket", 233 ng_btsocket_modevent, 234 NULL 235}; 236
| 30 */ 31 32#include <sys/param.h> 33#include <sys/systm.h> 34#include <sys/bitstring.h> 35#include <sys/errno.h> 36#include <sys/domain.h> 37#include <sys/kernel.h> 38#include <sys/lock.h> 39#include <sys/mbuf.h> 40#include <sys/mutex.h> 41#include <sys/protosw.h> 42#include <sys/socket.h> 43#include <sys/socketvar.h> 44#include <sys/sysctl.h> 45#include <sys/taskqueue.h> 46#include <netgraph/ng_message.h> 47#include <netgraph/netgraph.h> 48#include <netgraph/bluetooth/include/ng_bluetooth.h> 49#include <netgraph/bluetooth/include/ng_hci.h> 50#include <netgraph/bluetooth/include/ng_l2cap.h> 51#include <netgraph/bluetooth/include/ng_btsocket.h> 52#include <netgraph/bluetooth/include/ng_btsocket_hci_raw.h> 53#include <netgraph/bluetooth/include/ng_btsocket_l2cap.h> 54#include <netgraph/bluetooth/include/ng_btsocket_rfcomm.h> 55 56static int ng_btsocket_modevent (module_t, int, void *); 57extern struct domain ng_btsocket_domain; 58 59/* 60 * Bluetooth raw HCI sockets 61 */ 62 63static struct pr_usrreqs ng_btsocket_hci_raw_usrreqs = { 64 .pru_abort = ng_btsocket_hci_raw_abort, 65 .pru_attach = ng_btsocket_hci_raw_attach, 66 .pru_bind = ng_btsocket_hci_raw_bind, 67 .pru_connect = ng_btsocket_hci_raw_connect, 68 .pru_control = ng_btsocket_hci_raw_control, 69 .pru_detach = ng_btsocket_hci_raw_detach, 70 .pru_disconnect = ng_btsocket_hci_raw_disconnect, 71 .pru_peeraddr = ng_btsocket_hci_raw_peeraddr, 72 .pru_send = ng_btsocket_hci_raw_send, 73 .pru_shutdown = NULL, 74 .pru_sockaddr = ng_btsocket_hci_raw_sockaddr, 75}; 76 77/* 78 * Bluetooth raw L2CAP sockets 79 */ 80 81static struct pr_usrreqs ng_btsocket_l2cap_raw_usrreqs = { 82 .pru_abort = ng_btsocket_l2cap_raw_abort, 83 .pru_attach = ng_btsocket_l2cap_raw_attach, 84 .pru_bind = ng_btsocket_l2cap_raw_bind, 85 .pru_connect = ng_btsocket_l2cap_raw_connect, 86 .pru_control = ng_btsocket_l2cap_raw_control, 87 .pru_detach = ng_btsocket_l2cap_raw_detach, 88 .pru_disconnect = ng_btsocket_l2cap_raw_disconnect, 89 .pru_peeraddr = ng_btsocket_l2cap_raw_peeraddr, 90 .pru_send = ng_btsocket_l2cap_raw_send, 91 .pru_shutdown = NULL, 92 .pru_sockaddr = ng_btsocket_l2cap_raw_sockaddr, 93}; 94 95/* 96 * Bluetooth SEQPACKET L2CAP sockets 97 */ 98 99static struct pr_usrreqs ng_btsocket_l2cap_usrreqs = { 100 .pru_abort = ng_btsocket_l2cap_abort, 101 .pru_accept = ng_btsocket_l2cap_accept, 102 .pru_attach = ng_btsocket_l2cap_attach, 103 .pru_bind = ng_btsocket_l2cap_bind, 104 .pru_connect = ng_btsocket_l2cap_connect, 105 .pru_control = ng_btsocket_l2cap_control, 106 .pru_detach = ng_btsocket_l2cap_detach, 107 .pru_disconnect = ng_btsocket_l2cap_disconnect, 108 .pru_listen = ng_btsocket_l2cap_listen, 109 .pru_peeraddr = ng_btsocket_l2cap_peeraddr, 110 .pru_send = ng_btsocket_l2cap_send, 111 .pru_shutdown = NULL, 112 .pru_sockaddr = ng_btsocket_l2cap_sockaddr, 113}; 114 115/* 116 * Bluetooth STREAM RFCOMM sockets 117 */ 118 119static struct pr_usrreqs ng_btsocket_rfcomm_usrreqs = { 120 .pru_abort = ng_btsocket_rfcomm_abort, 121 .pru_accept = ng_btsocket_rfcomm_accept, 122 .pru_attach = ng_btsocket_rfcomm_attach, 123 .pru_bind = ng_btsocket_rfcomm_bind, 124 .pru_connect = ng_btsocket_rfcomm_connect, 125 .pru_control = ng_btsocket_rfcomm_control, 126 .pru_detach = ng_btsocket_rfcomm_detach, 127 .pru_disconnect = ng_btsocket_rfcomm_disconnect, 128 .pru_listen = ng_btsocket_rfcomm_listen, 129 .pru_peeraddr = ng_btsocket_rfcomm_peeraddr, 130 .pru_send = ng_btsocket_rfcomm_send, 131 .pru_shutdown = NULL, 132 .pru_sockaddr = ng_btsocket_rfcomm_sockaddr, 133}; 134 135/* 136 * Definitions of protocols supported in the BLUETOOTH domain 137 */ 138 139static struct protosw ng_btsocket_protosw[] = { 140{ 141 SOCK_RAW, /* protocol type */ 142 &ng_btsocket_domain, /* backpointer to domain */ 143 BLUETOOTH_PROTO_HCI, /* protocol */ 144 PR_ATOMIC | PR_ADDR, /* flags */ 145 NULL, NULL, NULL, /* input, output, ctlinput */ 146 ng_btsocket_hci_raw_ctloutput, /* ctloutput */ 147 NULL, /* ousrreq() */ 148 ng_btsocket_hci_raw_init, /* init */ 149 NULL, NULL, NULL, /* fasttimeo, slowtimo, drain */ 150 &ng_btsocket_hci_raw_usrreqs, /* usrreq table (above) */ 151 /* { NULL } */ /* pfh (protocol filter head?) */ 152}, 153{ 154 SOCK_RAW, /* protocol type */ 155 &ng_btsocket_domain, /* backpointer to domain */ 156 BLUETOOTH_PROTO_L2CAP, /* protocol */ 157 PR_ATOMIC | PR_ADDR, /* flags */ 158 NULL, NULL, NULL, /* input, output, ctlinput */ 159 NULL, /* ctloutput */ 160 NULL, /* ousrreq() */ 161 ng_btsocket_l2cap_raw_init, /* init */ 162 NULL, NULL, NULL, /* fasttimeo, slowtimo, drain */ 163 &ng_btsocket_l2cap_raw_usrreqs, /* usrreq table (above) */ 164 /* { NULL } */ /* pfh (protocol filter head?) */ 165}, 166{ 167 SOCK_SEQPACKET, /* protocol type */ 168 &ng_btsocket_domain, /* backpointer to domain */ 169 BLUETOOTH_PROTO_L2CAP, /* protocol */ 170 PR_ATOMIC | PR_CONNREQUIRED, /* flags */ 171 NULL, NULL, NULL, /* input, output, ctlinput */ 172 ng_btsocket_l2cap_ctloutput, /* ctloutput */ 173 NULL, /* ousrreq() */ 174 ng_btsocket_l2cap_init, /* init */ 175 NULL, NULL, NULL, /* fasttimeo, slowtimo, drain */ 176 &ng_btsocket_l2cap_usrreqs, /* usrreq table (above) */ 177 /* { NULL } */ /* pfh (protocol filter head?) */ 178}, 179{ 180 SOCK_STREAM, /* protocol type */ 181 &ng_btsocket_domain, /* backpointer to domain */ 182 BLUETOOTH_PROTO_RFCOMM, /* protocol */ 183 PR_ATOMIC | PR_CONNREQUIRED, /* flags */ 184 NULL, NULL, NULL, /* input, output, ctlinput */ 185 ng_btsocket_rfcomm_ctloutput, /* ctloutput */ 186 NULL, /* ousrreq() */ 187 ng_btsocket_rfcomm_init, /* init */ 188 NULL, NULL, NULL, /* fasttimeo, slowtimo, drain */ 189 &ng_btsocket_rfcomm_usrreqs, /* usrreq table (above) */ 190 /* { NULL } */ /* pfh (protocol filter head?) */ 191} 192}; 193#define ng_btsocket_protosw_size \ 194 (sizeof(ng_btsocket_protosw)/sizeof(ng_btsocket_protosw[0])) 195#define ng_btsocket_protosw_end \ 196 &ng_btsocket_protosw[ng_btsocket_protosw_size] 197 198/* 199 * BLUETOOTH domain 200 */ 201 202struct domain ng_btsocket_domain = { 203 AF_BLUETOOTH, /* family */ 204 "bluetooth", /* domain name */ 205 NULL, /* init() */ 206 NULL, /* externalize() */ 207 NULL, /* dispose() */ 208 ng_btsocket_protosw, /* protosw entry */ 209 ng_btsocket_protosw_end, /* end of protosw entries */ 210 NULL, /* next domain in list */ 211 NULL, /* rtattach() */ 212 0, /* arg to rtattach in bits */ 213 0 /* maxrtkey */ 214}; 215 216/* 217 * Socket sysctl tree 218 */ 219 220SYSCTL_NODE(_net_bluetooth_hci, OID_AUTO, sockets, CTLFLAG_RW, 221 0, "Bluetooth HCI sockets family"); 222SYSCTL_NODE(_net_bluetooth_l2cap, OID_AUTO, sockets, CTLFLAG_RW, 223 0, "Bluetooth L2CAP sockets family"); 224SYSCTL_NODE(_net_bluetooth_rfcomm, OID_AUTO, sockets, CTLFLAG_RW, 225 0, "Bluetooth RFCOMM sockets family"); 226 227/* 228 * Module 229 */ 230 231static moduledata_t ng_btsocket_mod = { 232 "ng_btsocket", 233 ng_btsocket_modevent, 234 NULL 235}; 236
|