title: Using hcitool to set ad packets
body: <p>There is a well known blog post going around on how to set a usb bluetooth 4 dongle to be an iBeacon. It boils down to this magical command:</p>
  
  <pre><code>sudo hcitool -i hci0 cmd 0x08 0x0008 1e 02 01 1a 1a ff 4c 00 02 15 e2 c5 6d b5 df fb 48 d2 b0 60 d0 f5 a7 10 96 e0 00 00 00 00 c5 00 00 00 00 00 00 00 00 00 00 00 00 00
  </code></pre>
  
  <p>The issue with this example is that it is so opaque it's hard to use it in any more general format. I've been able to break it apart a bit:</p>
  
  <pre><code>sudo hcitool -i hci0 cmd
  </code></pre>
  
  <p>sends an hci command to the hci0 device</p>
  
  <pre><code>0x08 0x0008 
  </code></pre>
  
  <p>is just magic to set the ad package, other stackoverflow commands have said "just use it, don't ask</p>
  
  <pre><code>1e
  </code></pre>
  
  <p>is the length of the ENTIRE following data packet in bytes</p>
  
  <pre><code>02 01 1a 1a
  </code></pre>
  
  <p>Are flags to set up the ad packet (details on request)</p>
  
  <pre><code>ff 4c 00 ...
  </code></pre>
  
  <p>is the 'company specific data' that encodes the iBeacon info</p>
  
  <p>What I've tried to do is replace the "FF ..." bytes with the opcodes for setting the NAME parameter "04 09 41 42 43" (which should set it to ABC) but that doesn't work.</p>
  
  <p>I'm surprised the hcitool doesn't give us some examples on how to set the ad packet as this would be very useful in setting all sorts of other params (like TEMP or POWER). Has anyone else had any experience in using hcitool to set things like NAME?</p>