| 1 |
|
| 2 | |
| 3 | RFCOMM implementation for Linux Bluetooth stack (BlueZ)
|
| 4 | Copyright (C) 2002 Maxim Krasnyansky <[email protected]>
|
| 5 | Copyright (C) 2002 Marcel Holtmann <[email protected]>
|
| 6 |
|
| 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
| 8 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 9 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
|
| 10 | IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
|
| 11 | CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
|
| 12 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
| 13 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
| 14 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
| 15 |
|
| 16 | ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
|
| 17 | COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
|
| 18 | SOFTWARE IS DISCLAIMED.
|
| 19 |
|
| 20 |
|
| 21 | #include <linux/refcount.h>
|
| 22 |
|
| 23 | #ifndef __RFCOMM_H
|
| 24 | #define __RFCOMM_H
|
| 25 |
|
| 26 | #define RFCOMM_CONN_TIMEOUT (HZ * 30)
|
| 27 | #define RFCOMM_DISC_TIMEOUT (HZ * 20)
|
| 28 | #define RFCOMM_AUTH_TIMEOUT (HZ * 25)
|
| 29 | #define RFCOMM_IDLE_TIMEOUT (HZ * 2)
|
| 30 |
|
| 31 | #define RFCOMM_DEFAULT_MTU 127
|
| 32 | #define RFCOMM_DEFAULT_CREDITS 7
|
| 33 |
|
| 34 | #define RFCOMM_MAX_CREDITS 40
|
| 35 |
|
| 36 | #define RFCOMM_SKB_HEAD_RESERVE 8
|
| 37 | #define RFCOMM_SKB_TAIL_RESERVE 2
|
| 38 | #define RFCOMM_SKB_RESERVE (RFCOMM_SKB_HEAD_RESERVE + RFCOMM_SKB_TAIL_RESERVE)
|
| 39 |
|
| 40 | #define RFCOMM_SABM 0x2f
|
| 41 | #define RFCOMM_DISC 0x43
|
| 42 | #define RFCOMM_UA 0x63
|
| 43 | #define RFCOMM_DM 0x0f
|
| 44 | #define RFCOMM_UIH 0xef
|
| 45 |
|
| 46 | #define RFCOMM_TEST 0x08
|
| 47 | #define RFCOMM_FCON 0x28
|
| 48 | #define RFCOMM_FCOFF 0x18
|
| 49 | #define RFCOMM_MSC 0x38
|
| 50 | #define RFCOMM_RPN 0x24
|
| 51 | #define RFCOMM_RLS 0x14
|
| 52 | #define RFCOMM_PN 0x20
|
| 53 | #define RFCOMM_NSC 0x04
|
| 54 |
|
| 55 | #define RFCOMM_V24_FC 0x02
|
| 56 | #define RFCOMM_V24_RTC 0x04
|
| 57 | #define RFCOMM_V24_RTR 0x08
|
| 58 | #define RFCOMM_V24_IC 0x40
|
| 59 | #define RFCOMM_V24_DV 0x80
|
| 60 |
|
| 61 | #define RFCOMM_RPN_BR_2400 0x0
|
| 62 | #define RFCOMM_RPN_BR_4800 0x1
|
| 63 | #define RFCOMM_RPN_BR_7200 0x2
|
| 64 | #define RFCOMM_RPN_BR_9600 0x3
|
| 65 | #define RFCOMM_RPN_BR_19200 0x4
|
| 66 | #define RFCOMM_RPN_BR_38400 0x5
|
| 67 | #define RFCOMM_RPN_BR_57600 0x6
|
| 68 | #define RFCOMM_RPN_BR_115200 0x7
|
| 69 | #define RFCOMM_RPN_BR_230400 0x8
|
| 70 |
|
| 71 | #define RFCOMM_RPN_DATA_5 0x0
|
| 72 | #define RFCOMM_RPN_DATA_6 0x1
|
| 73 | #define RFCOMM_RPN_DATA_7 0x2
|
| 74 | #define RFCOMM_RPN_DATA_8 0x3
|
| 75 |
|
| 76 | #define RFCOMM_RPN_STOP_1 0
|
| 77 | #define RFCOMM_RPN_STOP_15 1
|
| 78 |
|
| 79 | #define RFCOMM_RPN_PARITY_NONE 0x0
|
| 80 | #define RFCOMM_RPN_PARITY_ODD 0x1
|
| 81 | #define RFCOMM_RPN_PARITY_EVEN 0x3
|
| 82 | #define RFCOMM_RPN_PARITY_MARK 0x5
|
| 83 | #define RFCOMM_RPN_PARITY_SPACE 0x7
|
| 84 |
|
| 85 | #define RFCOMM_RPN_FLOW_NONE 0x00
|
| 86 |
|
| 87 | #define RFCOMM_RPN_XON_CHAR 0x11
|
| 88 | #define RFCOMM_RPN_XOFF_CHAR 0x13
|
| 89 |
|
| 90 | #define RFCOMM_RPN_PM_BITRATE 0x0001
|
| 91 | #define RFCOMM_RPN_PM_DATA 0x0002
|
| 92 | #define RFCOMM_RPN_PM_STOP 0x0004
|
| 93 | #define RFCOMM_RPN_PM_PARITY 0x0008
|
| 94 | #define RFCOMM_RPN_PM_PARITY_TYPE 0x0010
|
| 95 | #define RFCOMM_RPN_PM_XON 0x0020
|
| 96 | #define RFCOMM_RPN_PM_XOFF 0x0040
|
| 97 | #define RFCOMM_RPN_PM_FLOW 0x3F00
|
| 98 |
|
| 99 | #define RFCOMM_RPN_PM_ALL 0x3F7F
|
| 100 |
|
| 101 | struct rfcomm_hdr {
|
| 102 | u8 addr;
|
| 103 | u8 ctrl;
|
| 104 | u8 len;
|
| 105 | } __packed;
|
| 106 |
|
| 107 | struct rfcomm_cmd {
|
| 108 | u8 addr;
|
| 109 | u8 ctrl;
|
| 110 | u8 len;
|
| 111 | u8 fcs;
|
| 112 | } __packed;
|
| 113 |
|
| 114 | struct rfcomm_mcc {
|
| 115 | u8 type;
|
| 116 | u8 len;
|
| 117 | } __packed;
|
| 118 |
|
| 119 | struct rfcomm_pn {
|
| 120 | u8 dlci;
|
| 121 | u8 flow_ctrl;
|
| 122 | u8 priority;
|
| 123 | u8 ack_timer;
|
| 124 | __le16 mtu;
|
| 125 | u8 max_retrans;
|
| 126 | u8 credits;
|
| 127 | } __packed;
|
| 128 |
|
| 129 | struct rfcomm_rpn {
|
| 130 | u8 dlci;
|
| 131 | u8 bit_rate;
|
| 132 | u8 line_settings;
|
| 133 | u8 flow_ctrl;
|
| 134 | u8 xon_char;
|
| 135 | u8 xoff_char;
|
| 136 | __le16 param_mask;
|
| 137 | } __packed;
|
| 138 |
|
| 139 | struct rfcomm_rls {
|
| 140 | u8 dlci;
|
| 141 | u8 status;
|
| 142 | } __packed;
|
| 143 |
|
| 144 | struct rfcomm_msc {
|
| 145 | u8 dlci;
|
| 146 | u8 v24_sig;
|
| 147 | } __packed;
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 | struct rfcomm_session {
|
| 152 | struct list_head list;
|
| 153 | struct socket *sock;
|
| 154 | struct timer_list timer;
|
| 155 | unsigned long state;
|
| 156 | unsigned long flags;
|
| 157 | int initiator;
|
| 158 |
|
| 159 |
|
| 160 | int cfc;
|
| 161 | uint mtu;
|
| 162 |
|
| 163 | struct list_head dlcs;
|
| 164 | };
|
| 165 |
|
| 166 | struct rfcomm_dlc {
|
| 167 | struct list_head list;
|
| 168 | struct rfcomm_session *session;
|
| 169 | struct sk_buff_head tx_queue;
|
| 170 | struct timer_list timer;
|
| 171 |
|
| 172 | struct mutex lock;
|
| 173 | unsigned long state;
|
| 174 | unsigned long flags;
|
| 175 | refcount_t refcnt;
|
| 176 | u8 dlci;
|
| 177 | u8 addr;
|
| 178 | u8 priority;
|
| 179 | u8 v24_sig;
|
| 180 | u8 remote_v24_sig;
|
| 181 | u8 mscex;
|
| 182 | u8 out;
|
| 183 | u8 sec_level;
|
| 184 | u8 role_switch;
|
| 185 | u32 defer_setup;
|
| 186 |
|
| 187 | uint mtu;
|
| 188 | uint cfc;
|
| 189 | uint rx_credits;
|
| 190 | uint tx_credits;
|
| 191 |
|
| 192 | void *owner;
|
| 193 |
|
| 194 | void (*data_ready)(struct rfcomm_dlc *d, struct sk_buff *skb);
|
| 195 | void (*state_change)(struct rfcomm_dlc *d, int err);
|
| 196 | void (*modem_status)(struct rfcomm_dlc *d, u8 v24_sig);
|
| 197 | };
|
| 198 |
|
| 199 |
|
| 200 | #define RFCOMM_RX_THROTTLED 0
|
| 201 | #define RFCOMM_TX_THROTTLED 1
|
| 202 | #define RFCOMM_TIMED_OUT 2
|
| 203 | #define RFCOMM_MSC_PENDING 3
|
| 204 | #define RFCOMM_SEC_PENDING 4
|
| 205 | #define RFCOMM_AUTH_PENDING 5
|
| 206 | #define RFCOMM_AUTH_ACCEPT 6
|
| 207 | #define RFCOMM_AUTH_REJECT 7
|
| 208 | #define RFCOMM_DEFER_SETUP 8
|
| 209 | #define RFCOMM_ENC_DROP 9
|
| 210 | #define RFCOMM_CLOSED 10
|
| 211 |
|
| 212 |
|
| 213 | #define RFCOMM_SCHED_WAKEUP 31
|
| 214 |
|
| 215 |
|
| 216 | #define RFCOMM_MSCEX_TX 1
|
| 217 | #define RFCOMM_MSCEX_RX 2
|
| 218 | #define RFCOMM_MSCEX_OK (RFCOMM_MSCEX_TX + RFCOMM_MSCEX_RX)
|
| 219 |
|
| 220 |
|
| 221 | #define RFCOMM_CFC_UNKNOWN -1
|
| 222 | #define RFCOMM_CFC_DISABLED 0
|
| 223 | #define RFCOMM_CFC_ENABLED RFCOMM_MAX_CREDITS
|
| 224 |
|
| 225 |
|
| 226 | int rfcomm_send_rpn(struct rfcomm_session *s, int cr, u8 dlci,
|
| 227 | u8 bit_rate, u8 data_bits, u8 stop_bits,
|
| 228 | u8 parity, u8 flow_ctrl_settings,
|
| 229 | u8 xon_char, u8 xoff_char, u16 param_mask);
|
| 230 | int rfcomm_dlc_send_rpn(struct rfcomm_dlc *d, u8 bit_rate, u8 data_bits,
|
| 231 | u8 stop_bits, u8 parity, u8 flow_ctrl_settings,
|
| 232 | u8 xon_char, u8 xoff_char, u16 param_mask);
|
| 233 |
|
| 234 |
|
| 235 | struct rfcomm_dlc *rfcomm_dlc_alloc(gfp_t prio);
|
| 236 | void rfcomm_dlc_free(struct rfcomm_dlc *d);
|
| 237 | int rfcomm_dlc_open(struct rfcomm_dlc *d, bdaddr_t *src, bdaddr_t *dst,
|
| 238 | u8 channel);
|
| 239 | int rfcomm_dlc_close(struct rfcomm_dlc *d, int reason);
|
| 240 | int rfcomm_dlc_send(struct rfcomm_dlc *d, struct sk_buff *skb);
|
| 241 | void rfcomm_dlc_send_noerror(struct rfcomm_dlc *d, struct sk_buff *skb);
|
| 242 | int rfcomm_dlc_set_modem_status(struct rfcomm_dlc *d, u8 v24_sig);
|
| 243 | int rfcomm_dlc_get_modem_status(struct rfcomm_dlc *d, u8 *v24_sig);
|
| 244 | void rfcomm_dlc_accept(struct rfcomm_dlc *d);
|
| 245 | struct rfcomm_dlc *rfcomm_dlc_exists(bdaddr_t *src, bdaddr_t *dst, u8 channel);
|
| 246 |
|
| 247 | #define rfcomm_dlc_lock(d) mutex_lock(&d->lock)
|
| 248 | #define rfcomm_dlc_unlock(d) mutex_unlock(&d->lock)
|
| 249 |
|
| 250 | static inline void rfcomm_dlc_hold(struct rfcomm_dlc *d)
|
| 251 | {
|
| 252 | refcount_inc(&d->refcnt);
|
| 253 | }
|
| 254 |
|
| 255 | static inline void rfcomm_dlc_put(struct rfcomm_dlc *d)
|
| 256 | {
|
| 257 | if (refcount_dec_and_test(&d->refcnt))
|
| 258 | rfcomm_dlc_free(d);
|
| 259 | }
|
| 260 |
|
| 261 | void __rfcomm_dlc_throttle(struct rfcomm_dlc *d);
|
| 262 | void __rfcomm_dlc_unthrottle(struct rfcomm_dlc *d);
|
| 263 |
|
| 264 | static inline void rfcomm_dlc_throttle(struct rfcomm_dlc *d)
|
| 265 | {
|
| 266 | if (!test_and_set_bit(RFCOMM_RX_THROTTLED, &d->flags))
|
| 267 | __rfcomm_dlc_throttle(d);
|
| 268 | }
|
| 269 |
|
| 270 | static inline void rfcomm_dlc_unthrottle(struct rfcomm_dlc *d)
|
| 271 | {
|
| 272 | if (test_and_clear_bit(RFCOMM_RX_THROTTLED, &d->flags))
|
| 273 | __rfcomm_dlc_unthrottle(d);
|
| 274 | }
|
| 275 |
|
| 276 |
|
| 277 | void rfcomm_session_getaddr(struct rfcomm_session *s, bdaddr_t *src,
|
| 278 | bdaddr_t *dst);
|
| 279 |
|
| 280 |
|
| 281 | struct sockaddr_rc {
|
| 282 | sa_family_t rc_family;
|
| 283 | bdaddr_t rc_bdaddr;
|
| 284 | u8 rc_channel;
|
| 285 | };
|
| 286 |
|
| 287 | #define RFCOMM_CONNINFO 0x02
|
| 288 | struct rfcomm_conninfo {
|
| 289 | __u16 hci_handle;
|
| 290 | __u8 dev_class[3];
|
| 291 | };
|
| 292 |
|
| 293 | #define RFCOMM_LM 0x03
|
| 294 | #define RFCOMM_LM_MASTER 0x0001
|
| 295 | #define RFCOMM_LM_AUTH 0x0002
|
| 296 | #define RFCOMM_LM_ENCRYPT 0x0004
|
| 297 | #define RFCOMM_LM_TRUSTED 0x0008
|
| 298 | #define RFCOMM_LM_RELIABLE 0x0010
|
| 299 | #define RFCOMM_LM_SECURE 0x0020
|
| 300 | #define RFCOMM_LM_FIPS 0x0040
|
| 301 |
|
| 302 | #define rfcomm_pi(sk) ((struct rfcomm_pinfo *) sk)
|
| 303 |
|
| 304 | struct rfcomm_pinfo {
|
| 305 | struct bt_sock bt;
|
| 306 | bdaddr_t src;
|
| 307 | bdaddr_t dst;
|
| 308 | struct rfcomm_dlc *dlc;
|
| 309 | u8 channel;
|
| 310 | u8 sec_level;
|
| 311 | u8 role_switch;
|
| 312 | };
|
| 313 |
|
| 314 | int rfcomm_init_sockets(void);
|
| 315 | void rfcomm_cleanup_sockets(void);
|
| 316 |
|
| 317 | int rfcomm_connect_ind(struct rfcomm_session *s, u8 channel,
|
| 318 | struct rfcomm_dlc **d);
|
| 319 |
|
| 320 |
|
| 321 | #define RFCOMM_MAX_DEV 256
|
| 322 |
|
| 323 | #define RFCOMMCREATEDEV _IOW('R', 200, int)
|
| 324 | #define RFCOMMRELEASEDEV _IOW('R', 201, int)
|
| 325 | #define RFCOMMGETDEVLIST _IOR('R', 210, int)
|
| 326 | #define RFCOMMGETDEVINFO _IOR('R', 211, int)
|
| 327 | #define RFCOMMSTEALDLC _IOW('R', 220, int)
|
| 328 |
|
| 329 |
|
| 330 | #define RFCOMM_REUSE_DLC 0
|
| 331 | #define RFCOMM_RELEASE_ONHUP 1
|
| 332 | #define RFCOMM_HANGUP_NOW 2
|
| 333 | #define RFCOMM_TTY_ATTACHED 3
|
| 334 | #define RFCOMM_DEFUNCT_BIT4 4
|
| 335 |
|
| 336 |
|
| 337 | #define RFCOMM_DEV_RELEASED 0
|
| 338 | #define RFCOMM_TTY_OWNED 1
|
| 339 |
|
| 340 | struct rfcomm_dev_req {
|
| 341 | s16 dev_id;
|
| 342 | u32 flags;
|
| 343 | bdaddr_t src;
|
| 344 | bdaddr_t dst;
|
| 345 | u8 channel;
|
| 346 | };
|
| 347 |
|
| 348 | struct rfcomm_dev_info {
|
| 349 | s16 id;
|
| 350 | u32 flags;
|
| 351 | u16 state;
|
| 352 | bdaddr_t src;
|
| 353 | bdaddr_t dst;
|
| 354 | u8 channel;
|
| 355 | };
|
| 356 |
|
| 357 | struct rfcomm_dev_list_req {
|
| 358 | u16 dev_num;
|
| 359 | struct rfcomm_dev_info dev_info[] __counted_by(dev_num);
|
| 360 | };
|
| 361 |
|
| 362 | int rfcomm_dev_ioctl(struct sock *sk, unsigned int cmd, void __user *arg);
|
| 363 |
|
| 364 | #ifdef CONFIG_BT_RFCOMM_TTY
|
| 365 | int rfcomm_init_ttys(void);
|
| 366 | void rfcomm_cleanup_ttys(void);
|
| 367 | #else
|
| 368 | static inline int rfcomm_init_ttys(void)
|
| 369 | {
|
| 370 | return 0;
|
| 371 | }
|
| 372 | static inline void rfcomm_cleanup_ttys(void)
|
| 373 | {
|
| 374 | }
|
| 375 | #endif
|
| 376 | #endif
|