Lines Matching +full:d +full:-
42 static int channel_mtu = -1;
56 static int rfcomm_queue_disc(struct rfcomm_dlc *d);
58 static int rfcomm_send_pn(struct rfcomm_session *s, int cr, struct rfcomm_dlc *d);
73 /* ---- RFCOMM frame parsing macros ---- */
81 #define __session_dir(s) ((s)->initiator ? 0x00 : 0x01)
109 /* ---- RFCOMM FCS computation ---- */
111 /* reversed, 8-bit, poly=0x07 */
160 return 0xff - __crc(data); in __fcs()
166 return 0xff - rfcomm_crc_table[__crc(data) ^ data[2]]; in __fcs2()
180 /* ---- L2CAP callbacks ---- */
183 BT_DBG("%p state %d", sk, sk->sk_state); in rfcomm_l2state_change()
201 struct sock *sk = (*sock)->sk; in rfcomm_l2sock_create()
202 sk->sk_data_ready = rfcomm_l2data_ready; in rfcomm_l2sock_create()
203 sk->sk_state_change = rfcomm_l2state_change; in rfcomm_l2sock_create()
208 static int rfcomm_check_security(struct rfcomm_dlc *d) in rfcomm_check_security() argument
210 struct sock *sk = d->session->sock->sk; in rfcomm_check_security()
211 struct l2cap_conn *conn = l2cap_pi(sk)->chan->conn; in rfcomm_check_security()
215 switch (d->sec_level) { in rfcomm_check_security()
228 return hci_conn_security(conn->hcon, d->sec_level, auth_type, in rfcomm_check_security()
229 d->out); in rfcomm_check_security()
236 BT_DBG("session %p state %ld", s, s->state); in rfcomm_session_timeout()
238 set_bit(RFCOMM_TIMED_OUT, &s->flags); in rfcomm_session_timeout()
244 BT_DBG("session %p state %ld timeout %ld", s, s->state, timeout); in rfcomm_session_set_timer()
246 mod_timer(&s->timer, jiffies + timeout); in rfcomm_session_set_timer()
251 BT_DBG("session %p state %ld", s, s->state); in rfcomm_session_clear_timer()
253 del_timer_sync(&s->timer); in rfcomm_session_clear_timer()
256 /* ---- RFCOMM DLCs ---- */
259 struct rfcomm_dlc *d = from_timer(d, t, timer); in rfcomm_dlc_timeout() local
261 BT_DBG("dlc %p state %ld", d, d->state); in rfcomm_dlc_timeout()
263 set_bit(RFCOMM_TIMED_OUT, &d->flags); in rfcomm_dlc_timeout()
264 rfcomm_dlc_put(d); in rfcomm_dlc_timeout()
268 static void rfcomm_dlc_set_timer(struct rfcomm_dlc *d, long timeout) in rfcomm_dlc_set_timer() argument
270 BT_DBG("dlc %p state %ld timeout %ld", d, d->state, timeout); in rfcomm_dlc_set_timer()
272 if (!mod_timer(&d->timer, jiffies + timeout)) in rfcomm_dlc_set_timer()
273 rfcomm_dlc_hold(d); in rfcomm_dlc_set_timer()
276 static void rfcomm_dlc_clear_timer(struct rfcomm_dlc *d) in rfcomm_dlc_clear_timer() argument
278 BT_DBG("dlc %p state %ld", d, d->state); in rfcomm_dlc_clear_timer()
280 if (del_timer(&d->timer)) in rfcomm_dlc_clear_timer()
281 rfcomm_dlc_put(d); in rfcomm_dlc_clear_timer()
284 static void rfcomm_dlc_clear_state(struct rfcomm_dlc *d) in rfcomm_dlc_clear_state() argument
286 BT_DBG("%p", d); in rfcomm_dlc_clear_state()
288 d->state = BT_OPEN; in rfcomm_dlc_clear_state()
289 d->flags = 0; in rfcomm_dlc_clear_state()
290 d->mscex = 0; in rfcomm_dlc_clear_state()
291 d->sec_level = BT_SECURITY_LOW; in rfcomm_dlc_clear_state()
292 d->mtu = RFCOMM_DEFAULT_MTU; in rfcomm_dlc_clear_state()
293 d->v24_sig = RFCOMM_V24_RTC | RFCOMM_V24_RTR | RFCOMM_V24_DV; in rfcomm_dlc_clear_state()
295 d->cfc = RFCOMM_CFC_DISABLED; in rfcomm_dlc_clear_state()
296 d->rx_credits = RFCOMM_DEFAULT_CREDITS; in rfcomm_dlc_clear_state()
301 struct rfcomm_dlc *d = kzalloc(sizeof(*d), prio); in rfcomm_dlc_alloc() local
303 if (!d) in rfcomm_dlc_alloc()
306 timer_setup(&d->timer, rfcomm_dlc_timeout, 0); in rfcomm_dlc_alloc()
308 skb_queue_head_init(&d->tx_queue); in rfcomm_dlc_alloc()
309 mutex_init(&d->lock); in rfcomm_dlc_alloc()
310 refcount_set(&d->refcnt, 1); in rfcomm_dlc_alloc()
312 rfcomm_dlc_clear_state(d); in rfcomm_dlc_alloc()
314 BT_DBG("%p", d); in rfcomm_dlc_alloc()
316 return d; in rfcomm_dlc_alloc()
319 void rfcomm_dlc_free(struct rfcomm_dlc *d) in rfcomm_dlc_free() argument
321 BT_DBG("%p", d); in rfcomm_dlc_free()
323 skb_queue_purge(&d->tx_queue); in rfcomm_dlc_free()
324 kfree(d); in rfcomm_dlc_free()
327 static void rfcomm_dlc_link(struct rfcomm_session *s, struct rfcomm_dlc *d) in rfcomm_dlc_link() argument
329 BT_DBG("dlc %p session %p", d, s); in rfcomm_dlc_link()
332 rfcomm_dlc_hold(d); in rfcomm_dlc_link()
333 list_add(&d->list, &s->dlcs); in rfcomm_dlc_link()
334 d->session = s; in rfcomm_dlc_link()
337 static void rfcomm_dlc_unlink(struct rfcomm_dlc *d) in rfcomm_dlc_unlink() argument
339 struct rfcomm_session *s = d->session; in rfcomm_dlc_unlink()
341 BT_DBG("dlc %p refcnt %d session %p", d, refcount_read(&d->refcnt), s); in rfcomm_dlc_unlink()
343 list_del(&d->list); in rfcomm_dlc_unlink()
344 d->session = NULL; in rfcomm_dlc_unlink()
345 rfcomm_dlc_put(d); in rfcomm_dlc_unlink()
347 if (list_empty(&s->dlcs)) in rfcomm_dlc_unlink()
353 struct rfcomm_dlc *d; in rfcomm_dlc_get() local
355 list_for_each_entry(d, &s->dlcs, list) in rfcomm_dlc_get()
356 if (d->dlci == dlci) in rfcomm_dlc_get()
357 return d; in rfcomm_dlc_get()
367 static int __rfcomm_dlc_open(struct rfcomm_dlc *d, bdaddr_t *src, bdaddr_t *dst, u8 channel) in __rfcomm_dlc_open() argument
373 BT_DBG("dlc %p state %ld %pMR -> %pMR channel %d", in __rfcomm_dlc_open()
374 d, d->state, src, dst, channel); in __rfcomm_dlc_open()
377 return -EINVAL; in __rfcomm_dlc_open()
379 if (d->state != BT_OPEN && d->state != BT_CLOSED) in __rfcomm_dlc_open()
384 s = rfcomm_session_create(src, dst, d->sec_level, &err); in __rfcomm_dlc_open()
393 return -EBUSY; in __rfcomm_dlc_open()
395 rfcomm_dlc_clear_state(d); in __rfcomm_dlc_open()
397 d->dlci = dlci; in __rfcomm_dlc_open()
398 d->addr = __addr(s->initiator, dlci); in __rfcomm_dlc_open()
399 d->priority = 7; in __rfcomm_dlc_open()
401 d->state = BT_CONFIG; in __rfcomm_dlc_open()
402 rfcomm_dlc_link(s, d); in __rfcomm_dlc_open()
404 d->out = 1; in __rfcomm_dlc_open()
406 d->mtu = s->mtu; in __rfcomm_dlc_open()
407 d->cfc = (s->cfc == RFCOMM_CFC_UNKNOWN) ? 0 : s->cfc; in __rfcomm_dlc_open()
409 if (s->state == BT_CONNECTED) { in __rfcomm_dlc_open()
410 if (rfcomm_check_security(d)) in __rfcomm_dlc_open()
411 rfcomm_send_pn(s, 1, d); in __rfcomm_dlc_open()
413 set_bit(RFCOMM_AUTH_PENDING, &d->flags); in __rfcomm_dlc_open()
416 rfcomm_dlc_set_timer(d, RFCOMM_CONN_TIMEOUT); in __rfcomm_dlc_open()
421 int rfcomm_dlc_open(struct rfcomm_dlc *d, bdaddr_t *src, bdaddr_t *dst, u8 channel) in rfcomm_dlc_open() argument
427 r = __rfcomm_dlc_open(d, src, dst, channel); in rfcomm_dlc_open()
433 static void __rfcomm_dlc_disconn(struct rfcomm_dlc *d) in __rfcomm_dlc_disconn() argument
435 struct rfcomm_session *s = d->session; in __rfcomm_dlc_disconn()
437 d->state = BT_DISCONN; in __rfcomm_dlc_disconn()
438 if (skb_queue_empty(&d->tx_queue)) { in __rfcomm_dlc_disconn()
439 rfcomm_send_disc(s, d->dlci); in __rfcomm_dlc_disconn()
440 rfcomm_dlc_set_timer(d, RFCOMM_DISC_TIMEOUT); in __rfcomm_dlc_disconn()
442 rfcomm_queue_disc(d); in __rfcomm_dlc_disconn()
443 rfcomm_dlc_set_timer(d, RFCOMM_DISC_TIMEOUT * 2); in __rfcomm_dlc_disconn()
447 static int __rfcomm_dlc_close(struct rfcomm_dlc *d, int err) in __rfcomm_dlc_close() argument
449 struct rfcomm_session *s = d->session; in __rfcomm_dlc_close()
453 BT_DBG("dlc %p state %ld dlci %d err %d session %p", in __rfcomm_dlc_close()
454 d, d->state, d->dlci, err, s); in __rfcomm_dlc_close()
456 switch (d->state) { in __rfcomm_dlc_close()
461 if (test_and_clear_bit(RFCOMM_DEFER_SETUP, &d->flags)) { in __rfcomm_dlc_close()
462 set_bit(RFCOMM_AUTH_REJECT, &d->flags); in __rfcomm_dlc_close()
468 switch (d->state) { in __rfcomm_dlc_close()
471 __rfcomm_dlc_disconn(d); in __rfcomm_dlc_close()
475 if (s->state != BT_BOUND) { in __rfcomm_dlc_close()
476 __rfcomm_dlc_disconn(d); in __rfcomm_dlc_close()
485 rfcomm_dlc_clear_timer(d); in __rfcomm_dlc_close()
487 rfcomm_dlc_lock(d); in __rfcomm_dlc_close()
488 d->state = BT_CLOSED; in __rfcomm_dlc_close()
489 d->state_change(d, err); in __rfcomm_dlc_close()
490 rfcomm_dlc_unlock(d); in __rfcomm_dlc_close()
492 skb_queue_purge(&d->tx_queue); in __rfcomm_dlc_close()
493 rfcomm_dlc_unlink(d); in __rfcomm_dlc_close()
499 int rfcomm_dlc_close(struct rfcomm_dlc *d, int err) in rfcomm_dlc_close() argument
505 BT_DBG("dlc %p state %ld dlci %d err %d", d, d->state, d->dlci, err); in rfcomm_dlc_close()
509 s = d->session; in rfcomm_dlc_close()
518 list_for_each_entry(d_list, &s->dlcs, list) { in rfcomm_dlc_close()
519 if (d_list == d) { in rfcomm_dlc_close()
520 r = __rfcomm_dlc_close(d, err); in rfcomm_dlc_close()
540 return ERR_PTR(-EINVAL); in rfcomm_dlc_exists()
552 static int rfcomm_dlc_send_frag(struct rfcomm_dlc *d, struct sk_buff *frag) in rfcomm_dlc_send_frag() argument
554 int len = frag->len; in rfcomm_dlc_send_frag()
556 BT_DBG("dlc %p mtu %d len %d", d, d->mtu, len); in rfcomm_dlc_send_frag()
558 if (len > d->mtu) in rfcomm_dlc_send_frag()
559 return -EINVAL; in rfcomm_dlc_send_frag()
561 rfcomm_make_uih(frag, d->addr); in rfcomm_dlc_send_frag()
562 __skb_queue_tail(&d->tx_queue, frag); in rfcomm_dlc_send_frag()
567 int rfcomm_dlc_send(struct rfcomm_dlc *d, struct sk_buff *skb) in rfcomm_dlc_send() argument
573 if (d->state != BT_CONNECTED) in rfcomm_dlc_send()
574 return -ENOTCONN; in rfcomm_dlc_send()
576 frag = skb_shinfo(skb)->frag_list; in rfcomm_dlc_send()
577 skb_shinfo(skb)->frag_list = NULL; in rfcomm_dlc_send()
580 spin_lock_irqsave(&d->tx_queue.lock, flags); in rfcomm_dlc_send()
582 len = rfcomm_dlc_send_frag(d, skb); in rfcomm_dlc_send()
589 next = frag->next; in rfcomm_dlc_send()
591 ret = rfcomm_dlc_send_frag(d, frag); in rfcomm_dlc_send()
601 spin_unlock_irqrestore(&d->tx_queue.lock, flags); in rfcomm_dlc_send()
603 if (len > 0 && !test_bit(RFCOMM_TX_THROTTLED, &d->flags)) in rfcomm_dlc_send()
608 void rfcomm_dlc_send_noerror(struct rfcomm_dlc *d, struct sk_buff *skb) in rfcomm_dlc_send_noerror() argument
610 int len = skb->len; in rfcomm_dlc_send_noerror()
612 BT_DBG("dlc %p mtu %d len %d", d, d->mtu, len); in rfcomm_dlc_send_noerror()
614 rfcomm_make_uih(skb, d->addr); in rfcomm_dlc_send_noerror()
615 skb_queue_tail(&d->tx_queue, skb); in rfcomm_dlc_send_noerror()
617 if (d->state == BT_CONNECTED && in rfcomm_dlc_send_noerror()
618 !test_bit(RFCOMM_TX_THROTTLED, &d->flags)) in rfcomm_dlc_send_noerror()
622 void __rfcomm_dlc_throttle(struct rfcomm_dlc *d) in __rfcomm_dlc_throttle() argument
624 BT_DBG("dlc %p state %ld", d, d->state); in __rfcomm_dlc_throttle()
626 if (!d->cfc) { in __rfcomm_dlc_throttle()
627 d->v24_sig |= RFCOMM_V24_FC; in __rfcomm_dlc_throttle()
628 set_bit(RFCOMM_MSC_PENDING, &d->flags); in __rfcomm_dlc_throttle()
633 void __rfcomm_dlc_unthrottle(struct rfcomm_dlc *d) in __rfcomm_dlc_unthrottle() argument
635 BT_DBG("dlc %p state %ld", d, d->state); in __rfcomm_dlc_unthrottle()
637 if (!d->cfc) { in __rfcomm_dlc_unthrottle()
638 d->v24_sig &= ~RFCOMM_V24_FC; in __rfcomm_dlc_unthrottle()
639 set_bit(RFCOMM_MSC_PENDING, &d->flags); in __rfcomm_dlc_unthrottle()
647 Remote status is provided by dlc->modem_status() callback.
649 int rfcomm_dlc_set_modem_status(struct rfcomm_dlc *d, u8 v24_sig) in rfcomm_dlc_set_modem_status() argument
652 d, d->state, v24_sig); in rfcomm_dlc_set_modem_status()
654 if (test_bit(RFCOMM_RX_THROTTLED, &d->flags)) in rfcomm_dlc_set_modem_status()
659 d->v24_sig = v24_sig; in rfcomm_dlc_set_modem_status()
661 if (!test_and_set_bit(RFCOMM_MSC_PENDING, &d->flags)) in rfcomm_dlc_set_modem_status()
667 int rfcomm_dlc_get_modem_status(struct rfcomm_dlc *d, u8 *v24_sig) in rfcomm_dlc_get_modem_status() argument
670 d, d->state, d->v24_sig); in rfcomm_dlc_get_modem_status()
672 *v24_sig = d->v24_sig; in rfcomm_dlc_get_modem_status()
676 /* ---- RFCOMM sessions ---- */
686 timer_setup(&s->timer, rfcomm_session_timeout, 0); in rfcomm_session_add()
688 INIT_LIST_HEAD(&s->dlcs); in rfcomm_session_add()
689 s->state = state; in rfcomm_session_add()
690 s->sock = sock; in rfcomm_session_add()
692 s->mtu = RFCOMM_DEFAULT_MTU; in rfcomm_session_add()
693 s->cfc = disable_cfc ? RFCOMM_CFC_DISABLED : RFCOMM_CFC_UNKNOWN; in rfcomm_session_add()
703 list_add(&s->list, &session_list); in rfcomm_session_add()
710 int state = s->state; in rfcomm_session_del()
712 BT_DBG("session %p state %ld", s, s->state); in rfcomm_session_del()
714 list_del(&s->list); in rfcomm_session_del()
717 sock_release(s->sock); in rfcomm_session_del()
731 chan = l2cap_pi(s->sock->sk)->chan; in rfcomm_session_get()
733 if ((!bacmp(src, BDADDR_ANY) || !bacmp(&chan->src, src)) && in rfcomm_session_get()
734 !bacmp(&chan->dst, dst)) in rfcomm_session_get()
743 struct rfcomm_dlc *d, *n; in rfcomm_session_close() local
745 s->state = BT_CLOSED; in rfcomm_session_close()
747 BT_DBG("session %p state %ld err %d", s, s->state, err); in rfcomm_session_close()
750 list_for_each_entry_safe(d, n, &s->dlcs, list) { in rfcomm_session_close()
751 d->state = BT_CLOSED; in rfcomm_session_close()
752 __rfcomm_dlc_close(d, err); in rfcomm_session_close()
769 BT_DBG("%pMR -> %pMR", src, dst); in rfcomm_session_create()
785 sk = sock->sk; in rfcomm_session_create()
788 l2cap_pi(sk)->chan->imtu = 0; in rfcomm_session_create()
789 l2cap_pi(sk)->chan->sec_level = sec_level; in rfcomm_session_create()
791 l2cap_pi(sk)->chan->mode = L2CAP_MODE_ERTM; in rfcomm_session_create()
796 *err = -ENOMEM; in rfcomm_session_create()
800 s->initiator = 1; in rfcomm_session_create()
808 if (*err == 0 || *err == -EINPROGRESS) in rfcomm_session_create()
820 struct l2cap_chan *chan = l2cap_pi(s->sock->sk)->chan; in rfcomm_session_getaddr()
822 bacpy(src, &chan->src); in rfcomm_session_getaddr()
824 bacpy(dst, &chan->dst); in rfcomm_session_getaddr()
827 /* ---- RFCOMM frame sending ---- */
833 BT_DBG("session %p len %d", s, len); in rfcomm_send_frame()
837 return kernel_sendmsg(s->sock, &msg, &iv, 1, len); in rfcomm_send_frame()
842 BT_DBG("%p cmd %u", s, cmd->ctrl); in rfcomm_send_cmd()
851 BT_DBG("%p dlci %d", s, dlci); in rfcomm_send_sabm()
853 cmd.addr = __addr(s->initiator, dlci); in rfcomm_send_sabm()
865 BT_DBG("%p dlci %d", s, dlci); in rfcomm_send_ua()
867 cmd.addr = __addr(!s->initiator, dlci); in rfcomm_send_ua()
879 BT_DBG("%p dlci %d", s, dlci); in rfcomm_send_disc()
881 cmd.addr = __addr(s->initiator, dlci); in rfcomm_send_disc()
889 static int rfcomm_queue_disc(struct rfcomm_dlc *d) in rfcomm_queue_disc() argument
894 BT_DBG("dlc %p dlci %d", d, d->dlci); in rfcomm_queue_disc()
898 return -ENOMEM; in rfcomm_queue_disc()
901 cmd->addr = d->addr; in rfcomm_queue_disc()
902 cmd->ctrl = __ctrl(RFCOMM_DISC, 1); in rfcomm_queue_disc()
903 cmd->len = __len8(0); in rfcomm_queue_disc()
904 cmd->fcs = __fcs2((u8 *) cmd); in rfcomm_queue_disc()
906 skb_queue_tail(&d->tx_queue, skb); in rfcomm_queue_disc()
915 BT_DBG("%p dlci %d", s, dlci); in rfcomm_send_dm()
917 cmd.addr = __addr(!s->initiator, dlci); in rfcomm_send_dm()
931 BT_DBG("%p cr %d type %d", s, cr, type); in rfcomm_send_nsc()
934 hdr->addr = __addr(s->initiator, 0); in rfcomm_send_nsc()
935 hdr->ctrl = __ctrl(RFCOMM_UIH, 0); in rfcomm_send_nsc()
936 hdr->len = __len8(sizeof(*mcc) + 1); in rfcomm_send_nsc()
939 mcc->type = __mcc_type(0, RFCOMM_NSC); in rfcomm_send_nsc()
940 mcc->len = __len8(1); in rfcomm_send_nsc()
947 return rfcomm_send_frame(s, buf, ptr - buf); in rfcomm_send_nsc()
950 static int rfcomm_send_pn(struct rfcomm_session *s, int cr, struct rfcomm_dlc *d) in rfcomm_send_pn() argument
957 BT_DBG("%p cr %d dlci %d mtu %d", s, cr, d->dlci, d->mtu); in rfcomm_send_pn()
960 hdr->addr = __addr(s->initiator, 0); in rfcomm_send_pn()
961 hdr->ctrl = __ctrl(RFCOMM_UIH, 0); in rfcomm_send_pn()
962 hdr->len = __len8(sizeof(*mcc) + sizeof(*pn)); in rfcomm_send_pn()
965 mcc->type = __mcc_type(cr, RFCOMM_PN); in rfcomm_send_pn()
966 mcc->len = __len8(sizeof(*pn)); in rfcomm_send_pn()
969 pn->dlci = d->dlci; in rfcomm_send_pn()
970 pn->priority = d->priority; in rfcomm_send_pn()
971 pn->ack_timer = 0; in rfcomm_send_pn()
972 pn->max_retrans = 0; in rfcomm_send_pn()
974 if (s->cfc) { in rfcomm_send_pn()
975 pn->flow_ctrl = cr ? 0xf0 : 0xe0; in rfcomm_send_pn()
976 pn->credits = RFCOMM_DEFAULT_CREDITS; in rfcomm_send_pn()
978 pn->flow_ctrl = 0; in rfcomm_send_pn()
979 pn->credits = 0; in rfcomm_send_pn()
983 pn->mtu = cpu_to_le16(channel_mtu); in rfcomm_send_pn()
985 pn->mtu = cpu_to_le16(d->mtu); in rfcomm_send_pn()
989 return rfcomm_send_frame(s, buf, ptr - buf); in rfcomm_send_pn()
1002 BT_DBG("%p cr %d dlci %d bit_r 0x%x data_b 0x%x stop_b 0x%x parity 0x%x" in rfcomm_send_rpn()
1008 hdr->addr = __addr(s->initiator, 0); in rfcomm_send_rpn()
1009 hdr->ctrl = __ctrl(RFCOMM_UIH, 0); in rfcomm_send_rpn()
1010 hdr->len = __len8(sizeof(*mcc) + sizeof(*rpn)); in rfcomm_send_rpn()
1013 mcc->type = __mcc_type(cr, RFCOMM_RPN); in rfcomm_send_rpn()
1014 mcc->len = __len8(sizeof(*rpn)); in rfcomm_send_rpn()
1017 rpn->dlci = __addr(1, dlci); in rfcomm_send_rpn()
1018 rpn->bit_rate = bit_rate; in rfcomm_send_rpn()
1019 rpn->line_settings = __rpn_line_settings(data_bits, stop_bits, parity); in rfcomm_send_rpn()
1020 rpn->flow_ctrl = flow_ctrl_settings; in rfcomm_send_rpn()
1021 rpn->xon_char = xon_char; in rfcomm_send_rpn()
1022 rpn->xoff_char = xoff_char; in rfcomm_send_rpn()
1023 rpn->param_mask = cpu_to_le16(param_mask); in rfcomm_send_rpn()
1027 return rfcomm_send_frame(s, buf, ptr - buf); in rfcomm_send_rpn()
1037 BT_DBG("%p cr %d status 0x%x", s, cr, status); in rfcomm_send_rls()
1040 hdr->addr = __addr(s->initiator, 0); in rfcomm_send_rls()
1041 hdr->ctrl = __ctrl(RFCOMM_UIH, 0); in rfcomm_send_rls()
1042 hdr->len = __len8(sizeof(*mcc) + sizeof(*rls)); in rfcomm_send_rls()
1045 mcc->type = __mcc_type(cr, RFCOMM_RLS); in rfcomm_send_rls()
1046 mcc->len = __len8(sizeof(*rls)); in rfcomm_send_rls()
1049 rls->dlci = __addr(1, dlci); in rfcomm_send_rls()
1050 rls->status = status; in rfcomm_send_rls()
1054 return rfcomm_send_frame(s, buf, ptr - buf); in rfcomm_send_rls()
1064 BT_DBG("%p cr %d v24 0x%x", s, cr, v24_sig); in rfcomm_send_msc()
1067 hdr->addr = __addr(s->initiator, 0); in rfcomm_send_msc()
1068 hdr->ctrl = __ctrl(RFCOMM_UIH, 0); in rfcomm_send_msc()
1069 hdr->len = __len8(sizeof(*mcc) + sizeof(*msc)); in rfcomm_send_msc()
1072 mcc->type = __mcc_type(cr, RFCOMM_MSC); in rfcomm_send_msc()
1073 mcc->len = __len8(sizeof(*msc)); in rfcomm_send_msc()
1076 msc->dlci = __addr(1, dlci); in rfcomm_send_msc()
1077 msc->v24_sig = v24_sig | 0x01; in rfcomm_send_msc()
1081 return rfcomm_send_frame(s, buf, ptr - buf); in rfcomm_send_msc()
1090 BT_DBG("%p cr %d", s, cr); in rfcomm_send_fcoff()
1093 hdr->addr = __addr(s->initiator, 0); in rfcomm_send_fcoff()
1094 hdr->ctrl = __ctrl(RFCOMM_UIH, 0); in rfcomm_send_fcoff()
1095 hdr->len = __len8(sizeof(*mcc)); in rfcomm_send_fcoff()
1098 mcc->type = __mcc_type(cr, RFCOMM_FCOFF); in rfcomm_send_fcoff()
1099 mcc->len = __len8(0); in rfcomm_send_fcoff()
1103 return rfcomm_send_frame(s, buf, ptr - buf); in rfcomm_send_fcoff()
1112 BT_DBG("%p cr %d", s, cr); in rfcomm_send_fcon()
1115 hdr->addr = __addr(s->initiator, 0); in rfcomm_send_fcon()
1116 hdr->ctrl = __ctrl(RFCOMM_UIH, 0); in rfcomm_send_fcon()
1117 hdr->len = __len8(sizeof(*mcc)); in rfcomm_send_fcon()
1120 mcc->type = __mcc_type(cr, RFCOMM_FCON); in rfcomm_send_fcon()
1121 mcc->len = __len8(0); in rfcomm_send_fcon()
1125 return rfcomm_send_frame(s, buf, ptr - buf); in rfcomm_send_fcon()
1130 struct socket *sock = s->sock; in rfcomm_send_test()
1136 return -EINVAL; in rfcomm_send_test()
1138 BT_DBG("%p cr %d", s, cr); in rfcomm_send_test()
1140 hdr[0] = __addr(s->initiator, 0); in rfcomm_send_test()
1165 BT_DBG("%p addr %d credits %d", s, addr, credits); in rfcomm_send_credits()
1168 hdr->addr = addr; in rfcomm_send_credits()
1169 hdr->ctrl = __ctrl(RFCOMM_UIH, 1); in rfcomm_send_credits()
1170 hdr->len = __len8(0); in rfcomm_send_credits()
1176 return rfcomm_send_frame(s, buf, ptr - buf); in rfcomm_send_credits()
1182 int len = skb->len; in rfcomm_make_uih()
1187 put_unaligned(cpu_to_le16(__len16(len)), (__le16 *) &hdr->len); in rfcomm_make_uih()
1190 hdr->len = __len8(len); in rfcomm_make_uih()
1192 hdr->addr = addr; in rfcomm_make_uih()
1193 hdr->ctrl = __ctrl(RFCOMM_UIH, 0); in rfcomm_make_uih()
1199 /* ---- RFCOMM frame reception ---- */
1202 BT_DBG("session %p state %ld dlci %d", s, s->state, dlci); in rfcomm_recv_ua()
1206 struct rfcomm_dlc *d = rfcomm_dlc_get(s, dlci); in rfcomm_recv_ua() local
1207 if (!d) { in rfcomm_recv_ua()
1212 switch (d->state) { in rfcomm_recv_ua()
1214 rfcomm_dlc_clear_timer(d); in rfcomm_recv_ua()
1216 rfcomm_dlc_lock(d); in rfcomm_recv_ua()
1217 d->state = BT_CONNECTED; in rfcomm_recv_ua()
1218 d->state_change(d, 0); in rfcomm_recv_ua()
1219 rfcomm_dlc_unlock(d); in rfcomm_recv_ua()
1221 rfcomm_send_msc(s, 1, dlci, d->v24_sig); in rfcomm_recv_ua()
1225 d->state = BT_CLOSED; in rfcomm_recv_ua()
1226 __rfcomm_dlc_close(d, 0); in rfcomm_recv_ua()
1228 if (list_empty(&s->dlcs)) { in rfcomm_recv_ua()
1229 s->state = BT_DISCONN; in rfcomm_recv_ua()
1238 switch (s->state) { in rfcomm_recv_ua()
1240 s->state = BT_CONNECTED; in rfcomm_recv_ua()
1256 BT_DBG("session %p state %ld dlci %d", s, s->state, dlci); in rfcomm_recv_dm()
1260 struct rfcomm_dlc *d = rfcomm_dlc_get(s, dlci); in rfcomm_recv_dm() local
1261 if (d) { in rfcomm_recv_dm()
1262 if (d->state == BT_CONNECT || d->state == BT_CONFIG) in rfcomm_recv_dm()
1267 d->state = BT_CLOSED; in rfcomm_recv_dm()
1268 __rfcomm_dlc_close(d, err); in rfcomm_recv_dm()
1271 if (s->state == BT_CONNECT) in rfcomm_recv_dm()
1286 BT_DBG("session %p state %ld dlci %d", s, s->state, dlci); in rfcomm_recv_disc()
1289 struct rfcomm_dlc *d = rfcomm_dlc_get(s, dlci); in rfcomm_recv_disc() local
1290 if (d) { in rfcomm_recv_disc()
1293 if (d->state == BT_CONNECT || d->state == BT_CONFIG) in rfcomm_recv_disc()
1298 d->state = BT_CLOSED; in rfcomm_recv_disc()
1299 __rfcomm_dlc_close(d, err); in rfcomm_recv_disc()
1306 if (s->state == BT_CONNECT) in rfcomm_recv_disc()
1316 void rfcomm_dlc_accept(struct rfcomm_dlc *d) in rfcomm_dlc_accept() argument
1318 struct sock *sk = d->session->sock->sk; in rfcomm_dlc_accept()
1319 struct l2cap_conn *conn = l2cap_pi(sk)->chan->conn; in rfcomm_dlc_accept()
1321 BT_DBG("dlc %p", d); in rfcomm_dlc_accept()
1323 rfcomm_send_ua(d->session, d->dlci); in rfcomm_dlc_accept()
1325 rfcomm_dlc_clear_timer(d); in rfcomm_dlc_accept()
1327 rfcomm_dlc_lock(d); in rfcomm_dlc_accept()
1328 d->state = BT_CONNECTED; in rfcomm_dlc_accept()
1329 d->state_change(d, 0); in rfcomm_dlc_accept()
1330 rfcomm_dlc_unlock(d); in rfcomm_dlc_accept()
1332 if (d->role_switch) in rfcomm_dlc_accept()
1333 hci_conn_switch_role(conn->hcon, 0x00); in rfcomm_dlc_accept()
1335 rfcomm_send_msc(d->session, 1, d->dlci, d->v24_sig); in rfcomm_dlc_accept()
1338 static void rfcomm_check_accept(struct rfcomm_dlc *d) in rfcomm_check_accept() argument
1340 if (rfcomm_check_security(d)) { in rfcomm_check_accept()
1341 if (d->defer_setup) { in rfcomm_check_accept()
1342 set_bit(RFCOMM_DEFER_SETUP, &d->flags); in rfcomm_check_accept()
1343 rfcomm_dlc_set_timer(d, RFCOMM_AUTH_TIMEOUT); in rfcomm_check_accept()
1345 rfcomm_dlc_lock(d); in rfcomm_check_accept()
1346 d->state = BT_CONNECT2; in rfcomm_check_accept()
1347 d->state_change(d, 0); in rfcomm_check_accept()
1348 rfcomm_dlc_unlock(d); in rfcomm_check_accept()
1350 rfcomm_dlc_accept(d); in rfcomm_check_accept()
1352 set_bit(RFCOMM_AUTH_PENDING, &d->flags); in rfcomm_check_accept()
1353 rfcomm_dlc_set_timer(d, RFCOMM_AUTH_TIMEOUT); in rfcomm_check_accept()
1359 struct rfcomm_dlc *d; in rfcomm_recv_sabm() local
1362 BT_DBG("session %p state %ld dlci %d", s, s->state, dlci); in rfcomm_recv_sabm()
1367 if (s->state == BT_OPEN) { in rfcomm_recv_sabm()
1368 s->state = BT_CONNECTED; in rfcomm_recv_sabm()
1375 d = rfcomm_dlc_get(s, dlci); in rfcomm_recv_sabm()
1376 if (d) { in rfcomm_recv_sabm()
1377 if (d->state == BT_OPEN) { in rfcomm_recv_sabm()
1379 rfcomm_check_accept(d); in rfcomm_recv_sabm()
1386 if (rfcomm_connect_ind(s, channel, &d)) { in rfcomm_recv_sabm()
1387 d->dlci = dlci; in rfcomm_recv_sabm()
1388 d->addr = __addr(s->initiator, dlci); in rfcomm_recv_sabm()
1389 rfcomm_dlc_link(s, d); in rfcomm_recv_sabm()
1391 rfcomm_check_accept(d); in rfcomm_recv_sabm()
1399 static int rfcomm_apply_pn(struct rfcomm_dlc *d, int cr, struct rfcomm_pn *pn) in rfcomm_apply_pn() argument
1401 struct rfcomm_session *s = d->session; in rfcomm_apply_pn()
1403 BT_DBG("dlc %p state %ld dlci %d mtu %d fc 0x%x credits %d", in rfcomm_apply_pn()
1404 d, d->state, d->dlci, pn->mtu, pn->flow_ctrl, pn->credits); in rfcomm_apply_pn()
1406 if ((pn->flow_ctrl == 0xf0 && s->cfc != RFCOMM_CFC_DISABLED) || in rfcomm_apply_pn()
1407 pn->flow_ctrl == 0xe0) { in rfcomm_apply_pn()
1408 d->cfc = RFCOMM_CFC_ENABLED; in rfcomm_apply_pn()
1409 d->tx_credits = pn->credits; in rfcomm_apply_pn()
1411 d->cfc = RFCOMM_CFC_DISABLED; in rfcomm_apply_pn()
1412 set_bit(RFCOMM_TX_THROTTLED, &d->flags); in rfcomm_apply_pn()
1415 if (s->cfc == RFCOMM_CFC_UNKNOWN) in rfcomm_apply_pn()
1416 s->cfc = d->cfc; in rfcomm_apply_pn()
1418 d->priority = pn->priority; in rfcomm_apply_pn()
1420 d->mtu = __le16_to_cpu(pn->mtu); in rfcomm_apply_pn()
1422 if (cr && d->mtu > s->mtu) in rfcomm_apply_pn()
1423 d->mtu = s->mtu; in rfcomm_apply_pn()
1430 struct rfcomm_pn *pn = (void *) skb->data; in rfcomm_recv_pn()
1431 struct rfcomm_dlc *d; in rfcomm_recv_pn() local
1432 u8 dlci = pn->dlci; in rfcomm_recv_pn()
1434 BT_DBG("session %p state %ld dlci %d", s, s->state, dlci); in rfcomm_recv_pn()
1439 d = rfcomm_dlc_get(s, dlci); in rfcomm_recv_pn()
1440 if (d) { in rfcomm_recv_pn()
1443 rfcomm_apply_pn(d, cr, pn); in rfcomm_recv_pn()
1444 rfcomm_send_pn(s, 0, d); in rfcomm_recv_pn()
1447 switch (d->state) { in rfcomm_recv_pn()
1449 rfcomm_apply_pn(d, cr, pn); in rfcomm_recv_pn()
1451 d->state = BT_CONNECT; in rfcomm_recv_pn()
1452 rfcomm_send_sabm(s, d->dlci); in rfcomm_recv_pn()
1464 if (rfcomm_connect_ind(s, channel, &d)) { in rfcomm_recv_pn()
1465 d->dlci = dlci; in rfcomm_recv_pn()
1466 d->addr = __addr(s->initiator, dlci); in rfcomm_recv_pn()
1467 rfcomm_dlc_link(s, d); in rfcomm_recv_pn()
1469 rfcomm_apply_pn(d, cr, pn); in rfcomm_recv_pn()
1471 d->state = BT_OPEN; in rfcomm_recv_pn()
1472 rfcomm_send_pn(s, 0, d); in rfcomm_recv_pn()
1482 struct rfcomm_rpn *rpn = (void *) skb->data; in rfcomm_recv_rpn()
1483 u8 dlci = __get_dlci(rpn->dlci); in rfcomm_recv_rpn()
1494 BT_DBG("dlci %d cr %d len 0x%x bitr 0x%x line 0x%x flow 0x%x xonc 0x%x xoffc 0x%x pm 0x%x", in rfcomm_recv_rpn()
1495 dlci, cr, len, rpn->bit_rate, rpn->line_settings, rpn->flow_ctrl, in rfcomm_recv_rpn()
1496 rpn->xon_char, rpn->xoff_char, rpn->param_mask); in rfcomm_recv_rpn()
1516 if (rpn->param_mask & cpu_to_le16(RFCOMM_RPN_PM_BITRATE)) { in rfcomm_recv_rpn()
1517 bit_rate = rpn->bit_rate; in rfcomm_recv_rpn()
1525 if (rpn->param_mask & cpu_to_le16(RFCOMM_RPN_PM_DATA)) { in rfcomm_recv_rpn()
1526 data_bits = __get_rpn_data_bits(rpn->line_settings); in rfcomm_recv_rpn()
1534 if (rpn->param_mask & cpu_to_le16(RFCOMM_RPN_PM_STOP)) { in rfcomm_recv_rpn()
1535 stop_bits = __get_rpn_stop_bits(rpn->line_settings); in rfcomm_recv_rpn()
1543 if (rpn->param_mask & cpu_to_le16(RFCOMM_RPN_PM_PARITY)) { in rfcomm_recv_rpn()
1544 parity = __get_rpn_parity(rpn->line_settings); in rfcomm_recv_rpn()
1552 if (rpn->param_mask & cpu_to_le16(RFCOMM_RPN_PM_FLOW)) { in rfcomm_recv_rpn()
1553 flow_ctrl = rpn->flow_ctrl; in rfcomm_recv_rpn()
1561 if (rpn->param_mask & cpu_to_le16(RFCOMM_RPN_PM_XON)) { in rfcomm_recv_rpn()
1562 xon_char = rpn->xon_char; in rfcomm_recv_rpn()
1570 if (rpn->param_mask & cpu_to_le16(RFCOMM_RPN_PM_XOFF)) { in rfcomm_recv_rpn()
1571 xoff_char = rpn->xoff_char; in rfcomm_recv_rpn()
1588 struct rfcomm_rls *rls = (void *) skb->data; in rfcomm_recv_rls()
1589 u8 dlci = __get_dlci(rls->dlci); in rfcomm_recv_rls()
1591 BT_DBG("dlci %d cr %d status 0x%x", dlci, cr, rls->status); in rfcomm_recv_rls()
1597 * for now it's sufficient just to reply -- Bluetooth 1.1 says it's in rfcomm_recv_rls()
1600 rfcomm_send_rls(s, 0, dlci, rls->status); in rfcomm_recv_rls()
1607 struct rfcomm_msc *msc = (void *) skb->data; in rfcomm_recv_msc()
1608 struct rfcomm_dlc *d; in rfcomm_recv_msc() local
1609 u8 dlci = __get_dlci(msc->dlci); in rfcomm_recv_msc()
1611 BT_DBG("dlci %d cr %d v24 0x%x", dlci, cr, msc->v24_sig); in rfcomm_recv_msc()
1613 d = rfcomm_dlc_get(s, dlci); in rfcomm_recv_msc()
1614 if (!d) in rfcomm_recv_msc()
1618 if (msc->v24_sig & RFCOMM_V24_FC && !d->cfc) in rfcomm_recv_msc()
1619 set_bit(RFCOMM_TX_THROTTLED, &d->flags); in rfcomm_recv_msc()
1621 clear_bit(RFCOMM_TX_THROTTLED, &d->flags); in rfcomm_recv_msc()
1623 rfcomm_dlc_lock(d); in rfcomm_recv_msc()
1625 d->remote_v24_sig = msc->v24_sig; in rfcomm_recv_msc()
1627 if (d->modem_status) in rfcomm_recv_msc()
1628 d->modem_status(d, msc->v24_sig); in rfcomm_recv_msc()
1630 rfcomm_dlc_unlock(d); in rfcomm_recv_msc()
1632 rfcomm_send_msc(s, 0, dlci, msc->v24_sig); in rfcomm_recv_msc()
1634 d->mscex |= RFCOMM_MSCEX_RX; in rfcomm_recv_msc()
1636 d->mscex |= RFCOMM_MSCEX_TX; in rfcomm_recv_msc()
1643 struct rfcomm_mcc *mcc = (void *) skb->data; in rfcomm_recv_mcc()
1646 cr = __test_cr(mcc->type); in rfcomm_recv_mcc()
1647 type = __get_mcc_type(mcc->type); in rfcomm_recv_mcc()
1648 len = __get_mcc_len(mcc->len); in rfcomm_recv_mcc()
1650 BT_DBG("%p type 0x%x cr %d", s, type, cr); in rfcomm_recv_mcc()
1673 set_bit(RFCOMM_TX_THROTTLED, &s->flags); in rfcomm_recv_mcc()
1680 clear_bit(RFCOMM_TX_THROTTLED, &s->flags); in rfcomm_recv_mcc()
1687 rfcomm_send_test(s, 0, skb->data, skb->len); in rfcomm_recv_mcc()
1703 struct rfcomm_dlc *d; in rfcomm_recv_data() local
1705 BT_DBG("session %p state %ld dlci %d pf %d", s, s->state, dlci, pf); in rfcomm_recv_data()
1707 d = rfcomm_dlc_get(s, dlci); in rfcomm_recv_data()
1708 if (!d) { in rfcomm_recv_data()
1713 if (pf && d->cfc) { in rfcomm_recv_data()
1714 u8 credits = *(u8 *) skb->data; skb_pull(skb, 1); in rfcomm_recv_data()
1716 d->tx_credits += credits; in rfcomm_recv_data()
1717 if (d->tx_credits) in rfcomm_recv_data()
1718 clear_bit(RFCOMM_TX_THROTTLED, &d->flags); in rfcomm_recv_data()
1721 if (skb->len && d->state == BT_CONNECTED) { in rfcomm_recv_data()
1722 rfcomm_dlc_lock(d); in rfcomm_recv_data()
1723 d->rx_credits--; in rfcomm_recv_data()
1724 d->data_ready(d, skb); in rfcomm_recv_data()
1725 rfcomm_dlc_unlock(d); in rfcomm_recv_data()
1737 struct rfcomm_hdr *hdr = (void *) skb->data; in rfcomm_recv_frame()
1746 dlci = __get_dlci(hdr->addr); in rfcomm_recv_frame()
1747 type = __get_type(hdr->ctrl); in rfcomm_recv_frame()
1750 skb->len--; skb->tail--; in rfcomm_recv_frame()
1753 if (__check_fcs(skb->data, type, fcs)) { in rfcomm_recv_frame()
1759 if (__test_ea(hdr->len)) in rfcomm_recv_frame()
1766 if (__test_pf(hdr->ctrl)) in rfcomm_recv_frame()
1771 if (__test_pf(hdr->ctrl)) in rfcomm_recv_frame()
1776 if (__test_pf(hdr->ctrl)) in rfcomm_recv_frame()
1786 rfcomm_recv_data(s, dlci, __test_pf(hdr->ctrl), skb); in rfcomm_recv_frame()
1800 /* ---- Connection and data processing ---- */
1804 struct rfcomm_dlc *d, *n; in rfcomm_process_connect() local
1806 BT_DBG("session %p state %ld", s, s->state); in rfcomm_process_connect()
1808 list_for_each_entry_safe(d, n, &s->dlcs, list) { in rfcomm_process_connect()
1809 if (d->state == BT_CONFIG) { in rfcomm_process_connect()
1810 d->mtu = s->mtu; in rfcomm_process_connect()
1811 if (rfcomm_check_security(d)) { in rfcomm_process_connect()
1812 rfcomm_send_pn(s, 1, d); in rfcomm_process_connect()
1814 set_bit(RFCOMM_AUTH_PENDING, &d->flags); in rfcomm_process_connect()
1815 rfcomm_dlc_set_timer(d, RFCOMM_AUTH_TIMEOUT); in rfcomm_process_connect()
1824 static int rfcomm_process_tx(struct rfcomm_dlc *d) in rfcomm_process_tx() argument
1829 BT_DBG("dlc %p state %ld cfc %d rx_credits %d tx_credits %d", in rfcomm_process_tx()
1830 d, d->state, d->cfc, d->rx_credits, d->tx_credits); in rfcomm_process_tx()
1833 if (test_and_clear_bit(RFCOMM_MSC_PENDING, &d->flags)) in rfcomm_process_tx()
1834 rfcomm_send_msc(d->session, 1, d->dlci, d->v24_sig); in rfcomm_process_tx()
1836 if (d->cfc) { in rfcomm_process_tx()
1839 if (!test_bit(RFCOMM_RX_THROTTLED, &d->flags) && in rfcomm_process_tx()
1840 d->rx_credits <= (d->cfc >> 2)) { in rfcomm_process_tx()
1841 rfcomm_send_credits(d->session, d->addr, d->cfc - d->rx_credits); in rfcomm_process_tx()
1842 d->rx_credits = d->cfc; in rfcomm_process_tx()
1847 d->tx_credits = 5; in rfcomm_process_tx()
1850 if (test_bit(RFCOMM_TX_THROTTLED, &d->flags)) in rfcomm_process_tx()
1851 return skb_queue_len(&d->tx_queue); in rfcomm_process_tx()
1853 while (d->tx_credits && (skb = skb_dequeue(&d->tx_queue))) { in rfcomm_process_tx()
1854 err = rfcomm_send_frame(d->session, skb->data, skb->len); in rfcomm_process_tx()
1856 skb_queue_head(&d->tx_queue, skb); in rfcomm_process_tx()
1860 d->tx_credits--; in rfcomm_process_tx()
1863 if (d->cfc && !d->tx_credits) { in rfcomm_process_tx()
1866 set_bit(RFCOMM_TX_THROTTLED, &d->flags); in rfcomm_process_tx()
1869 return skb_queue_len(&d->tx_queue); in rfcomm_process_tx()
1874 struct rfcomm_dlc *d, *n; in rfcomm_process_dlcs() local
1876 BT_DBG("session %p state %ld", s, s->state); in rfcomm_process_dlcs()
1878 list_for_each_entry_safe(d, n, &s->dlcs, list) { in rfcomm_process_dlcs()
1879 if (test_bit(RFCOMM_TIMED_OUT, &d->flags)) { in rfcomm_process_dlcs()
1880 __rfcomm_dlc_close(d, ETIMEDOUT); in rfcomm_process_dlcs()
1884 if (test_bit(RFCOMM_ENC_DROP, &d->flags)) { in rfcomm_process_dlcs()
1885 __rfcomm_dlc_close(d, ECONNREFUSED); in rfcomm_process_dlcs()
1889 if (test_and_clear_bit(RFCOMM_AUTH_ACCEPT, &d->flags)) { in rfcomm_process_dlcs()
1890 rfcomm_dlc_clear_timer(d); in rfcomm_process_dlcs()
1891 if (d->out) { in rfcomm_process_dlcs()
1892 rfcomm_send_pn(s, 1, d); in rfcomm_process_dlcs()
1893 rfcomm_dlc_set_timer(d, RFCOMM_CONN_TIMEOUT); in rfcomm_process_dlcs()
1895 if (d->defer_setup) { in rfcomm_process_dlcs()
1896 set_bit(RFCOMM_DEFER_SETUP, &d->flags); in rfcomm_process_dlcs()
1897 rfcomm_dlc_set_timer(d, RFCOMM_AUTH_TIMEOUT); in rfcomm_process_dlcs()
1899 rfcomm_dlc_lock(d); in rfcomm_process_dlcs()
1900 d->state = BT_CONNECT2; in rfcomm_process_dlcs()
1901 d->state_change(d, 0); in rfcomm_process_dlcs()
1902 rfcomm_dlc_unlock(d); in rfcomm_process_dlcs()
1904 rfcomm_dlc_accept(d); in rfcomm_process_dlcs()
1907 } else if (test_and_clear_bit(RFCOMM_AUTH_REJECT, &d->flags)) { in rfcomm_process_dlcs()
1908 rfcomm_dlc_clear_timer(d); in rfcomm_process_dlcs()
1909 if (!d->out) in rfcomm_process_dlcs()
1910 rfcomm_send_dm(s, d->dlci); in rfcomm_process_dlcs()
1912 d->state = BT_CLOSED; in rfcomm_process_dlcs()
1913 __rfcomm_dlc_close(d, ECONNREFUSED); in rfcomm_process_dlcs()
1917 if (test_bit(RFCOMM_SEC_PENDING, &d->flags)) in rfcomm_process_dlcs()
1920 if (test_bit(RFCOMM_TX_THROTTLED, &s->flags)) in rfcomm_process_dlcs()
1923 if ((d->state == BT_CONNECTED || d->state == BT_DISCONN) && in rfcomm_process_dlcs()
1924 d->mscex == RFCOMM_MSCEX_OK) in rfcomm_process_dlcs()
1925 rfcomm_process_tx(d); in rfcomm_process_dlcs()
1931 struct socket *sock = s->sock; in rfcomm_process_rx()
1932 struct sock *sk = sock->sk; in rfcomm_process_rx()
1935 BT_DBG("session %p state %ld qlen %d", s, s->state, skb_queue_len(&sk->sk_receive_queue)); in rfcomm_process_rx()
1938 while ((skb = skb_dequeue(&sk->sk_receive_queue))) { in rfcomm_process_rx()
1949 if (s && (sk->sk_state == BT_CLOSED)) in rfcomm_process_rx()
1950 s = rfcomm_session_close(s, sk->sk_err); in rfcomm_process_rx()
1957 struct socket *sock = s->sock, *nsock; in rfcomm_accept_connection()
1962 if (list_empty(&bt_sk(sock->sk)->accept_q)) in rfcomm_accept_connection()
1972 nsock->sk->sk_data_ready = rfcomm_l2data_ready; in rfcomm_accept_connection()
1973 nsock->sk->sk_state_change = rfcomm_l2state_change; in rfcomm_accept_connection()
1979 s->mtu = min(l2cap_pi(nsock->sk)->chan->omtu, in rfcomm_accept_connection()
1980 l2cap_pi(nsock->sk)->chan->imtu) - 5; in rfcomm_accept_connection()
1989 struct sock *sk = s->sock->sk; in rfcomm_check_connection()
1991 BT_DBG("%p state %ld", s, s->state); in rfcomm_check_connection()
1993 switch (sk->sk_state) { in rfcomm_check_connection()
1995 s->state = BT_CONNECT; in rfcomm_check_connection()
1999 s->mtu = min(l2cap_pi(sk)->chan->omtu, l2cap_pi(sk)->chan->imtu) - 5; in rfcomm_check_connection()
2005 s = rfcomm_session_close(s, sk->sk_err); in rfcomm_check_connection()
2018 if (test_and_clear_bit(RFCOMM_TIMED_OUT, &s->flags)) { in rfcomm_process_sessions()
2019 s->state = BT_DISCONN; in rfcomm_process_sessions()
2024 switch (s->state) { in rfcomm_process_sessions()
2056 BT_ERR("Create socket failed %d", err); in rfcomm_add_listener()
2068 BT_ERR("Bind failed %d", err); in rfcomm_add_listener()
2073 sk = sock->sk; in rfcomm_add_listener()
2076 l2cap_pi(sk)->chan->imtu = 0; in rfcomm_add_listener()
2082 BT_ERR("Listen failed %d", err); in rfcomm_add_listener()
2089 err = -ENOMEM; in rfcomm_add_listener()
2114 set_user_nice(current, -10); in rfcomm_run()
2136 struct rfcomm_dlc *d, *n; in rfcomm_security_cfm() local
2140 s = rfcomm_session_get(&conn->hdev->bdaddr, &conn->dst); in rfcomm_security_cfm()
2144 list_for_each_entry_safe(d, n, &s->dlcs, list) { in rfcomm_security_cfm()
2145 if (test_and_clear_bit(RFCOMM_SEC_PENDING, &d->flags)) { in rfcomm_security_cfm()
2146 rfcomm_dlc_clear_timer(d); in rfcomm_security_cfm()
2148 set_bit(RFCOMM_ENC_DROP, &d->flags); in rfcomm_security_cfm()
2153 if (d->state == BT_CONNECTED && !status && encrypt == 0x00) { in rfcomm_security_cfm()
2154 if (d->sec_level == BT_SECURITY_MEDIUM) { in rfcomm_security_cfm()
2155 set_bit(RFCOMM_SEC_PENDING, &d->flags); in rfcomm_security_cfm()
2156 rfcomm_dlc_set_timer(d, RFCOMM_AUTH_TIMEOUT); in rfcomm_security_cfm()
2158 } else if (d->sec_level == BT_SECURITY_HIGH || in rfcomm_security_cfm()
2159 d->sec_level == BT_SECURITY_FIPS) { in rfcomm_security_cfm()
2160 set_bit(RFCOMM_ENC_DROP, &d->flags); in rfcomm_security_cfm()
2165 if (!test_and_clear_bit(RFCOMM_AUTH_PENDING, &d->flags)) in rfcomm_security_cfm()
2168 if (!status && hci_conn_check_secure(conn, d->sec_level)) in rfcomm_security_cfm()
2169 set_bit(RFCOMM_AUTH_ACCEPT, &d->flags); in rfcomm_security_cfm()
2171 set_bit(RFCOMM_AUTH_REJECT, &d->flags); in rfcomm_security_cfm()
2189 struct l2cap_chan *chan = l2cap_pi(s->sock->sk)->chan; in rfcomm_dlc_debugfs_show()
2190 struct rfcomm_dlc *d; in rfcomm_dlc_debugfs_show() local
2191 list_for_each_entry(d, &s->dlcs, list) { in rfcomm_dlc_debugfs_show()
2192 seq_printf(f, "%pMR %pMR %ld %d %d %d %d\n", in rfcomm_dlc_debugfs_show()
2193 &chan->src, &chan->dst, in rfcomm_dlc_debugfs_show()
2194 d->state, d->dlci, d->mtu, in rfcomm_dlc_debugfs_show()
2195 d->rx_credits, d->tx_credits); in rfcomm_dlc_debugfs_show()
2208 /* ---- Initialization ---- */
2281 MODULE_ALIAS("bt-proto-3");