@@ -2504,6 +2504,9 @@ static void smp_resume_cb(struct l2cap_chan *chan)
25042504
25052505 BT_DBG ("chan %p" , chan );
25062506
2507+ if (hcon -> type == ACL_LINK )
2508+ return ;
2509+
25072510 if (!smp )
25082511 return ;
25092512
@@ -2527,10 +2530,14 @@ static void smp_ready_cb(struct l2cap_chan *chan)
25272530
25282531static int smp_recv_cb (struct l2cap_chan * chan , struct sk_buff * skb )
25292532{
2533+ struct hci_conn * hcon = chan -> conn -> hcon ;
25302534 int err ;
25312535
25322536 BT_DBG ("chan %p" , chan );
25332537
2538+ if (hcon -> type == ACL_LINK )
2539+ return - EOPNOTSUPP ;
2540+
25342541 err = smp_sig_channel (chan , skb );
25352542 if (err ) {
25362543 struct smp_chan * smp = chan -> data ;
@@ -2627,34 +2634,40 @@ static const struct l2cap_ops smp_root_chan_ops = {
26272634 .memcpy_fromiovec = l2cap_chan_no_memcpy_fromiovec ,
26282635};
26292636
2630- int smp_register (struct hci_dev * hdev )
2637+ static struct l2cap_chan * smp_add_cid (struct hci_dev * hdev , u16 cid )
26312638{
26322639 struct l2cap_chan * chan ;
26332640 struct crypto_blkcipher * tfm_aes ;
26342641
2635- BT_DBG ("%s" , hdev -> name );
2642+ if (cid == L2CAP_CID_SMP_BREDR ) {
2643+ tfm_aes = NULL ;
2644+ goto create_chan ;
2645+ }
26362646
26372647 tfm_aes = crypto_alloc_blkcipher ("ecb(aes)" , 0 , 0 );
26382648 if (IS_ERR (tfm_aes )) {
2639- int err = PTR_ERR (tfm_aes );
26402649 BT_ERR ("Unable to create crypto context" );
2641- return err ;
2650+ return ERR_PTR ( PTR_ERR ( tfm_aes )) ;
26422651 }
26432652
2653+ create_chan :
26442654 chan = l2cap_chan_create ();
26452655 if (!chan ) {
26462656 crypto_free_blkcipher (tfm_aes );
2647- return - ENOMEM ;
2657+ return ERR_PTR ( - ENOMEM ) ;
26482658 }
26492659
26502660 chan -> data = tfm_aes ;
26512661
2652- l2cap_add_scid (chan , L2CAP_CID_SMP );
2662+ l2cap_add_scid (chan , cid );
26532663
26542664 l2cap_chan_set_defaults (chan );
26552665
26562666 bacpy (& chan -> src , & hdev -> bdaddr );
2657- chan -> src_type = BDADDR_LE_PUBLIC ;
2667+ if (cid == L2CAP_CID_SMP )
2668+ chan -> src_type = BDADDR_LE_PUBLIC ;
2669+ else
2670+ chan -> src_type = BDADDR_BREDR ;
26582671 chan -> state = BT_LISTEN ;
26592672 chan -> mode = L2CAP_MODE_BASIC ;
26602673 chan -> imtu = L2CAP_DEFAULT_MTU ;
@@ -2663,27 +2676,67 @@ int smp_register(struct hci_dev *hdev)
26632676 /* Set correct nesting level for a parent/listening channel */
26642677 atomic_set (& chan -> nesting , L2CAP_NESTING_PARENT );
26652678
2666- hdev -> smp_data = chan ;
2667-
2668- return 0 ;
2679+ return chan ;
26692680}
26702681
2671- void smp_unregister (struct hci_dev * hdev )
2682+ static void smp_del_chan (struct l2cap_chan * chan )
26722683{
2673- struct l2cap_chan * chan = hdev -> smp_data ;
2674- struct crypto_blkcipher * tfm_aes ;
2675-
2676- if (!chan )
2677- return ;
2684+ struct crypto_blkcipher * tfm_aes ;
26782685
2679- BT_DBG ("%s chan %p" , hdev -> name , chan );
2686+ BT_DBG ("chan %p" , chan );
26802687
26812688 tfm_aes = chan -> data ;
26822689 if (tfm_aes ) {
26832690 chan -> data = NULL ;
26842691 crypto_free_blkcipher (tfm_aes );
26852692 }
26862693
2687- hdev -> smp_data = NULL ;
26882694 l2cap_chan_put (chan );
26892695}
2696+
2697+ int smp_register (struct hci_dev * hdev )
2698+ {
2699+ struct l2cap_chan * chan ;
2700+
2701+ BT_DBG ("%s" , hdev -> name );
2702+
2703+ chan = smp_add_cid (hdev , L2CAP_CID_SMP );
2704+ if (IS_ERR (chan ))
2705+ return PTR_ERR (chan );
2706+
2707+ hdev -> smp_data = chan ;
2708+
2709+ if (!lmp_sc_capable (hdev ) &&
2710+ !test_bit (HCI_FORCE_LESC , & hdev -> dbg_flags ))
2711+ return 0 ;
2712+
2713+ chan = smp_add_cid (hdev , L2CAP_CID_SMP_BREDR );
2714+ if (IS_ERR (chan )) {
2715+ int err = PTR_ERR (chan );
2716+ chan = hdev -> smp_data ;
2717+ hdev -> smp_data = NULL ;
2718+ smp_del_chan (chan );
2719+ return err ;
2720+ }
2721+
2722+ hdev -> smp_bredr_data = chan ;
2723+
2724+ return 0 ;
2725+ }
2726+
2727+ void smp_unregister (struct hci_dev * hdev )
2728+ {
2729+ struct l2cap_chan * chan ;
2730+
2731+ if (hdev -> smp_bredr_data ) {
2732+ chan = hdev -> smp_bredr_data ;
2733+ hdev -> smp_bredr_data = NULL ;
2734+ smp_del_chan (chan );
2735+ }
2736+
2737+ if (hdev -> smp_data ) {
2738+ chan = hdev -> smp_data ;
2739+ hdev -> smp_data = NULL ;
2740+ smp_del_chan (chan );
2741+ }
2742+ }
0 commit comments