title: BlueZ scotest App and with Linux Config Can't Connect to SCO Socket
body: <p>I am using BlueZ 4.101 on an embedded Linux project with Kernel 3.4.79+. Normal Bluetooth operations work great and I can use many headset with my device to transfer Audio. Now I am working towards Bluetooth Compliance and so I am using the Bluetooth SIG's USB PTS Dongle. I am passing every test except for part of the incoming call test where I need to open the SCO connection after accepting a call with the PTS dongle.</p>
  
  <p>The SCO connection attempt works with the headsets but not with the PTS dongle. The error is given from bluetoothd as:</p>
  
  <pre><code>bluetoothd[6306]: audio/headset.c:headset_set_state() State changed /org/bluez/6306/hci0/dev_00_1B_DC_07_30_40: HEADSET_STATE_PLAY_IN_PROGRESS -&gt; HEADSET_STATE_CONNECTED
  bluetoothd[6306]: audio/headset.c:headset_set_state() State changed /org/bluez/6306/hci0/dev_00_1B_DC_07_30_40: HEADSET_STATE_CONNECTED -&gt; HEADSET_STATE_PLAY_IN_PROGRESS
  bluetoothd[6306]: Protocol not supported (93)
  </code></pre>
  
  <p>So I compiled scotest from the test directory of BlueZ and ran that after connecting with the dongle and got the same result:</p>
  
  <pre><code># ./scotest -s -b HELLO 00:1B:DC:07:30:40
  scotest[1687]: Can't connect: Protocol not supported (93)
  scotest[1687]: Can't connect to the server: Protocol not supported (93)
  </code></pre>
  
  <p>Here is the do_connect function in scotest.c that is failing in:</p>
  
  <pre><code>static int do_connect(char *svr)
  {
      struct sockaddr_sco addr;
      struct sco_conninfo conn;
      socklen_t optlen;
      int sk;
  
      /* Create socket */
      sk = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_SCO);
      if (sk &lt; 0) {
          syslog(LOG_ERR, "Can't create socket: %s (%d)",
                              strerror(errno), errno);
          return -1;
      }
  
      /* Bind to local address */
      memset(&amp;addr, 0, sizeof(addr));
      addr.sco_family = AF_BLUETOOTH;
      bacpy(&amp;addr.sco_bdaddr, &amp;bdaddr);
  
      if (bind(sk, (struct sockaddr *) &amp;addr, sizeof(addr)) &lt; 0) {
          syslog(LOG_ERR, "Can't bind socket: %s (%d)",
                              strerror(errno), errno);
          goto error;
      }
  
      /* Connect to remote device */
      memset(&amp;addr, 0, sizeof(addr));
      addr.sco_family = AF_BLUETOOTH;
      str2ba(svr, &amp;addr.sco_bdaddr);
  
      if (connect(sk, (struct sockaddr *) &amp;addr, sizeof(addr)) &lt; 0) {
          syslog(LOG_ERR, "Can't connect: %s (%d)",
                              strerror(errno), errno);
          goto error;
      }
  
      /* Get connection information */
      memset(&amp;conn, 0, sizeof(conn));
      optlen = sizeof(conn);
  
      if (getsockopt(sk, SOL_SCO, SCO_CONNINFO, &amp;conn, &amp;optlen) &lt; 0) {
          syslog(LOG_ERR, "Can't get SCO connection information: %s (%d)",
                              strerror(errno), errno);
          goto error;
      }
  
      syslog(LOG_INFO, "Connected [handle %d, class 0x%02x%02x%02x]",
          conn.hci_handle,
          conn.dev_class[2], conn.dev_class[1], conn.dev_class[0]);
  
      return sk;
  
  error:
      close(sk);
      return -1;
  }
  </code></pre>
  
  <p>What am I missing in the Kernel Config to allow the PTS dongle to be put into a Playing state with an open SCO connection?</p>
  
  <p>Here is my .config for Linux ( I'm using backports-3.13.2-1 to support the TI WL1271 BT/WiFi module ):</p>
  
  <pre><code>CPTCFG_IPV6_SUBTREES=y
  CPTCFG_NFT_RBTREE=m
  CPTCFG_BRIDGE_NF_EBTABLES=m
  CPTCFG_BRIDGE_EBT_BROUTE=m
  CPTCFG_BRIDGE_EBT_T_FILTER=m
  CPTCFG_BRIDGE_EBT_T_NAT=m
  CPTCFG_BRIDGE_EBT_802_3=m
  CPTCFG_BRIDGE_EBT_AMONG=m
  CPTCFG_BRIDGE_EBT_ARP=m
  CPTCFG_BRIDGE_EBT_IP=m
  CPTCFG_BRIDGE_EBT_IP6=m
  CPTCFG_BRIDGE_EBT_LIMIT=m
  CPTCFG_BRIDGE_EBT_MARK=m
  CPTCFG_BRIDGE_EBT_PKTTYPE=m
  CPTCFG_BRIDGE_EBT_STP=m
  CPTCFG_BRIDGE_EBT_VLAN=m
  CPTCFG_BRIDGE_EBT_ARPREPLY=m
  CPTCFG_BRIDGE_EBT_DNAT=m
  CPTCFG_BRIDGE_EBT_MARK_T=m
  CPTCFG_BRIDGE_EBT_REDIRECT=m
  CPTCFG_BRIDGE_EBT_SNAT=m
  CPTCFG_BRIDGE_EBT_LOG=m
  CPTCFG_BRIDGE_EBT_NFLOG=m
  CPTCFG_MAC_EMUMOUSEBTN=m
  CPTCFG_RTLBTCOEXIST=m
  CPTCFG_TABLET_USB_KBTAB=m
  CPTCFG_INPUT_ATLAS_BTNS=m
  CPTCFG_SND_BT87X=m
  CPTCFG_LIRC_BT829=m
  CPTCFG_USB_BTMTK=m
  CPTCFG_TOSHIBA_BT_RFKILL=m
  CPTCFG_BTRFS_FS=m
  CPTCFG_BTRFS_FS_POSIX_ACL=y
  CPTCFG_RBTREE_TEST=m
  CPTCFG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE=y
  CPTCFG_BTREE=y
  CPTCFG_BACKPORT_OPTION_BT_SOCK_CREATE_NEEDS_KERN=y
  CPTCFG_BT=m
  CPTCFG_BT_RFCOMM=m
  # CPTCFG_BT_RFCOMM_TTY is not set
  CPTCFG_BT_BNEP=m
  CPTCFG_BT_BNEP_MC_FILTER=y
  CPTCFG_BT_BNEP_PROTO_FILTER=y
  # CPTCFG_BT_CMTP is not set
  CPTCFG_BT_HIDP=m
  CPTCFG_BT_HCIBTUSB=m
  CPTCFG_BT_HCIBTSDIO=m
  CPTCFG_BT_HCIUART=m
  CPTCFG_BT_HCIUART_H4=y
  CPTCFG_BT_HCIUART_BCSP=y
  # CPTCFG_BT_HCIUART_ATH3K is not set
  CPTCFG_BT_HCIUART_LL=y
  CPTCFG_BT_HCIUART_3WIRE=y
  # CPTCFG_BT_HCIBCM203X is not set
  # CPTCFG_BT_HCIBPA10X is not set
  # CPTCFG_BT_HCIBFUSB is not set
  # CPTCFG_BT_HCIDTL1 is not set
  # CPTCFG_BT_HCIBT3C is not set
  # CPTCFG_BT_HCIBLUECARD is not set
  CPTCFG_BT_HCIBTUART=m
  CPTCFG_BT_HCIVHCI=m
  # CPTCFG_BT_MRVL is not set
  # CPTCFG_BT_ATH3K is not set
  CPTCFG_BT_WILINK=m
  </code></pre>
  
  <p>I instrumented the sco.c file in the kernel with printks. </p>
  
  <p>On success with a normal headset it looks like this after successfully opening SCO connection:</p>
  
  <pre><code>*** sco_sock_create
  *** sco_sock_alloc
  *** sco_sock_init
  *** sco_sock_bind
  *** sco_sock_connect
  *** sco_connect
  *** sco_conn_add
  *** sco_chan_add
  *** __sco_chan_add
  *** sco_sock_set_timer
  *** sco_connect_cfm
  *** sco_conn_add
  *** sco_conn_ready
  *** sco_sock_clear_timer
  *** sco_sock_getsockopt
  *** sco_sock_setsockopt_old
  *** sco_sock_getsockopt
  *** sco_sock_setsockopt_old
  *** sco_sock_sendmsg
  *** sco_send_frame
  *** sco_sock_sendmsg
  *** sco_send_frame
  *** sco_sock_sendmsg
  *** sco_send_frame
  </code></pre>
  
  <p>On failure it looks like this:</p>
  
  <pre><code>*** sco_sock_create
  *** sco_sock_alloc
  *** sco_sock_init
  *** sco_sock_bind
  *** sco_sock_connect
  *** sco_connect
  *** sco_conn_add
  *** sco_chan_add
  *** __sco_chan_add
  *** sco_sock_set_timer
  *** sco_connect_cfm
  *** sco_conn_del
  *** sco_chan_get
  *** sco_sock_clear_timer
  *** sco_chan_del
  *** sco_sock_release
  *** sco_sock_close
  *** sco_sock_kill
  *** sco_sock_clear_timer
  *** __sco_sock_connect
  *** sco_sock_kill
  *** sco_sock_kill
  *** sco_sock_destruct
  </code></pre>
  
  <p>Further instrumentation shows the failures are happening in this sco.c function:</p>
  
  <pre><code>void sco_connect_cfm(struct hci_conn *hcon, __u8 status)
  {
  
      printk("*** sco_connect_cfm start\n");
  
      BT_DBG("hcon %p bdaddr %pMR status %d", hcon, &amp;hcon-&gt;dst, status);
      printk("*** sco_connect_cfm_stat hcon %p bdaddr %pMR status %d\n", hcon, &amp;hcon-&gt;dst, status);
      if (!status) {
          struct sco_conn *conn;
  
          conn = sco_conn_add(hcon);
          printk("*** sco_connect_cfm sco_conn_add: %d\n",conn);
          if (conn)
              printk("*** sco_connect_cfm ready\n");
              sco_conn_ready(conn);
      } else
          printk("*** sco_connect_delete: %d\n",status);
          sco_conn_del(hcon, bt_to_errno(status));
  }
  </code></pre>
  
  <p>That output looks like this:</p>
  
  <pre><code>*** sco_sock_create
  *** sco_sock_alloc
  *** sco_sock_init
  *** sco_sock_bind
  *** sco_sock_connect
  *** sco_connect
  *** sco_conn_add
  *** sco_chan_add
  *** __sco_chan_add
  *** sco_sock_set_timer
  *** sco_connect_cfm start
  *** sco_connect_cfm_stat hcon d9ec2400 bdaddr 40:30:07:dc:1b:00 status 26
  *** sco_connect_delete: 26
  *** sco_conn_del
  *** sco_chan_get
  *** sco_sock_clear_timer
  *** sco_chan_del
  *** sco_sock_release
  *** sco_sock_close
  *** sco_sock_clear_timer
  *** sco_sock_kill
  *** __sco_sock_connect
  *** sco_sock_kill
  *** sco_sock_kill
  *** sco_sock_destruct
  </code></pre>