Lines Matching +full:- +full:chn +full:- +full:disabled

44 static int channel_mtu = -1;
75 /* ---- RFCOMM frame parsing macros ---- */
83 #define __session_dir(s) ((s)->initiator ? 0x00 : 0x01)
87 #define __dlci(dir, chn) (((chn & 0x1f) << 1) | dir) argument
111 /* ---- RFCOMM FCS computation ---- */
113 /* reversed, 8-bit, poly=0x07 */
162 return 0xff - __crc(data); in __fcs()
168 return 0xff - rfcomm_crc_table[__crc(data) ^ data[2]]; in __fcs2()
182 /* ---- L2CAP callbacks ---- */
185 BT_DBG("%p state %d", sk, sk->sk_state); in rfcomm_l2state_change()
205 struct sock *sk = (*sock)->sk; in rfcomm_l2sock_create()
206 sk->sk_data_ready = rfcomm_l2data_ready; in rfcomm_l2sock_create()
207 sk->sk_state_change = rfcomm_l2state_change; in rfcomm_l2sock_create()
214 struct sock *sk = d->session->sock->sk; in rfcomm_check_security()
215 struct l2cap_conn *conn = l2cap_pi(sk)->chan->conn; in rfcomm_check_security()
219 switch (d->sec_level) { in rfcomm_check_security()
232 return hci_conn_security(conn->hcon, d->sec_level, auth_type, in rfcomm_check_security()
233 d->out); in rfcomm_check_security()
240 BT_DBG("session %p state %ld", s, s->state); in rfcomm_session_timeout()
242 set_bit(RFCOMM_TIMED_OUT, &s->flags); in rfcomm_session_timeout()
248 BT_DBG("session %p state %ld timeout %ld", s, s->state, timeout); in rfcomm_session_set_timer()
250 mod_timer(&s->timer, jiffies + timeout); in rfcomm_session_set_timer()
255 BT_DBG("session %p state %ld", s, s->state); in rfcomm_session_clear_timer()
257 del_timer_sync(&s->timer); in rfcomm_session_clear_timer()
260 /* ---- RFCOMM DLCs ---- */
265 BT_DBG("dlc %p state %ld", d, d->state); in rfcomm_dlc_timeout()
267 set_bit(RFCOMM_TIMED_OUT, &d->flags); in rfcomm_dlc_timeout()
274 BT_DBG("dlc %p state %ld timeout %ld", d, d->state, timeout); in rfcomm_dlc_set_timer()
276 if (!mod_timer(&d->timer, jiffies + timeout)) in rfcomm_dlc_set_timer()
282 BT_DBG("dlc %p state %ld", d, d->state); in rfcomm_dlc_clear_timer()
284 if (del_timer(&d->timer)) in rfcomm_dlc_clear_timer()
292 d->state = BT_OPEN; in rfcomm_dlc_clear_state()
293 d->flags = 0; in rfcomm_dlc_clear_state()
294 d->mscex = 0; in rfcomm_dlc_clear_state()
295 d->sec_level = BT_SECURITY_LOW; in rfcomm_dlc_clear_state()
296 d->mtu = RFCOMM_DEFAULT_MTU; in rfcomm_dlc_clear_state()
297 d->v24_sig = RFCOMM_V24_RTC | RFCOMM_V24_RTR | RFCOMM_V24_DV; in rfcomm_dlc_clear_state()
299 d->cfc = RFCOMM_CFC_DISABLED; in rfcomm_dlc_clear_state()
300 d->rx_credits = RFCOMM_DEFAULT_CREDITS; in rfcomm_dlc_clear_state()
310 timer_setup(&d->timer, rfcomm_dlc_timeout, 0); in rfcomm_dlc_alloc()
312 skb_queue_head_init(&d->tx_queue); in rfcomm_dlc_alloc()
313 mutex_init(&d->lock); in rfcomm_dlc_alloc()
314 refcount_set(&d->refcnt, 1); in rfcomm_dlc_alloc()
327 skb_queue_purge(&d->tx_queue); in rfcomm_dlc_free()
337 list_add(&d->list, &s->dlcs); in rfcomm_dlc_link()
338 d->session = s; in rfcomm_dlc_link()
343 struct rfcomm_session *s = d->session; in rfcomm_dlc_unlink()
345 BT_DBG("dlc %p refcnt %d session %p", d, refcount_read(&d->refcnt), s); in rfcomm_dlc_unlink()
347 list_del(&d->list); in rfcomm_dlc_unlink()
348 d->session = NULL; in rfcomm_dlc_unlink()
351 if (list_empty(&s->dlcs)) in rfcomm_dlc_unlink()
359 list_for_each_entry(d, &s->dlcs, list) in rfcomm_dlc_get()
360 if (d->dlci == dlci) in rfcomm_dlc_get()
377 BT_DBG("dlc %p state %ld %pMR -> %pMR channel %d", in __rfcomm_dlc_open()
378 d, d->state, src, dst, channel); in __rfcomm_dlc_open()
381 return -EINVAL; in __rfcomm_dlc_open()
383 if (d->state != BT_OPEN && d->state != BT_CLOSED) in __rfcomm_dlc_open()
388 s = rfcomm_session_create(src, dst, d->sec_level, &err); in __rfcomm_dlc_open()
397 return -EBUSY; in __rfcomm_dlc_open()
401 d->dlci = dlci; in __rfcomm_dlc_open()
402 d->addr = __addr(s->initiator, dlci); in __rfcomm_dlc_open()
403 d->priority = 7; in __rfcomm_dlc_open()
405 d->state = BT_CONFIG; in __rfcomm_dlc_open()
408 d->out = 1; in __rfcomm_dlc_open()
410 d->mtu = s->mtu; in __rfcomm_dlc_open()
411 d->cfc = (s->cfc == RFCOMM_CFC_UNKNOWN) ? 0 : s->cfc; in __rfcomm_dlc_open()
413 if (s->state == BT_CONNECTED) { in __rfcomm_dlc_open()
417 set_bit(RFCOMM_AUTH_PENDING, &d->flags); in __rfcomm_dlc_open()
439 struct rfcomm_session *s = d->session; in __rfcomm_dlc_disconn()
441 d->state = BT_DISCONN; in __rfcomm_dlc_disconn()
442 if (skb_queue_empty(&d->tx_queue)) { in __rfcomm_dlc_disconn()
443 rfcomm_send_disc(s, d->dlci); in __rfcomm_dlc_disconn()
453 struct rfcomm_session *s = d->session; in __rfcomm_dlc_close()
458 d, d->state, d->dlci, err, s); in __rfcomm_dlc_close()
460 switch (d->state) { in __rfcomm_dlc_close()
465 if (test_and_clear_bit(RFCOMM_DEFER_SETUP, &d->flags)) { in __rfcomm_dlc_close()
466 set_bit(RFCOMM_AUTH_REJECT, &d->flags); in __rfcomm_dlc_close()
472 switch (d->state) { in __rfcomm_dlc_close()
479 if (s->state != BT_BOUND) { in __rfcomm_dlc_close()
492 d->state = BT_CLOSED; in __rfcomm_dlc_close()
493 d->state_change(d, err); in __rfcomm_dlc_close()
496 skb_queue_purge(&d->tx_queue); in __rfcomm_dlc_close()
509 BT_DBG("dlc %p state %ld dlci %d err %d", d, d->state, d->dlci, err); in rfcomm_dlc_close()
513 s = d->session; in rfcomm_dlc_close()
522 list_for_each_entry(d_list, &s->dlcs, list) { in rfcomm_dlc_close()
544 return ERR_PTR(-EINVAL); in rfcomm_dlc_exists()
558 int len = frag->len; in rfcomm_dlc_send_frag()
560 BT_DBG("dlc %p mtu %d len %d", d, d->mtu, len); in rfcomm_dlc_send_frag()
562 if (len > d->mtu) in rfcomm_dlc_send_frag()
563 return -EINVAL; in rfcomm_dlc_send_frag()
565 rfcomm_make_uih(frag, d->addr); in rfcomm_dlc_send_frag()
566 __skb_queue_tail(&d->tx_queue, frag); in rfcomm_dlc_send_frag()
577 if (d->state != BT_CONNECTED) in rfcomm_dlc_send()
578 return -ENOTCONN; in rfcomm_dlc_send()
580 frag = skb_shinfo(skb)->frag_list; in rfcomm_dlc_send()
581 skb_shinfo(skb)->frag_list = NULL; in rfcomm_dlc_send()
584 spin_lock_irqsave(&d->tx_queue.lock, flags); in rfcomm_dlc_send()
593 next = frag->next; in rfcomm_dlc_send()
605 spin_unlock_irqrestore(&d->tx_queue.lock, flags); in rfcomm_dlc_send()
607 if (len > 0 && !test_bit(RFCOMM_TX_THROTTLED, &d->flags)) in rfcomm_dlc_send()
614 int len = skb->len; in rfcomm_dlc_send_noerror()
616 BT_DBG("dlc %p mtu %d len %d", d, d->mtu, len); in rfcomm_dlc_send_noerror()
618 rfcomm_make_uih(skb, d->addr); in rfcomm_dlc_send_noerror()
619 skb_queue_tail(&d->tx_queue, skb); in rfcomm_dlc_send_noerror()
621 if (d->state == BT_CONNECTED && in rfcomm_dlc_send_noerror()
622 !test_bit(RFCOMM_TX_THROTTLED, &d->flags)) in rfcomm_dlc_send_noerror()
628 BT_DBG("dlc %p state %ld", d, d->state); in __rfcomm_dlc_throttle()
630 if (!d->cfc) { in __rfcomm_dlc_throttle()
631 d->v24_sig |= RFCOMM_V24_FC; in __rfcomm_dlc_throttle()
632 set_bit(RFCOMM_MSC_PENDING, &d->flags); in __rfcomm_dlc_throttle()
639 BT_DBG("dlc %p state %ld", d, d->state); in __rfcomm_dlc_unthrottle()
641 if (!d->cfc) { in __rfcomm_dlc_unthrottle()
642 d->v24_sig &= ~RFCOMM_V24_FC; in __rfcomm_dlc_unthrottle()
643 set_bit(RFCOMM_MSC_PENDING, &d->flags); in __rfcomm_dlc_unthrottle()
651 Remote status is provided by dlc->modem_status() callback.
656 d, d->state, v24_sig); in rfcomm_dlc_set_modem_status()
658 if (test_bit(RFCOMM_RX_THROTTLED, &d->flags)) in rfcomm_dlc_set_modem_status()
663 d->v24_sig = v24_sig; in rfcomm_dlc_set_modem_status()
665 if (!test_and_set_bit(RFCOMM_MSC_PENDING, &d->flags)) in rfcomm_dlc_set_modem_status()
674 d, d->state, d->v24_sig); in rfcomm_dlc_get_modem_status()
676 *v24_sig = d->v24_sig; in rfcomm_dlc_get_modem_status()
680 /* ---- RFCOMM sessions ---- */
690 timer_setup(&s->timer, rfcomm_session_timeout, 0); in rfcomm_session_add()
692 INIT_LIST_HEAD(&s->dlcs); in rfcomm_session_add()
693 s->state = state; in rfcomm_session_add()
694 s->sock = sock; in rfcomm_session_add()
696 s->mtu = RFCOMM_DEFAULT_MTU; in rfcomm_session_add()
697 s->cfc = disable_cfc ? RFCOMM_CFC_DISABLED : RFCOMM_CFC_UNKNOWN; in rfcomm_session_add()
707 list_add(&s->list, &session_list); in rfcomm_session_add()
714 int state = s->state; in rfcomm_session_del()
716 BT_DBG("session %p state %ld", s, s->state); in rfcomm_session_del()
718 list_del(&s->list); in rfcomm_session_del()
721 sock_release(s->sock); in rfcomm_session_del()
735 chan = l2cap_pi(s->sock->sk)->chan; in rfcomm_session_get()
737 if ((!bacmp(src, BDADDR_ANY) || !bacmp(&chan->src, src)) && in rfcomm_session_get()
738 !bacmp(&chan->dst, dst)) in rfcomm_session_get()
749 s->state = BT_CLOSED; in rfcomm_session_close()
751 BT_DBG("session %p state %ld err %d", s, s->state, err); in rfcomm_session_close()
754 list_for_each_entry_safe(d, n, &s->dlcs, list) { in rfcomm_session_close()
755 d->state = BT_CLOSED; in rfcomm_session_close()
773 BT_DBG("%pMR -> %pMR", src, dst); in rfcomm_session_create()
789 sk = sock->sk; in rfcomm_session_create()
792 l2cap_pi(sk)->chan->imtu = 0; in rfcomm_session_create()
793 l2cap_pi(sk)->chan->sec_level = sec_level; in rfcomm_session_create()
795 l2cap_pi(sk)->chan->mode = L2CAP_MODE_ERTM; in rfcomm_session_create()
800 *err = -ENOMEM; in rfcomm_session_create()
804 s->initiator = 1; in rfcomm_session_create()
812 if (*err == 0 || *err == -EINPROGRESS) in rfcomm_session_create()
824 struct l2cap_chan *chan = l2cap_pi(s->sock->sk)->chan; in rfcomm_session_getaddr()
826 bacpy(src, &chan->src); in rfcomm_session_getaddr()
828 bacpy(dst, &chan->dst); in rfcomm_session_getaddr()
831 /* ---- RFCOMM frame sending ---- */
841 return kernel_sendmsg(s->sock, &msg, &iv, 1, len); in rfcomm_send_frame()
846 BT_DBG("%p cmd %u", s, cmd->ctrl); in rfcomm_send_cmd()
857 cmd.addr = __addr(s->initiator, dlci); in rfcomm_send_sabm()
871 cmd.addr = __addr(!s->initiator, dlci); in rfcomm_send_ua()
885 cmd.addr = __addr(s->initiator, dlci); in rfcomm_send_disc()
898 BT_DBG("dlc %p dlci %d", d, d->dlci); in rfcomm_queue_disc()
902 return -ENOMEM; in rfcomm_queue_disc()
905 cmd->addr = d->addr; in rfcomm_queue_disc()
906 cmd->ctrl = __ctrl(RFCOMM_DISC, 1); in rfcomm_queue_disc()
907 cmd->len = __len8(0); in rfcomm_queue_disc()
908 cmd->fcs = __fcs2((u8 *) cmd); in rfcomm_queue_disc()
910 skb_queue_tail(&d->tx_queue, skb); in rfcomm_queue_disc()
921 cmd.addr = __addr(!s->initiator, dlci); in rfcomm_send_dm()
938 hdr->addr = __addr(s->initiator, 0); in rfcomm_send_nsc()
939 hdr->ctrl = __ctrl(RFCOMM_UIH, 0); in rfcomm_send_nsc()
940 hdr->len = __len8(sizeof(*mcc) + 1); in rfcomm_send_nsc()
943 mcc->type = __mcc_type(0, RFCOMM_NSC); in rfcomm_send_nsc()
944 mcc->len = __len8(1); in rfcomm_send_nsc()
951 return rfcomm_send_frame(s, buf, ptr - buf); in rfcomm_send_nsc()
961 BT_DBG("%p cr %d dlci %d mtu %d", s, cr, d->dlci, d->mtu); in rfcomm_send_pn()
964 hdr->addr = __addr(s->initiator, 0); in rfcomm_send_pn()
965 hdr->ctrl = __ctrl(RFCOMM_UIH, 0); in rfcomm_send_pn()
966 hdr->len = __len8(sizeof(*mcc) + sizeof(*pn)); in rfcomm_send_pn()
969 mcc->type = __mcc_type(cr, RFCOMM_PN); in rfcomm_send_pn()
970 mcc->len = __len8(sizeof(*pn)); in rfcomm_send_pn()
973 pn->dlci = d->dlci; in rfcomm_send_pn()
974 pn->priority = d->priority; in rfcomm_send_pn()
975 pn->ack_timer = 0; in rfcomm_send_pn()
976 pn->max_retrans = 0; in rfcomm_send_pn()
978 if (s->cfc) { in rfcomm_send_pn()
979 pn->flow_ctrl = cr ? 0xf0 : 0xe0; in rfcomm_send_pn()
980 pn->credits = RFCOMM_DEFAULT_CREDITS; in rfcomm_send_pn()
982 pn->flow_ctrl = 0; in rfcomm_send_pn()
983 pn->credits = 0; in rfcomm_send_pn()
987 pn->mtu = cpu_to_le16(channel_mtu); in rfcomm_send_pn()
989 pn->mtu = cpu_to_le16(d->mtu); in rfcomm_send_pn()
993 return rfcomm_send_frame(s, buf, ptr - buf); in rfcomm_send_pn()
1012 hdr->addr = __addr(s->initiator, 0); in rfcomm_send_rpn()
1013 hdr->ctrl = __ctrl(RFCOMM_UIH, 0); in rfcomm_send_rpn()
1014 hdr->len = __len8(sizeof(*mcc) + sizeof(*rpn)); in rfcomm_send_rpn()
1017 mcc->type = __mcc_type(cr, RFCOMM_RPN); in rfcomm_send_rpn()
1018 mcc->len = __len8(sizeof(*rpn)); in rfcomm_send_rpn()
1021 rpn->dlci = __addr(1, dlci); in rfcomm_send_rpn()
1022 rpn->bit_rate = bit_rate; in rfcomm_send_rpn()
1023 rpn->line_settings = __rpn_line_settings(data_bits, stop_bits, parity); in rfcomm_send_rpn()
1024 rpn->flow_ctrl = flow_ctrl_settings; in rfcomm_send_rpn()
1025 rpn->xon_char = xon_char; in rfcomm_send_rpn()
1026 rpn->xoff_char = xoff_char; in rfcomm_send_rpn()
1027 rpn->param_mask = cpu_to_le16(param_mask); in rfcomm_send_rpn()
1031 return rfcomm_send_frame(s, buf, ptr - buf); in rfcomm_send_rpn()
1044 hdr->addr = __addr(s->initiator, 0); in rfcomm_send_rls()
1045 hdr->ctrl = __ctrl(RFCOMM_UIH, 0); in rfcomm_send_rls()
1046 hdr->len = __len8(sizeof(*mcc) + sizeof(*rls)); in rfcomm_send_rls()
1049 mcc->type = __mcc_type(cr, RFCOMM_RLS); in rfcomm_send_rls()
1050 mcc->len = __len8(sizeof(*rls)); in rfcomm_send_rls()
1053 rls->dlci = __addr(1, dlci); in rfcomm_send_rls()
1054 rls->status = status; in rfcomm_send_rls()
1058 return rfcomm_send_frame(s, buf, ptr - buf); in rfcomm_send_rls()
1071 hdr->addr = __addr(s->initiator, 0); in rfcomm_send_msc()
1072 hdr->ctrl = __ctrl(RFCOMM_UIH, 0); in rfcomm_send_msc()
1073 hdr->len = __len8(sizeof(*mcc) + sizeof(*msc)); in rfcomm_send_msc()
1076 mcc->type = __mcc_type(cr, RFCOMM_MSC); in rfcomm_send_msc()
1077 mcc->len = __len8(sizeof(*msc)); in rfcomm_send_msc()
1080 msc->dlci = __addr(1, dlci); in rfcomm_send_msc()
1081 msc->v24_sig = v24_sig | 0x01; in rfcomm_send_msc()
1085 return rfcomm_send_frame(s, buf, ptr - buf); in rfcomm_send_msc()
1097 hdr->addr = __addr(s->initiator, 0); in rfcomm_send_fcoff()
1098 hdr->ctrl = __ctrl(RFCOMM_UIH, 0); in rfcomm_send_fcoff()
1099 hdr->len = __len8(sizeof(*mcc)); in rfcomm_send_fcoff()
1102 mcc->type = __mcc_type(cr, RFCOMM_FCOFF); in rfcomm_send_fcoff()
1103 mcc->len = __len8(0); in rfcomm_send_fcoff()
1107 return rfcomm_send_frame(s, buf, ptr - buf); in rfcomm_send_fcoff()
1119 hdr->addr = __addr(s->initiator, 0); in rfcomm_send_fcon()
1120 hdr->ctrl = __ctrl(RFCOMM_UIH, 0); in rfcomm_send_fcon()
1121 hdr->len = __len8(sizeof(*mcc)); in rfcomm_send_fcon()
1124 mcc->type = __mcc_type(cr, RFCOMM_FCON); in rfcomm_send_fcon()
1125 mcc->len = __len8(0); in rfcomm_send_fcon()
1129 return rfcomm_send_frame(s, buf, ptr - buf); in rfcomm_send_fcon()
1134 struct socket *sock = s->sock; in rfcomm_send_test()
1140 return -EINVAL; in rfcomm_send_test()
1144 hdr[0] = __addr(s->initiator, 0); in rfcomm_send_test()
1172 hdr->addr = addr; in rfcomm_send_credits()
1173 hdr->ctrl = __ctrl(RFCOMM_UIH, 1); in rfcomm_send_credits()
1174 hdr->len = __len8(0); in rfcomm_send_credits()
1180 return rfcomm_send_frame(s, buf, ptr - buf); in rfcomm_send_credits()
1186 int len = skb->len; in rfcomm_make_uih()
1191 put_unaligned(cpu_to_le16(__len16(len)), (__le16 *) &hdr->len); in rfcomm_make_uih()
1194 hdr->len = __len8(len); in rfcomm_make_uih()
1196 hdr->addr = addr; in rfcomm_make_uih()
1197 hdr->ctrl = __ctrl(RFCOMM_UIH, 0); in rfcomm_make_uih()
1203 /* ---- RFCOMM frame reception ---- */
1206 BT_DBG("session %p state %ld dlci %d", s, s->state, dlci); in rfcomm_recv_ua()
1216 switch (d->state) { in rfcomm_recv_ua()
1221 d->state = BT_CONNECTED; in rfcomm_recv_ua()
1222 d->state_change(d, 0); in rfcomm_recv_ua()
1225 rfcomm_send_msc(s, 1, dlci, d->v24_sig); in rfcomm_recv_ua()
1229 d->state = BT_CLOSED; in rfcomm_recv_ua()
1232 if (list_empty(&s->dlcs)) { in rfcomm_recv_ua()
1233 s->state = BT_DISCONN; in rfcomm_recv_ua()
1242 switch (s->state) { in rfcomm_recv_ua()
1244 s->state = BT_CONNECTED; in rfcomm_recv_ua()
1260 BT_DBG("session %p state %ld dlci %d", s, s->state, dlci); in rfcomm_recv_dm()
1266 if (d->state == BT_CONNECT || d->state == BT_CONFIG) in rfcomm_recv_dm()
1271 d->state = BT_CLOSED; in rfcomm_recv_dm()
1275 if (s->state == BT_CONNECT) in rfcomm_recv_dm()
1290 BT_DBG("session %p state %ld dlci %d", s, s->state, dlci); in rfcomm_recv_disc()
1297 if (d->state == BT_CONNECT || d->state == BT_CONFIG) in rfcomm_recv_disc()
1302 d->state = BT_CLOSED; in rfcomm_recv_disc()
1310 if (s->state == BT_CONNECT) in rfcomm_recv_disc()
1322 struct sock *sk = d->session->sock->sk; in rfcomm_dlc_accept()
1323 struct l2cap_conn *conn = l2cap_pi(sk)->chan->conn; in rfcomm_dlc_accept()
1327 rfcomm_send_ua(d->session, d->dlci); in rfcomm_dlc_accept()
1332 d->state = BT_CONNECTED; in rfcomm_dlc_accept()
1333 d->state_change(d, 0); in rfcomm_dlc_accept()
1336 if (d->role_switch) in rfcomm_dlc_accept()
1337 hci_conn_switch_role(conn->hcon, 0x00); in rfcomm_dlc_accept()
1339 rfcomm_send_msc(d->session, 1, d->dlci, d->v24_sig); in rfcomm_dlc_accept()
1345 if (d->defer_setup) { in rfcomm_check_accept()
1346 set_bit(RFCOMM_DEFER_SETUP, &d->flags); in rfcomm_check_accept()
1350 d->state = BT_CONNECT2; in rfcomm_check_accept()
1351 d->state_change(d, 0); in rfcomm_check_accept()
1356 set_bit(RFCOMM_AUTH_PENDING, &d->flags); in rfcomm_check_accept()
1366 BT_DBG("session %p state %ld dlci %d", s, s->state, dlci); in rfcomm_recv_sabm()
1371 if (s->state == BT_OPEN) { in rfcomm_recv_sabm()
1372 s->state = BT_CONNECTED; in rfcomm_recv_sabm()
1381 if (d->state == BT_OPEN) { in rfcomm_recv_sabm()
1391 d->dlci = dlci; in rfcomm_recv_sabm()
1392 d->addr = __addr(s->initiator, dlci); in rfcomm_recv_sabm()
1405 struct rfcomm_session *s = d->session; in rfcomm_apply_pn()
1408 d, d->state, d->dlci, pn->mtu, pn->flow_ctrl, pn->credits); in rfcomm_apply_pn()
1410 if ((pn->flow_ctrl == 0xf0 && s->cfc != RFCOMM_CFC_DISABLED) || in rfcomm_apply_pn()
1411 pn->flow_ctrl == 0xe0) { in rfcomm_apply_pn()
1412 d->cfc = RFCOMM_CFC_ENABLED; in rfcomm_apply_pn()
1413 d->tx_credits = pn->credits; in rfcomm_apply_pn()
1415 d->cfc = RFCOMM_CFC_DISABLED; in rfcomm_apply_pn()
1416 set_bit(RFCOMM_TX_THROTTLED, &d->flags); in rfcomm_apply_pn()
1419 if (s->cfc == RFCOMM_CFC_UNKNOWN) in rfcomm_apply_pn()
1420 s->cfc = d->cfc; in rfcomm_apply_pn()
1422 d->priority = pn->priority; in rfcomm_apply_pn()
1424 d->mtu = __le16_to_cpu(pn->mtu); in rfcomm_apply_pn()
1426 if (cr && d->mtu > s->mtu) in rfcomm_apply_pn()
1427 d->mtu = s->mtu; in rfcomm_apply_pn()
1434 struct rfcomm_pn *pn = (void *) skb->data; in rfcomm_recv_pn()
1436 u8 dlci = pn->dlci; in rfcomm_recv_pn()
1438 BT_DBG("session %p state %ld dlci %d", s, s->state, dlci); in rfcomm_recv_pn()
1451 switch (d->state) { in rfcomm_recv_pn()
1455 d->state = BT_CONNECT; in rfcomm_recv_pn()
1456 rfcomm_send_sabm(s, d->dlci); in rfcomm_recv_pn()
1469 d->dlci = dlci; in rfcomm_recv_pn()
1470 d->addr = __addr(s->initiator, dlci); in rfcomm_recv_pn()
1475 d->state = BT_OPEN; in rfcomm_recv_pn()
1486 struct rfcomm_rpn *rpn = (void *) skb->data; in rfcomm_recv_rpn()
1487 u8 dlci = __get_dlci(rpn->dlci); in rfcomm_recv_rpn()
1499 dlci, cr, len, rpn->bit_rate, rpn->line_settings, rpn->flow_ctrl, in rfcomm_recv_rpn()
1500 rpn->xon_char, rpn->xoff_char, rpn->param_mask); in rfcomm_recv_rpn()
1520 if (rpn->param_mask & cpu_to_le16(RFCOMM_RPN_PM_BITRATE)) { in rfcomm_recv_rpn()
1521 bit_rate = rpn->bit_rate; in rfcomm_recv_rpn()
1529 if (rpn->param_mask & cpu_to_le16(RFCOMM_RPN_PM_DATA)) { in rfcomm_recv_rpn()
1530 data_bits = __get_rpn_data_bits(rpn->line_settings); in rfcomm_recv_rpn()
1538 if (rpn->param_mask & cpu_to_le16(RFCOMM_RPN_PM_STOP)) { in rfcomm_recv_rpn()
1539 stop_bits = __get_rpn_stop_bits(rpn->line_settings); in rfcomm_recv_rpn()
1547 if (rpn->param_mask & cpu_to_le16(RFCOMM_RPN_PM_PARITY)) { in rfcomm_recv_rpn()
1548 parity = __get_rpn_parity(rpn->line_settings); in rfcomm_recv_rpn()
1556 if (rpn->param_mask & cpu_to_le16(RFCOMM_RPN_PM_FLOW)) { in rfcomm_recv_rpn()
1557 flow_ctrl = rpn->flow_ctrl; in rfcomm_recv_rpn()
1565 if (rpn->param_mask & cpu_to_le16(RFCOMM_RPN_PM_XON)) { in rfcomm_recv_rpn()
1566 xon_char = rpn->xon_char; in rfcomm_recv_rpn()
1574 if (rpn->param_mask & cpu_to_le16(RFCOMM_RPN_PM_XOFF)) { in rfcomm_recv_rpn()
1575 xoff_char = rpn->xoff_char; in rfcomm_recv_rpn()
1592 struct rfcomm_rls *rls = (void *) skb->data; in rfcomm_recv_rls()
1593 u8 dlci = __get_dlci(rls->dlci); in rfcomm_recv_rls()
1595 BT_DBG("dlci %d cr %d status 0x%x", dlci, cr, rls->status); in rfcomm_recv_rls()
1601 * for now it's sufficient just to reply -- Bluetooth 1.1 says it's in rfcomm_recv_rls()
1604 rfcomm_send_rls(s, 0, dlci, rls->status); in rfcomm_recv_rls()
1611 struct rfcomm_msc *msc = (void *) skb->data; in rfcomm_recv_msc()
1613 u8 dlci = __get_dlci(msc->dlci); in rfcomm_recv_msc()
1615 BT_DBG("dlci %d cr %d v24 0x%x", dlci, cr, msc->v24_sig); in rfcomm_recv_msc()
1622 if (msc->v24_sig & RFCOMM_V24_FC && !d->cfc) in rfcomm_recv_msc()
1623 set_bit(RFCOMM_TX_THROTTLED, &d->flags); in rfcomm_recv_msc()
1625 clear_bit(RFCOMM_TX_THROTTLED, &d->flags); in rfcomm_recv_msc()
1629 d->remote_v24_sig = msc->v24_sig; in rfcomm_recv_msc()
1631 if (d->modem_status) in rfcomm_recv_msc()
1632 d->modem_status(d, msc->v24_sig); in rfcomm_recv_msc()
1636 rfcomm_send_msc(s, 0, dlci, msc->v24_sig); in rfcomm_recv_msc()
1638 d->mscex |= RFCOMM_MSCEX_RX; in rfcomm_recv_msc()
1640 d->mscex |= RFCOMM_MSCEX_TX; in rfcomm_recv_msc()
1647 struct rfcomm_mcc *mcc = (void *) skb->data; in rfcomm_recv_mcc()
1650 cr = __test_cr(mcc->type); in rfcomm_recv_mcc()
1651 type = __get_mcc_type(mcc->type); in rfcomm_recv_mcc()
1652 len = __get_mcc_len(mcc->len); in rfcomm_recv_mcc()
1677 set_bit(RFCOMM_TX_THROTTLED, &s->flags); in rfcomm_recv_mcc()
1684 clear_bit(RFCOMM_TX_THROTTLED, &s->flags); in rfcomm_recv_mcc()
1691 rfcomm_send_test(s, 0, skb->data, skb->len); in rfcomm_recv_mcc()
1709 BT_DBG("session %p state %ld dlci %d pf %d", s, s->state, dlci, pf); in rfcomm_recv_data()
1717 if (pf && d->cfc) { in rfcomm_recv_data()
1718 u8 credits = *(u8 *) skb->data; skb_pull(skb, 1); in rfcomm_recv_data()
1720 d->tx_credits += credits; in rfcomm_recv_data()
1721 if (d->tx_credits) in rfcomm_recv_data()
1722 clear_bit(RFCOMM_TX_THROTTLED, &d->flags); in rfcomm_recv_data()
1725 if (skb->len && d->state == BT_CONNECTED) { in rfcomm_recv_data()
1727 d->rx_credits--; in rfcomm_recv_data()
1728 d->data_ready(d, skb); in rfcomm_recv_data()
1741 struct rfcomm_hdr *hdr = (void *) skb->data; in rfcomm_recv_frame()
1750 dlci = __get_dlci(hdr->addr); in rfcomm_recv_frame()
1751 type = __get_type(hdr->ctrl); in rfcomm_recv_frame()
1754 skb->len--; skb->tail--; in rfcomm_recv_frame()
1757 if (__check_fcs(skb->data, type, fcs)) { in rfcomm_recv_frame()
1763 if (__test_ea(hdr->len)) in rfcomm_recv_frame()
1770 if (__test_pf(hdr->ctrl)) in rfcomm_recv_frame()
1775 if (__test_pf(hdr->ctrl)) in rfcomm_recv_frame()
1780 if (__test_pf(hdr->ctrl)) in rfcomm_recv_frame()
1790 rfcomm_recv_data(s, dlci, __test_pf(hdr->ctrl), skb); in rfcomm_recv_frame()
1804 /* ---- Connection and data processing ---- */
1810 BT_DBG("session %p state %ld", s, s->state); in rfcomm_process_connect()
1812 list_for_each_entry_safe(d, n, &s->dlcs, list) { in rfcomm_process_connect()
1813 if (d->state == BT_CONFIG) { in rfcomm_process_connect()
1814 d->mtu = s->mtu; in rfcomm_process_connect()
1818 set_bit(RFCOMM_AUTH_PENDING, &d->flags); in rfcomm_process_connect()
1834 d, d->state, d->cfc, d->rx_credits, d->tx_credits); in rfcomm_process_tx()
1837 if (test_and_clear_bit(RFCOMM_MSC_PENDING, &d->flags)) in rfcomm_process_tx()
1838 rfcomm_send_msc(d->session, 1, d->dlci, d->v24_sig); in rfcomm_process_tx()
1840 if (d->cfc) { in rfcomm_process_tx()
1843 if (!test_bit(RFCOMM_RX_THROTTLED, &d->flags) && in rfcomm_process_tx()
1844 d->rx_credits <= (d->cfc >> 2)) { in rfcomm_process_tx()
1845 rfcomm_send_credits(d->session, d->addr, d->cfc - d->rx_credits); in rfcomm_process_tx()
1846 d->rx_credits = d->cfc; in rfcomm_process_tx()
1849 /* CFC disabled. in rfcomm_process_tx()
1851 d->tx_credits = 5; in rfcomm_process_tx()
1854 if (test_bit(RFCOMM_TX_THROTTLED, &d->flags)) in rfcomm_process_tx()
1855 return skb_queue_len(&d->tx_queue); in rfcomm_process_tx()
1857 while (d->tx_credits && (skb = skb_dequeue(&d->tx_queue))) { in rfcomm_process_tx()
1858 err = rfcomm_send_frame(d->session, skb->data, skb->len); in rfcomm_process_tx()
1860 skb_queue_head(&d->tx_queue, skb); in rfcomm_process_tx()
1864 d->tx_credits--; in rfcomm_process_tx()
1867 if (d->cfc && !d->tx_credits) { in rfcomm_process_tx()
1870 set_bit(RFCOMM_TX_THROTTLED, &d->flags); in rfcomm_process_tx()
1873 return skb_queue_len(&d->tx_queue); in rfcomm_process_tx()
1880 BT_DBG("session %p state %ld", s, s->state); in rfcomm_process_dlcs()
1882 list_for_each_entry_safe(d, n, &s->dlcs, list) { in rfcomm_process_dlcs()
1883 if (test_bit(RFCOMM_TIMED_OUT, &d->flags)) { in rfcomm_process_dlcs()
1888 if (test_bit(RFCOMM_ENC_DROP, &d->flags)) { in rfcomm_process_dlcs()
1893 if (test_and_clear_bit(RFCOMM_AUTH_ACCEPT, &d->flags)) { in rfcomm_process_dlcs()
1895 if (d->out) { in rfcomm_process_dlcs()
1899 if (d->defer_setup) { in rfcomm_process_dlcs()
1900 set_bit(RFCOMM_DEFER_SETUP, &d->flags); in rfcomm_process_dlcs()
1904 d->state = BT_CONNECT2; in rfcomm_process_dlcs()
1905 d->state_change(d, 0); in rfcomm_process_dlcs()
1911 } else if (test_and_clear_bit(RFCOMM_AUTH_REJECT, &d->flags)) { in rfcomm_process_dlcs()
1913 if (!d->out) in rfcomm_process_dlcs()
1914 rfcomm_send_dm(s, d->dlci); in rfcomm_process_dlcs()
1916 d->state = BT_CLOSED; in rfcomm_process_dlcs()
1921 if (test_bit(RFCOMM_SEC_PENDING, &d->flags)) in rfcomm_process_dlcs()
1924 if (test_bit(RFCOMM_TX_THROTTLED, &s->flags)) in rfcomm_process_dlcs()
1927 if ((d->state == BT_CONNECTED || d->state == BT_DISCONN) && in rfcomm_process_dlcs()
1928 d->mscex == RFCOMM_MSCEX_OK) in rfcomm_process_dlcs()
1935 struct socket *sock = s->sock; in rfcomm_process_rx()
1936 struct sock *sk = sock->sk; in rfcomm_process_rx()
1939 BT_DBG("session %p state %ld qlen %d", s, s->state, skb_queue_len(&sk->sk_receive_queue)); in rfcomm_process_rx()
1942 while ((skb = skb_dequeue(&sk->sk_receive_queue))) { in rfcomm_process_rx()
1944 if (!skb_linearize(skb) && sk->sk_state != BT_CLOSED) { in rfcomm_process_rx()
1953 if (s && (sk->sk_state == BT_CLOSED)) in rfcomm_process_rx()
1954 s = rfcomm_session_close(s, sk->sk_err); in rfcomm_process_rx()
1961 struct socket *sock = s->sock, *nsock; in rfcomm_accept_connection()
1966 if (list_empty(&bt_sk(sock->sk)->accept_q)) in rfcomm_accept_connection()
1976 nsock->sk->sk_data_ready = rfcomm_l2data_ready; in rfcomm_accept_connection()
1977 nsock->sk->sk_state_change = rfcomm_l2state_change; in rfcomm_accept_connection()
1983 s->mtu = min(l2cap_pi(nsock->sk)->chan->omtu, in rfcomm_accept_connection()
1984 l2cap_pi(nsock->sk)->chan->imtu) - 5; in rfcomm_accept_connection()
1993 struct sock *sk = s->sock->sk; in rfcomm_check_connection()
1995 BT_DBG("%p state %ld", s, s->state); in rfcomm_check_connection()
1997 switch (sk->sk_state) { in rfcomm_check_connection()
1999 s->state = BT_CONNECT; in rfcomm_check_connection()
2003 s->mtu = min(l2cap_pi(sk)->chan->omtu, l2cap_pi(sk)->chan->imtu) - 5; in rfcomm_check_connection()
2009 s = rfcomm_session_close(s, sk->sk_err); in rfcomm_check_connection()
2022 if (test_and_clear_bit(RFCOMM_TIMED_OUT, &s->flags)) { in rfcomm_process_sessions()
2023 s->state = BT_DISCONN; in rfcomm_process_sessions()
2028 switch (s->state) { in rfcomm_process_sessions()
2077 sk = sock->sk; in rfcomm_add_listener()
2080 l2cap_pi(sk)->chan->imtu = 0; in rfcomm_add_listener()
2093 err = -ENOMEM; in rfcomm_add_listener()
2118 set_user_nice(current, -10); in rfcomm_run()
2144 s = rfcomm_session_get(&conn->hdev->bdaddr, &conn->dst); in rfcomm_security_cfm()
2148 list_for_each_entry_safe(d, n, &s->dlcs, list) { in rfcomm_security_cfm()
2149 if (test_and_clear_bit(RFCOMM_SEC_PENDING, &d->flags)) { in rfcomm_security_cfm()
2152 set_bit(RFCOMM_ENC_DROP, &d->flags); in rfcomm_security_cfm()
2157 if (d->state == BT_CONNECTED && !status && encrypt == 0x00) { in rfcomm_security_cfm()
2158 if (d->sec_level == BT_SECURITY_MEDIUM) { in rfcomm_security_cfm()
2159 set_bit(RFCOMM_SEC_PENDING, &d->flags); in rfcomm_security_cfm()
2162 } else if (d->sec_level == BT_SECURITY_HIGH || in rfcomm_security_cfm()
2163 d->sec_level == BT_SECURITY_FIPS) { in rfcomm_security_cfm()
2164 set_bit(RFCOMM_ENC_DROP, &d->flags); in rfcomm_security_cfm()
2169 if (!test_and_clear_bit(RFCOMM_AUTH_PENDING, &d->flags)) in rfcomm_security_cfm()
2172 if (!status && hci_conn_check_secure(conn, d->sec_level)) in rfcomm_security_cfm()
2173 set_bit(RFCOMM_AUTH_ACCEPT, &d->flags); in rfcomm_security_cfm()
2175 set_bit(RFCOMM_AUTH_REJECT, &d->flags); in rfcomm_security_cfm()
2193 struct l2cap_chan *chan = l2cap_pi(s->sock->sk)->chan; in rfcomm_dlc_debugfs_show()
2195 list_for_each_entry(d, &s->dlcs, list) { in rfcomm_dlc_debugfs_show()
2197 &chan->src, &chan->dst, in rfcomm_dlc_debugfs_show()
2198 d->state, d->dlci, d->mtu, in rfcomm_dlc_debugfs_show()
2199 d->rx_credits, d->tx_credits); in rfcomm_dlc_debugfs_show()
2212 /* ---- Initialization ---- */
2285 MODULE_ALIAS("bt-proto-3");