Skip to content

Commit 875b768

Browse files
committed
Signed-off-by: Robert Davidson <[email protected]>
1 parent ecf19da commit 875b768

7 files changed

+8462
-0
lines changed

iOS/ANCS/README.md

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Apple Notification Center Service Demo #
2+
[Apple Notification Center Service](https://developer.apple.com/library/ios/documentation/CoreBluetooth/Reference/AppleNotificationCenterServiceSpecification/AppleNotificationCenterServiceSpecification.pdf) is a GATT service that will send push notifications to an connected bluetooth device whenever a notification event occurs on the iOS device.
3+
This code lays out the basic stuff you need to get ANCS working on a project with an embedded device, such as a DIY smartwatch.
4+
5+
## Setting the Correct Advertising Packet ##
6+
In order to have your device show up in the list of available bluetooth devices in the system settings pane, you need to register your interest. The Punch Through Design [blog post](http://blog.punchthrough.com/post/63658238857/the-apple-notification-center-service-or-wtf-is) on ANCS left a hint about how to do this. You need to use "Service Solicitation" to indicate that you are interested in subscribing to the ANCS service.
7+
8+
Core 4.0 Vol 3 Part C, 18.9 gives the AD identifier, `$15`. I included a local name in my packet so that I could identify my device. In actual byte order, here is the contents of my packet:
9+
10+
`02` AD Field, 2 bytes
11+
`01` AD Flags
12+
`02` General Discovery, no BR/EDR, you can change this as needed
13+
`04` AD Field, 4 bytes
14+
`09` AD Complete Local Name
15+
`4C 45 44` LED, not sure why I called it that
16+
`11` AD Field, 17 bytes
17+
`15` AD Service Solicitation, 128 bits
18+
`D0 00 2D 12 1E 4B 0F A4 99 4E CE B5 31 F4 05 79` The ANCS service in LSB to MSB order.
19+
20+
## Pairing ##
21+
Subscribing to events requires that the devices be paired. Bluegiga has a [doc](https://bluegiga.zendesk.com/entries/22882472--REFERENCE-Bonding-encryption-and-MITM-protection-with-the-BLE112) that I worked from to start encryption when the connection event is fired on the device. You do not need to have a pin.
22+
23+
## Enumerating the iOS Services ##
24+
Before you can enumerate the ANCS service, you must find its handle range. iOS will only return characteristics for the correct service range, so enumerating `$0000` to `$ffff` will not work.
25+
26+
ANCS is a primary service, so listing all primary services will allow you to find it, as well as give you the start and end handles for attribute enumeration. An excellent bluegiga example [health thermometer collector](https://bluegiga.zendesk.com/entries/23999407--BGScript-htm-collector-Health-Thermometer-collector-BLE-master-), gave me the structure I needed for enumerating the services, enumerating the attributes of the service of interest, subscribing to a notifiable attribute using the Client Characteristic Configuration Descriptor, and receiving new values via an event callback.
27+
28+
## Enumerating the ANCS Service ##
29+
Here are the attributes of the ANCS service, as returned to my device, in the exact order that the bytes given to the buffer, essentially reverse-documentation order.
30+
31+
`00 28` Primary Service
32+
33+
`03 28` Characteristic Declaration
34+
`d9 d9 aa fd bd 9b 21 98 a8 49 e1 45 f3 d8 d1 69` ANCS Control Point
35+
`00 29` Characteristic Extended Properties
36+
37+
`03 28` Characteristic Declaration
38+
`bd 1d a2 99 e6 25 58 8c d9 42 01 63 0d 12 bf 9f` ANCS Notification Source
39+
`02 29` Client Characteristic Configuration Descriptor
40+
41+
`03 28` Characteristic Declaration
42+
`fb 7b 7c ce 6a b3 44 be b5 4b d6 24 e9 c6 ea 22` ANCS Data Source
43+
`02 29` Client Characteristic Configuration Descriptor
44+
45+
Core 4.0 Vol 3 Part G, 3.4 lists built-in types, and 4.0 Vol 3 Part G, 3.3.3 provides more information on each type.
46+
47+
Save the attribute handles for:
48+
- The ANCS Control Point
49+
- The Client Characteristic Configuration Descriptor for the Notification Source
50+
- The Client Characteristic Configuration Descriptor for the Data Source
51+
52+
## Subscribe to events ##
53+
At minimum, set the Notification Source CCC for notification (indication is not supported) by writing `01 00` to the Notification Source CCC attribute. If you also want to get textual or other data, first subscribe to the Data Source by setting the Data Source CCC for notification, then set the Notification source after that. When you receive a notification, get the textual data from the notification by writing a message to the ANCS Control Point attribute. You will receive a response from the Data Source attribute with the notification id and data requested.
54+
55+
Example incoming notification:
56+
57+
New incoming call (value source is NS handle):
58+
59+
`00` Event ID - Event Added
60+
`02` Event Flags - Important
61+
`01` Category ID - Incoming call
62+
`01` Category Count - 1
63+
`15 00 00 00` Notification UID
64+
65+
Get the caller id (write this to the CP handle)
66+
67+
`00` Command ID - GetNotificationAttributes
68+
`15 00 00 00` Notification UID
69+
`01` Attribute ID - Title
70+
`0B 00` Attribute max length (11 bytes)
71+
72+
Response (value source is DS handle)
73+
74+
`00` Command ID - GetNotificationAttributes
75+
`15 00 00 00` Notification UID
76+
`01` Attribute ID - Title
77+
`0A 00` Attribute length (10 bytes)
78+
`73 6c 61 63 6b 68 61 70 70 79`
79+
80+
81+
## Demo ##
82+
[View video](http://instagram.com/p/jf3HmdQwsb/embed/#)

iOS/ANCS/attributes.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
xgatt_led 17

iOS/ANCS/gatt.xml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<configuration>
3+
4+
<service uuid="1800">
5+
<description>Generic Access Profile</description>
6+
7+
<characteristic uuid="2a00">
8+
<properties read="true" const="true" />
9+
<value>LED</value>
10+
</characteristic>
11+
12+
<characteristic uuid="2a01">
13+
<properties read="true" const="true" />
14+
<value type="hex">4142</value>
15+
</characteristic>
16+
</service>
17+
<service uuid="180A">
18+
<description>Device Information</description>
19+
<characteristic uuid="2a29">
20+
<properties read="true" const="true" />
21+
<value>Bluegiga</value>
22+
</characteristic>
23+
<characteristic uuid="2a28">
24+
<properties read="true" const="true" />
25+
<value>1.0</value>
26+
</characteristic>
27+
<characteristic uuid="2a26">
28+
<properties read="true" const="true" />
29+
<value>25</value>
30+
</characteristic>
31+
<characteristic uuid="2a24">
32+
<properties read="true" const="true" />
33+
<value>BLE112</value>
34+
</characteristic>
35+
</service>
36+
37+
<service uuid="384abbc5-9ad6-4eaa-86af-1ee629ba9838" advertise="true">
38+
<description>LED Control Service</description>
39+
<characteristic uuid="ee7c328f-6d47-4935-96ae-7ab28942074c" id="xgatt_led">
40+
<description>LED Toggle</description>
41+
<properties read="true" write="true" />
42+
<value length="1" type="hex">01</value>
43+
</characteristic>
44+
</service>
45+
46+
<!--
47+
<service uuid="7905F431-B5CE-4E99-A40F-4B1E122D00D0" advertise="true">
48+
<description>ANCS</description>
49+
<characteristic uuid="9FBF120D-6301-42D9-8C58-25E699A21DBD" id="xgatt_ns">
50+
<description>Notification Source</description>
51+
<properties notify="true" />
52+
<value length="1" type="hex">01</value>
53+
</characteristic>
54+
<characteristic uuid="69D1D8F3-45E1-49A8-9821-9BBDFDAAD9D9" id="xgatt_cp">
55+
<description>Control Point</description>
56+
<properties write="true" />
57+
<value length="1" type="hex">01</value>
58+
</characteristic>
59+
</service>
60+
-->
61+
</configuration>
62+

iOS/ANCS/hardware.xml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<hardware>
3+
<sleeposc enable="true" ppm="30" />
4+
<usb enable="false"/>
5+
<txpower power="15" bias="5" />
6+
<script enable="true" />
7+
<usart channel="0" alternate="1" baud="115200" endpoint="none" mode="uart" flow="false"/>
8+
</hardware>

0 commit comments

Comments
 (0)