{"id":23752,"date":"2018-06-07T15:10:17","date_gmt":"2018-06-07T20:10:17","guid":{"rendered":"http:\/\/www.multitech.net\/developer\/?page_id=23752"},"modified":"2019-09-04T09:11:18","modified_gmt":"2019-09-04T14:11:18","slug":"bluez-5-pan-setup","status":"publish","type":"page","link":"https:\/\/www.multitech.net\/developer\/software\/mlinux\/using-mlinux\/bluez-5-pan-setup\/","title":{"rendered":"bluez5 PAN Setup"},"content":{"rendered":"<p><strong>NOTE:<\/strong> This information only applies to devices with Bluetooth using\u00a0mLinux<sup>\u2122<\/sup> 4.x or higher which has bluez5. For devices using mLinux 3.x, refer to <a href=\"https:\/\/www.multitech.net\/developer\/software\/mlinux\/using-mlinux\/bluetooth\/\">Bluetooth<\/a>.<\/p>\n<p>BlueZ includes a utility called \u00a0bluetoothctl.<\/p>\n<p><strong>bluetoothctl Tips<\/strong><\/p>\n<ul>\n<li>bluetoothctl is space sensitive. If you have two spaces between a command and its argument, it will fail as follows:<\/li>\n<\/ul>\n<pre class=\"brush:shell\" style=\"padding-left: 30px;\">[bluetooth] trust  5C:F3:70:74:04:AF\r\nDevice 5C:F3:70:74:04:AF not available<\/pre>\n<ul>\n<li><span style=\"font-size: 12px;\">To exit bluetoothctl, type &#8220;quit&#8221; followed by the enter key.<br \/>\n<\/span><\/li>\n<\/ul>\n<p>In this case, the hex value is is the <strong>BD_ADDR<\/strong> (Bluetooth Device Address, similar to an ethernet MAC address) of the remote bluetooth device. If you get the Device not available message, look closely to verify the syntax. Otherwise, try again.<\/p>\n<pre class=\"brush:shell\">Authorize service\r\n[agent] Authorize service 0000000f-0000-1000-8000-00805f9b34fb (yes\/no): yes\r\n[bluetooth] default-agent<\/pre>\n<p>If you do not do the trust step, there is also a race condition between the client and issuing the message. The client may timeout before the\u00a0<b>Authorize service<\/b>\u00a0can be answered. So it is best to trust the bluetooth client device. Also, if bluetoothctl or some program to answer the authorization request is not running, the connection attempt will fail. Every time bluetoothctl is started, it is important to do the\u00a0<b>default-agent<\/b>\u00a0command.<\/p>\n<p><b>Measuring bluetooth performance<\/b><\/p>\n<p>You can discover the bytes sent with the \/proc\/net\/dev kernel file.<\/p>\n<pre class=\"brush:shell\">mtcdt:~$ egrep 'pan0|Receive|fifo' \/proc\/net\/dev\r\nInter-|   Receive                                                |  Transmit\r\n face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed\r\n  pan0:  336375    2905    0    0    0     0          0         0  3354937    3097    0    0    0     0       0          0<\/pre>\n<p><span style=\"font-size: large;\"><br \/>\n<strong>mLinux 4 with bluez5<\/strong><\/span><\/p>\n<p>You must configure the network settings for eth0 and pan0 by modifying the \/etc\/network\/interfaces file. This includes setting up a NAT.<\/p>\n<h2><span style=\"font-size: medium;\">Set up eth0 (or wifi) to forward<\/span><\/h2>\n<p>In \/etc\/network\/interfaces:<\/p>\n<pre class=\"brush:shell\"># Wired interface\r\nauto eth0\r\niface eth0 inet static\r\naddress 172.16.1.135\r\nnetmask 255.255.0.0\r\ngateway 172.16.0.1\r\npost-up echo 1 &gt;\/proc\/sys\/net\/ipv4\/ip_forward\r\npost-up iptables -F                                   \r\npost-up iptables -t nat -F\r\npost-up iptables -t mangle -F\r\npost-up iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE<\/pre>\n<h2><span style=\"font-size: medium;\">Set up bridge node<\/span><\/h2>\n<p>In \/etc\/network\/interfaces:<\/p>\n<pre class=\"brush:shell\">auto pan0\r\niface pan0 inet static\r\naddress 10.1.0.1\r\nnetmask 255.255.255.0 \r\npre-up brctl addbr pan0\r\npre-up brctl setfd pan0 0\r\npre-up brctl stp pan0 off<\/pre>\n<h2><span style=\"font-size: medium;\">Restart eth0 and bring up pan0<\/span><\/h2>\n<p>The nohup allows completion of the command if you are using <strong>eth0<\/strong> to log into the device. If the <strong>eth0<\/strong> address changes, and you are using <strong>eth0<\/strong> to log into the device, you will lose your session.<\/p>\n<pre class=\"brush:shell\">$ sudo nohup bash -c \"ifdown eth0\u00a0; sleep 2; ifup eth0\"<\/pre>\n<h2>Set up bluetooth service<\/h2>\n<h3>main.conf<\/h3>\n<p>The file \/etc\/bluetooth\/main.conf should be set up.<\/p>\n<p>The main.conf file contains these sections:<\/p>\n<h4 style=\"padding-left: 30px;\">General Section<a title=\"Edit section: General Section\" href=\"http:\/\/sw.multitech.prv\/mediawiki\/index.php?title=Bluez_5_PAN_setup&amp;action=edit&amp;section=8\"><br \/>\n<\/a><\/h4>\n<pre class=\"brush:shell\">[General]\r\nName = MTCDT-Bluez  # Some identifiable name\r\nDiscoverableTimeout = 0 # Stay discoverable\r\nAutoConnectTimeout = 0 # automatic connection timeout<\/pre>\n<h4 style=\"padding-left: 30px;\">Policy Section<\/h4>\n<p style=\"padding-left: 30px;\">Autoenable automatically powers up the bluetooth device on boot.<\/p>\n<pre class=\"brush:shell\">[Policy]\r\nAutoEnable=true<\/pre>\n<h3 style=\"padding-left: 30px;\">\/etc\/default\/bluetooth<\/h3>\n<p style=\"padding-left: 30px;\">Set the enable line:<\/p>\n<pre class=\"brush:shell\">BLUETOOTH_ENABLED=1<\/pre>\n<h3>Start Bluetooth daemon<\/h3>\n<pre class=\"brush:shell\">sudo \/etc\/init.d\/bluetooth start<\/pre>\n<h2><span style=\"font-size: medium;\">Enable and start pand<\/span><\/h2>\n<p>Pan should be enabled. Debug is optional.<\/p>\n<p>Edit the file \/etc\/default\/bt-pan:<\/p>\n<pre class=\"brush:shell\">ENABLED=\"yes\"\r\nPANOPTS=\"--debug\"<\/pre>\n<p>Now start it up.<\/p>\n<pre class=\"brush:shell\">sudo \/etc\/init.d\/bt-pan start<\/pre>\n<h2><span style=\"font-size: medium;\">Set up dnsmasq<\/span><\/h2>\n<h3 style=\"padding-left: 30px;\"><span style=\"font-size: small;\">Enable<\/span><\/h3>\n<p style=\"padding-left: 30px;\">You must set ENABLED=&#8221;yes&#8221; in \/etc\/default\/dnsmasq (default is no):<\/p>\n<pre class=\"brush:shell\">     ENABLED=\"yes\"<\/pre>\n<h3 style=\"padding-left: 30px;\"><span style=\"font-size: small;\">Configure<\/span><\/h3>\n<p style=\"padding-left: 30px;\">The following configuration lines must only appear once in all the configuration files in the directory \/etc\/dnsmasq.d:<\/p>\n<ul style=\"padding-left: 30px;\">\n<ul>\n<li style=\"padding-left: 30px;\">dhcp-lease-max<\/li>\n<li style=\"padding-left: 30px;\">dhcp-leasefile<\/li>\n<\/ul>\n<\/ul>\n<p style=\"padding-left: 30px;\">Modify the file \/etc\/dnsmasq.d\/dhcp.conf to match the following:<\/p>\n<pre class=\"brush:shell\">interface=pan0\r\ndhcp-range=10.1.0.100,10.1.0.250,12h\r\ndhcp-lease-max=200\r\ndhcp-leasefile=\/var\/config\/dnsmasq_dhcp_pan0.leases\r\ndhcp-option=option:netmask,255.255.255.0\r\ndhcp-option=option:router,10.1.0.1\r\ndhcp-option=option:dns-server,10.1.0.1\r\ndhcp-authoritative<\/pre>\n<p style=\"padding-left: 30px;\">In another file called \/etc\/dnsmasq.d\/dns.conf, include:<\/p>\n<pre class=\"brush:shell\">no-hosts\r\naddn-hosts=\/var\/config\/hosts\r\nresolv-file=\/etc\/resolv.conf<\/pre>\n<p style=\"padding-left: 30px;\">If you are not using a DHCP server from the device, set up \/etc\/network\/resolv.conf.\u00a0 (Do not use \/etc\/resolv.conf, as this file is a sym link to volatile storage and is created at boot.)<\/p>\n<p style=\"padding-left: 30px;\">Edit the resolv.conf as required.<\/p>\n<p style=\"padding-left: 60px;\">Example:<\/p>\n<pre class=\"brush:shell\" style=\"padding-left: 60px;\">nameserver 172.16.0.20\r\nsearch mydomain.net<\/pre>\n<p style=\"padding-left: 30px;\">If you are using DHCP with eth0, \/etc\/resolv.conf is created automatically. In that case you should not edit \/etc\/resolv.conf, and it should be used in \/etc\/dnsmasq.d\/dns.conf.<\/p>\n<h2>Start dnsmasq<\/h2>\n<pre class=\"brush:shell\">sudo \/etc\/init.d\/dnsmasq restart<\/pre>\n<p>&nbsp;<\/p>\n<h2>Pairing<\/h2>\n<p>Follow the steps for <a href=\"https:\/\/www.multitech.net\/developer\/software\/mlinux\/using-mlinux\/pairing\/\">pairing<\/a>\u00a0with another bluetooth device.<\/p>\n<h3>Connect to pand<\/h3>\n<p>On the phone, select <strong>Internet access.<\/strong><\/p>\n<p>If you do not trust the phone (as shown previously), every time you select the PAN service, the system asks to approve the connection.<\/p>\n<p>Without trust, you must have a program running on the device to do this (like <strong>bluetoothct<\/strong>l).\u00a0For this example we are running bluetoothctl on the device.\u00a0 Start bluetoothctl:<\/p>\n<p><code>$ sudo -s bluetoothctl<br \/>\n[bluetooth]#<\/code><\/p>\n<p>On your device, you may see the following if you did not do the <i>Trust<\/i> step (type yes to authorize service and hit enter):<\/p>\n<p><code>Authorize service<br \/>\n[agent] Authorize service 0000000f-0000-1000-8000-00805f9b34fb (yes\/no): yes<br \/>\n[John Cell Phone]#<br \/>\ndevice bnep0 entered promiscuous mode<br \/>\npan0: port 1(bnep0) entered forwarding state<br \/>\npan0: port 1(bnep0) entered forwarding state<\/code><\/p>\n<p><strong><span style=\"font-size: large;\">Windows with bluez5<\/span><\/strong><\/p>\n<p>To do this, you must have a bluetooth device on your PC. It could be a USB dongle. With some equipment, it is internal.<\/p>\n<h2><span style=\"font-size: small;\">Set up pairing agent<\/span><\/h2>\n<pre class=\"brush:shell\">[bluetooth] agent KeyboardOnly\r\nAgent registered\r\n[bluetooth] default-agent\r\nDefault agent request successful<\/pre>\n<h2><span style=\"font-size: medium;\">Make discoverable in Windows<\/span><a title=\"Edit section: Make discoverable in Windows\" href=\"http:\/\/sw.multitech.prv\/mediawiki\/index.php?title=Bluez_5_PAN_setup&amp;action=edit&amp;section=26\"><br \/>\n<\/a><\/h2>\n<ol>\n<li>From the lower right tray in the Windows OS, select the bluetooth icon.<\/li>\n<li>Click to get its menu. Select <strong>Show Bluetooth Devices<\/strong>.<\/li>\n<li>The <strong>Bluetooth Settings<\/strong> window displays. Click the<strong> Options<\/strong> tab.<\/li>\n<li>Check <strong>Allow Bluetooth devices to find this computer<\/strong>. Click <strong>OK.<\/strong><\/li>\n<\/ol>\n<h2><span style=\"font-size: medium;\">Make the device discoverable and pairable if not already<\/span><\/h2>\n<pre class=\"brush:shell\">[bluetooth] discoverable on\r\nChanging discoverable on succeeded\r\n[bluetooth] pairable on\r\nChanging pairable on succeeded<\/pre>\n<h2><span style=\"font-size: medium;\">Turn scan on and find Windows System<\/span><\/h2>\n<pre class=\"brush:shell\">Device 5C:F3:70:74:04:AF CALMQUIST-L1<\/pre>\n<h2><span style=\"font-size: medium;\">Scan Off and Pair<\/span><\/h2>\n<p>The pairing is initiated in mLinux on the device (not your PC) and\u00a0time-limited. Follow these steps quickly or the pairing will fail:<\/p>\n<ol>\n<li>Enter the following command on mLinux to pair the device with your PC:\n<pre class=\"brush:shell\">[bluetooth] pair 5C:F3:70:74:04:AF<\/pre>\n<\/li>\n<li>Answer yes in mLinux on the device.<\/li>\n<li>On your PC, immediately click on the Windows bubble saying that <strong>a Bluetooth device is trying to connect<\/strong>.<\/li>\n<li>Quickly answer the prompt by clicking <strong>Next<\/strong> to add the device for the pairing request. (Otherwise, the pairing will fail.)<\/li>\n<li>Windows displays a success message if successful.<\/li>\n<\/ol>\n<p style=\"padding-left: 30px;\">The resulting output (if successful) on the device should look like:<\/p>\n<pre class=\"brush:shell\">Attempting to pair with 5C:F3:70:74:04:AF\r\n[CHG] Device 5C:F3:70:74:04:AF Connected: yes\r\nRequest confirmation\r\n[agent] Confirm passkey 912097 (yes\/no): yes\r\n[CHG] Device 5C:F3:70:74:04:AF UUIDs: 00001000-0000-1000-8000-00805f9b34fb\r\n[CHG] Device 5C:F3:70:74:04:AF UUIDs: 00001115-0000-1000-8000-00805f9b34fb\r\n[CHG] Device 5C:F3:70:74:04:AF ServicesResolved: yes\r\n[CHG] Device 5C:F3:70:74:04:AF Paired: yes\r\nPairing successful\r\n[CHG] Device 5C:F3:70:74:04:AF ServicesResolved: no\r\n[CHG] Device 5C:F3:70:74:04:AF Connected: no<\/pre>\n<p>&nbsp;<\/p>\n<h2><span style=\"font-size: medium;\">Trust<\/span><\/h2>\n<p>Trust is needed so the client may connect without a response from the device. Enter the following command:<\/p>\n<pre class=\"brush:shell\">[bluetooth] trust 5C:F3:70:74:04:AF<\/pre>\n<p>The system confirms your change with:<\/p>\n<pre class=\"brush:shell\">[CHG] Device 5C:F3:70:74:04:AF Trusted: yes<\/pre>\n<h2><span style=\"font-size: medium;\">Connect<\/span><\/h2>\n<p>On your PC, connect using access point by following these steps:<\/p>\n<ol>\n<li>Click on <strong>Start Menu &gt;\u00a0Devices and Printers &gt;<\/strong>\u00a0<strong>Bluetooth Personal Area Network Devices<\/strong><\/li>\n<li>Right click on your device to display its menu.<\/li>\n<li>Select <strong>Connect using &gt; Access point<\/strong>.<\/li>\n<\/ol>\n<p>On your device, you may see the following if you did not do the <strong>Trust\u00a0 <\/strong>step (type yes to authorize service and hit enter):<\/p>\n<pre class=\"brush:shell\">[agent] Authorize service 0000000f-0000-1000-8000-00805f9b34fb (yes\/no): yes\r\n[CHG] Device 54:93:2C:37:5C:95 RSSI: -85\r\n[CHG] Device 54:93:2C:37:5C:95 RSSI: -69<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>NOTE: This information only applies to devices with Bluetooth using\u00a0mLinux\u2122 4.x or higher which has bluez5. For devices using mLinux 3.x, refer to Bluetooth. BlueZ includes a utility called \u00a0bluetoothctl. bluetoothctl Tips bluetoothctl is space sensitive. If you have two spaces between a command and its argument, it will fail as follows: [bluetooth] trust 5C:F3:70:74:04:AF [&hellip;]<\/p>\n","protected":false},"author":1478,"featured_media":0,"parent":9184,"menu_order":7,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"class_list":["post-23752","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/pages\/23752","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/users\/1478"}],"replies":[{"embeddable":true,"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/comments?post=23752"}],"version-history":[{"count":53,"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/pages\/23752\/revisions"}],"predecessor-version":[{"id":23754,"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/pages\/23752\/revisions\/23754"}],"up":[{"embeddable":true,"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/pages\/9184"}],"wp:attachment":[{"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/media?parent=23752"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}