Back to home page

OSCL-LXR

 
 

    


0001 /*
0002    RFCOMM implementation for Linux Bluetooth stack (BlueZ)
0003    Copyright (C) 2002 Maxim Krasnyansky <maxk@qualcomm.com>
0004    Copyright (C) 2002 Marcel Holtmann <marcel@holtmann.org>
0005 
0006    This program is free software; you can redistribute it and/or modify
0007    it under the terms of the GNU General Public License version 2 as
0008    published by the Free Software Foundation;
0009 
0010    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
0011    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0012    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
0013    IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
0014    CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
0015    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
0016    ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
0017    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
0018 
0019    ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
0020    COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
0021    SOFTWARE IS DISCLAIMED.
0022 */
0023 
0024 #include <linux/refcount.h>
0025 
0026 #ifndef __RFCOMM_H
0027 #define __RFCOMM_H
0028 
0029 #define RFCOMM_CONN_TIMEOUT (HZ * 30)
0030 #define RFCOMM_DISC_TIMEOUT (HZ * 20)
0031 #define RFCOMM_AUTH_TIMEOUT (HZ * 25)
0032 #define RFCOMM_IDLE_TIMEOUT (HZ * 2)
0033 
0034 #define RFCOMM_DEFAULT_MTU  127
0035 #define RFCOMM_DEFAULT_CREDITS  7
0036 
0037 #define RFCOMM_MAX_CREDITS  40
0038 
0039 #define RFCOMM_SKB_HEAD_RESERVE 8
0040 #define RFCOMM_SKB_TAIL_RESERVE 2
0041 #define RFCOMM_SKB_RESERVE  (RFCOMM_SKB_HEAD_RESERVE + RFCOMM_SKB_TAIL_RESERVE)
0042 
0043 #define RFCOMM_SABM 0x2f
0044 #define RFCOMM_DISC 0x43
0045 #define RFCOMM_UA   0x63
0046 #define RFCOMM_DM   0x0f
0047 #define RFCOMM_UIH  0xef
0048 
0049 #define RFCOMM_TEST 0x08
0050 #define RFCOMM_FCON 0x28
0051 #define RFCOMM_FCOFF    0x18
0052 #define RFCOMM_MSC  0x38
0053 #define RFCOMM_RPN  0x24
0054 #define RFCOMM_RLS  0x14
0055 #define RFCOMM_PN   0x20
0056 #define RFCOMM_NSC  0x04
0057 
0058 #define RFCOMM_V24_FC   0x02
0059 #define RFCOMM_V24_RTC  0x04
0060 #define RFCOMM_V24_RTR  0x08
0061 #define RFCOMM_V24_IC   0x40
0062 #define RFCOMM_V24_DV   0x80
0063 
0064 #define RFCOMM_RPN_BR_2400  0x0
0065 #define RFCOMM_RPN_BR_4800  0x1
0066 #define RFCOMM_RPN_BR_7200  0x2
0067 #define RFCOMM_RPN_BR_9600  0x3
0068 #define RFCOMM_RPN_BR_19200 0x4
0069 #define RFCOMM_RPN_BR_38400 0x5
0070 #define RFCOMM_RPN_BR_57600 0x6
0071 #define RFCOMM_RPN_BR_115200    0x7
0072 #define RFCOMM_RPN_BR_230400    0x8
0073 
0074 #define RFCOMM_RPN_DATA_5   0x0
0075 #define RFCOMM_RPN_DATA_6   0x1
0076 #define RFCOMM_RPN_DATA_7   0x2
0077 #define RFCOMM_RPN_DATA_8   0x3
0078 
0079 #define RFCOMM_RPN_STOP_1   0
0080 #define RFCOMM_RPN_STOP_15  1
0081 
0082 #define RFCOMM_RPN_PARITY_NONE  0x0
0083 #define RFCOMM_RPN_PARITY_ODD   0x1
0084 #define RFCOMM_RPN_PARITY_EVEN  0x3
0085 #define RFCOMM_RPN_PARITY_MARK  0x5
0086 #define RFCOMM_RPN_PARITY_SPACE 0x7
0087 
0088 #define RFCOMM_RPN_FLOW_NONE    0x00
0089 
0090 #define RFCOMM_RPN_XON_CHAR 0x11
0091 #define RFCOMM_RPN_XOFF_CHAR    0x13
0092 
0093 #define RFCOMM_RPN_PM_BITRATE       0x0001
0094 #define RFCOMM_RPN_PM_DATA      0x0002
0095 #define RFCOMM_RPN_PM_STOP      0x0004
0096 #define RFCOMM_RPN_PM_PARITY        0x0008
0097 #define RFCOMM_RPN_PM_PARITY_TYPE   0x0010
0098 #define RFCOMM_RPN_PM_XON       0x0020
0099 #define RFCOMM_RPN_PM_XOFF      0x0040
0100 #define RFCOMM_RPN_PM_FLOW      0x3F00
0101 
0102 #define RFCOMM_RPN_PM_ALL       0x3F7F
0103 
0104 struct rfcomm_hdr {
0105     u8 addr;
0106     u8 ctrl;
0107     u8 len;    /* Actual size can be 2 bytes */
0108 } __packed;
0109 
0110 struct rfcomm_cmd {
0111     u8 addr;
0112     u8 ctrl;
0113     u8 len;
0114     u8 fcs;
0115 } __packed;
0116 
0117 struct rfcomm_mcc {
0118     u8 type;
0119     u8 len;
0120 } __packed;
0121 
0122 struct rfcomm_pn {
0123     u8  dlci;
0124     u8  flow_ctrl;
0125     u8  priority;
0126     u8  ack_timer;
0127     __le16 mtu;
0128     u8  max_retrans;
0129     u8  credits;
0130 } __packed;
0131 
0132 struct rfcomm_rpn {
0133     u8  dlci;
0134     u8  bit_rate;
0135     u8  line_settings;
0136     u8  flow_ctrl;
0137     u8  xon_char;
0138     u8  xoff_char;
0139     __le16 param_mask;
0140 } __packed;
0141 
0142 struct rfcomm_rls {
0143     u8  dlci;
0144     u8  status;
0145 } __packed;
0146 
0147 struct rfcomm_msc {
0148     u8  dlci;
0149     u8  v24_sig;
0150 } __packed;
0151 
0152 /* ---- Core structures, flags etc ---- */
0153 
0154 struct rfcomm_session {
0155     struct list_head list;
0156     struct socket   *sock;
0157     struct timer_list timer;
0158     unsigned long    state;
0159     unsigned long    flags;
0160     int              initiator;
0161 
0162     /* Default DLC parameters */
0163     int    cfc;
0164     uint   mtu;
0165 
0166     struct list_head dlcs;
0167 };
0168 
0169 struct rfcomm_dlc {
0170     struct list_head      list;
0171     struct rfcomm_session *session;
0172     struct sk_buff_head   tx_queue;
0173     struct timer_list     timer;
0174 
0175     struct mutex  lock;
0176     unsigned long state;
0177     unsigned long flags;
0178     refcount_t    refcnt;
0179     u8            dlci;
0180     u8            addr;
0181     u8            priority;
0182     u8            v24_sig;
0183     u8            remote_v24_sig;
0184     u8            mscex;
0185     u8            out;
0186     u8            sec_level;
0187     u8            role_switch;
0188     u32           defer_setup;
0189 
0190     uint          mtu;
0191     uint          cfc;
0192     uint          rx_credits;
0193     uint          tx_credits;
0194 
0195     void          *owner;
0196 
0197     void (*data_ready)(struct rfcomm_dlc *d, struct sk_buff *skb);
0198     void (*state_change)(struct rfcomm_dlc *d, int err);
0199     void (*modem_status)(struct rfcomm_dlc *d, u8 v24_sig);
0200 };
0201 
0202 /* DLC and session flags */
0203 #define RFCOMM_RX_THROTTLED 0
0204 #define RFCOMM_TX_THROTTLED 1
0205 #define RFCOMM_TIMED_OUT    2
0206 #define RFCOMM_MSC_PENDING  3
0207 #define RFCOMM_SEC_PENDING  4
0208 #define RFCOMM_AUTH_PENDING 5
0209 #define RFCOMM_AUTH_ACCEPT  6
0210 #define RFCOMM_AUTH_REJECT  7
0211 #define RFCOMM_DEFER_SETUP  8
0212 #define RFCOMM_ENC_DROP     9
0213 
0214 /* Scheduling flags and events */
0215 #define RFCOMM_SCHED_WAKEUP 31
0216 
0217 /* MSC exchange flags */
0218 #define RFCOMM_MSCEX_TX     1
0219 #define RFCOMM_MSCEX_RX     2
0220 #define RFCOMM_MSCEX_OK     (RFCOMM_MSCEX_TX + RFCOMM_MSCEX_RX)
0221 
0222 /* CFC states */
0223 #define RFCOMM_CFC_UNKNOWN  -1
0224 #define RFCOMM_CFC_DISABLED 0
0225 #define RFCOMM_CFC_ENABLED  RFCOMM_MAX_CREDITS
0226 
0227 /* ---- RFCOMM SEND RPN ---- */
0228 int rfcomm_send_rpn(struct rfcomm_session *s, int cr, u8 dlci,
0229             u8 bit_rate, u8 data_bits, u8 stop_bits,
0230             u8 parity, u8 flow_ctrl_settings,
0231             u8 xon_char, u8 xoff_char, u16 param_mask);
0232 
0233 /* ---- RFCOMM DLCs (channels) ---- */
0234 struct rfcomm_dlc *rfcomm_dlc_alloc(gfp_t prio);
0235 void rfcomm_dlc_free(struct rfcomm_dlc *d);
0236 int  rfcomm_dlc_open(struct rfcomm_dlc *d, bdaddr_t *src, bdaddr_t *dst,
0237                                 u8 channel);
0238 int  rfcomm_dlc_close(struct rfcomm_dlc *d, int reason);
0239 int  rfcomm_dlc_send(struct rfcomm_dlc *d, struct sk_buff *skb);
0240 void rfcomm_dlc_send_noerror(struct rfcomm_dlc *d, struct sk_buff *skb);
0241 int  rfcomm_dlc_set_modem_status(struct rfcomm_dlc *d, u8 v24_sig);
0242 int  rfcomm_dlc_get_modem_status(struct rfcomm_dlc *d, u8 *v24_sig);
0243 void rfcomm_dlc_accept(struct rfcomm_dlc *d);
0244 struct rfcomm_dlc *rfcomm_dlc_exists(bdaddr_t *src, bdaddr_t *dst, u8 channel);
0245 
0246 #define rfcomm_dlc_lock(d)     mutex_lock(&d->lock)
0247 #define rfcomm_dlc_unlock(d)   mutex_unlock(&d->lock)
0248 
0249 static inline void rfcomm_dlc_hold(struct rfcomm_dlc *d)
0250 {
0251     refcount_inc(&d->refcnt);
0252 }
0253 
0254 static inline void rfcomm_dlc_put(struct rfcomm_dlc *d)
0255 {
0256     if (refcount_dec_and_test(&d->refcnt))
0257         rfcomm_dlc_free(d);
0258 }
0259 
0260 void __rfcomm_dlc_throttle(struct rfcomm_dlc *d);
0261 void __rfcomm_dlc_unthrottle(struct rfcomm_dlc *d);
0262 
0263 static inline void rfcomm_dlc_throttle(struct rfcomm_dlc *d)
0264 {
0265     if (!test_and_set_bit(RFCOMM_RX_THROTTLED, &d->flags))
0266         __rfcomm_dlc_throttle(d);
0267 }
0268 
0269 static inline void rfcomm_dlc_unthrottle(struct rfcomm_dlc *d)
0270 {
0271     if (test_and_clear_bit(RFCOMM_RX_THROTTLED, &d->flags))
0272         __rfcomm_dlc_unthrottle(d);
0273 }
0274 
0275 /* ---- RFCOMM sessions ---- */
0276 void   rfcomm_session_getaddr(struct rfcomm_session *s, bdaddr_t *src,
0277                                 bdaddr_t *dst);
0278 
0279 /* ---- RFCOMM sockets ---- */
0280 struct sockaddr_rc {
0281     sa_family_t rc_family;
0282     bdaddr_t    rc_bdaddr;
0283     u8      rc_channel;
0284 };
0285 
0286 #define RFCOMM_CONNINFO 0x02
0287 struct rfcomm_conninfo {
0288     __u16 hci_handle;
0289     __u8  dev_class[3];
0290 };
0291 
0292 #define RFCOMM_LM   0x03
0293 #define RFCOMM_LM_MASTER    0x0001
0294 #define RFCOMM_LM_AUTH      0x0002
0295 #define RFCOMM_LM_ENCRYPT   0x0004
0296 #define RFCOMM_LM_TRUSTED   0x0008
0297 #define RFCOMM_LM_RELIABLE  0x0010
0298 #define RFCOMM_LM_SECURE    0x0020
0299 #define RFCOMM_LM_FIPS      0x0040
0300 
0301 #define rfcomm_pi(sk) ((struct rfcomm_pinfo *) sk)
0302 
0303 struct rfcomm_pinfo {
0304     struct bt_sock bt;
0305     bdaddr_t src;
0306     bdaddr_t dst;
0307     struct rfcomm_dlc   *dlc;
0308     u8     channel;
0309     u8     sec_level;
0310     u8     role_switch;
0311 };
0312 
0313 int  rfcomm_init_sockets(void);
0314 void rfcomm_cleanup_sockets(void);
0315 
0316 int  rfcomm_connect_ind(struct rfcomm_session *s, u8 channel,
0317                             struct rfcomm_dlc **d);
0318 
0319 /* ---- RFCOMM TTY ---- */
0320 #define RFCOMM_MAX_DEV  256
0321 
0322 #define RFCOMMCREATEDEV     _IOW('R', 200, int)
0323 #define RFCOMMRELEASEDEV    _IOW('R', 201, int)
0324 #define RFCOMMGETDEVLIST    _IOR('R', 210, int)
0325 #define RFCOMMGETDEVINFO    _IOR('R', 211, int)
0326 #define RFCOMMSTEALDLC      _IOW('R', 220, int)
0327 
0328 /* rfcomm_dev.flags bit definitions */
0329 #define RFCOMM_REUSE_DLC      0
0330 #define RFCOMM_RELEASE_ONHUP  1
0331 #define RFCOMM_HANGUP_NOW     2
0332 #define RFCOMM_TTY_ATTACHED   3
0333 #define RFCOMM_DEFUNCT_BIT4   4   /* don't reuse this bit - userspace visible */
0334 
0335 /* rfcomm_dev.status bit definitions */
0336 #define RFCOMM_DEV_RELEASED   0
0337 #define RFCOMM_TTY_OWNED      1
0338 
0339 struct rfcomm_dev_req {
0340     s16      dev_id;
0341     u32      flags;
0342     bdaddr_t src;
0343     bdaddr_t dst;
0344     u8       channel;
0345 };
0346 
0347 struct rfcomm_dev_info {
0348     s16      id;
0349     u32      flags;
0350     u16      state;
0351     bdaddr_t src;
0352     bdaddr_t dst;
0353     u8       channel;
0354 };
0355 
0356 struct rfcomm_dev_list_req {
0357     u16      dev_num;
0358     struct   rfcomm_dev_info dev_info[];
0359 };
0360 
0361 int  rfcomm_dev_ioctl(struct sock *sk, unsigned int cmd, void __user *arg);
0362 
0363 #ifdef CONFIG_BT_RFCOMM_TTY
0364 int  rfcomm_init_ttys(void);
0365 void rfcomm_cleanup_ttys(void);
0366 #else
0367 static inline int rfcomm_init_ttys(void)
0368 {
0369     return 0;
0370 }
0371 static inline void rfcomm_cleanup_ttys(void)
0372 {
0373 }
0374 #endif
0375 #endif /* __RFCOMM_H */