You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By default, Crownstones have encryption enabled as a security and privacy measure.
Setup mode
When a Crownstone is new or factory reset, it will go into setup mode.
Setup mode turns down the power of the antenna (low TX) so you can only communicate with it when you're close by. The purpose of this mode
is to configure the Crownstone so only you, or people in your group, can communicate with it.
Phone reads the Crownstone MAC address (required for iOS). This characteristic is not encrypted.
Phone reads the session key and session nonce from the setup service. These characteristics are not encrypted.
The values are only valid for this connection session. The session key and the session nonce will be used to encrypt the rest of the setup phase using AES 128 CTR as explained here.
Phone starts setting up the Crownstone using the config control characteristic
Values that are read from the characteristics will be encrypted
Values that are written to the characteristics will have to be encrypted
Session nonce
After connecting, you first have to read the session nonce from the Crownstone service. The session nonce is ECB encrypted with the guest key. After decryption, you should verify whether you have read and decrypted succesfully by checking if the validation key in the data is equal to 0xCAFEBABE. If so, you now have the correct session nonce.
The session nonce has two purposes:
Validation: the first 4 bytes of the session nonce is what we call the validation key, it is used for any encrypted packet.
Encryption: the whole 5 bytes are used for the nonce, which is used for CTR encryption. The first 3 bytes of the nonce are the packet nonce (which should be randomly generated each time you write to a characteristic), the last 5 are the session nonce.
The session nonce and validation key are only valid during the connection.
Session nonce after ECB decryption
Type
Name
Length
Description
uint 32
Validation key
4
0xCAFEBABE as validation.
byte array
Session nonce
5
The session nonce for this session.
byte array
Padding
7
Zero-padding so that the whole packet is 16 bytes.
Reading and writing characteristics
We use the AES 128 CTR method to encrypt everything that is written to- and read from characteristics. For this you need an 8 byte number called a nonce. The first 3 bytes of the nonce are sent with each packet, we call this the packet nonce. When writing to a characteristic, you should generate a new random packet nonce each time. The last 5 bytes of the nonce are called the session nonce, which should be read after connecting. When reading a characteristic, you should check if the (decrypted) validation key is equal to the validation key that was read after connecting.
Encrypted Packet
Type
Name
Length
Description
byte array
Packet nonce
3
First 3 bytes of nonce used in the encryption of this message.
Used to verify that the correct key was used for decryption/encryption.
byte array
Payload
Whatever data would have been sent if encryption was disabled.
byte array
Padding
Zero-padding so that the whole packet is of size N*16 bytes.
Advertisements and scan response
When no device is connected, advertisements will be sent at a regular interval (100ms by default). A device that actively scans, will also receive a scan response packet. This contains useful info about the state.
iBeacon advertisement packet
This packet is according to iBeacon spec, see for example here.
This packet contains the state info. If encryption is enabled, the last 16 bytes will be encrypted using AES 128 ECB using the guest key.
You receive a MAC address on Android and an UUID on iOS for each advertisement packet. This allows you to get the Crownstone ID associated with the packet and you verify the decryption by checking the expected Crownstone ID against the one in the packet.
Bitflags to indicate a certain state of the Crownstone.
int 8
Temperature
1
Chip temperature (°C)
int 32
Power usage
4
The power usage at this moment (mW).
int 32
Accumulated energy
4
The accumulated energy (Wh).
uint 8[]
Rand
3
Random bytes.
Event Bitmask
Bit
Name
Description
0
New data available
If you request something from the Crownstone and the result is available, this will be 1.
1
Showing external data
If this is 1, the shown ID and data is from another Crownstone.
2
Error
If this is 1, the Crownstone has an error, you should check what error it is.
3
Reserved
Reserved for future use.
4
Reserved
Reserved for future use.
5
Reserved
Reserved for future use.
6
Reserved
Reserved for future use.
7
Setup mode active
If this is 1, the Crownstone is in setup mode.
Switch State Packet
To be able to distinguish between switching with relay and switching with PWM, the switch state is a bit struct with
the following layout
Bit 7 is used for the relay flag, where 0 = OFF, 1 = ON.
Bits 6-0 are used for PWM, where 100 is fully ON, 0 is OFF, dimmed in between.
Services
When connected, the following services are available.
The AUG columns indicate which users can use these characteristics if encryption is enabled. The access can be further restricted per packet. Dots (..) indicate encryption is not enabled for that characteristic.
A = Admin
U = User
G = Guest
Crownstone service
The crownstone service has UUID 24f00000-7d10-4805-bfc1-7663a01c3bff and provides all the functionality of the Crownstone through the following services
If you lose your encryption keys you can use this characteristic to factory reset the Crownstone.
This method is only available for 20 seconds after the Crownstone powers on.
You need to write 0xDEADBEEF to it. After this, the Crownstone disconnects and goes into Low TX mode so you'll have to be close to continue the factory reset. After this, you reconnect and write 0xDEADBEEF again to this characteristic to factory reset the Crownstone.
Return values
The control characteristics (Control, Mesh Control, Config Control and State Control) of the Crownstone service return a uint16 code on execution of the command.
The code determines success or failure of the command. If commands have to be executed sequentially, make sure that the return value of the previous command
was received before calling the next (either by polling or subscribing). The possible values of the return values are listed in the table below
Value
Name
Description
0
SUCCESS
completed successfully
1
VALUE_UNDEFINED
no value provided
2
WRONG_PAYLOAD_LENGTH
wrong payload lenght provided
3
UNKNOWN_OP_CODE
unknown operation code, e.g. notify for config read
5
BUFFER_LOCKED
buffer is locked, failed queue command
6
BUFFER_TOO_SMALL
buffer is too small to execute command
256
COMMAND_NOT_FOUND
command type not found
257
NOT_AVAILABLE
command not available in this mode
258
WRONG_PARAMETER
wrong parameter provided
259
COMMAND_FAILED
other failure
260
NOT_IMPLEMENTED
command not implemented (only debug version)
512
INVALID_MESSAGE
invalid mesh message provided
768
READ_CONFIG_FAILED
read configuration failed
769
WRITE_CONFIG_DISABLED
write configuration disalbed for this type
770
CONFIG_NOT_FOUND
config type not found
1024
STATE_NOT_FOUND
state type not found
1025
STATE_WRITE_DISABLED
writing to state disabled
Setup service
The setup service has UUID 24f10000-7d10-4805-bfc1-7663a01c3bff and is only available after a factory reset or when you first power on the Crownstone.
When encryption is enabled, the control and both config characteristics are encrypted with AES CTR. The key and session Nonce for this are gotten from their
characteristics.
Read or Notify on a previously selected config setting
GoTo DFU
24f10006-7d10-4805-bfc1-7663a01c3bff
uint 8
Write 66 to go to DFU
Session nonce
24f10008-7d10-4805-bfc1-7663a01c3bff
uint 8 [5]
Read the session nonce. First 4 bytes are also used as validation key.
The control characteristics (Control, and Config Control) of the Setup Service return a uint 16 code on execution of the command. The code determines success or failure of the command. If commands have to be executed sequentially, make sure that the return value of the previous command was received before calling the next (either by polling or subscribing). The possible values are the same as for the Crownstone Service, see above.
General service
The general service has UUID 24f20000-7d10-4805-bfc1-7663a01c3bff.
Characteristic
UUID
Date type
Description
A
U
G
Temperature
24f20001-7d10-4805-bfc1-7663a01c3bff
int 32
Chip temperature in Celcius. Notifications are available.
x
Reset
24f20002-7d10-4805-bfc1-7663a01c3bff
uint 8
Write 1 to reset. Write 66 to go to DFU mode.
x
Power service
The power service has UUID 24f30000-7d10-4805-bfc1-7663a01c3bff. Should be encrypted but it is not at the moment due to implementation.
Characteristic
UUID
Date type
Description
A
U
G
PWM
24f30001-7d10-4805-bfc1-7663a01c3bff
uint 8
Set PWM value. Value of 0 is completely off, 255 (100 on new devices) is completely on.
The mesh service comes with OpenMesh and has UUID 0000fee4-0000-1000-8000-00805f9b34fb
Characteristic
UUID
Date type
Description
A
U
G
Meta data
2a1e0004-fd51-d882-8ba8-b98c0000cd1e
Get mesh configuration.
x
Value
2a1e0005-fd51-d882-8ba8-b98c0000cd1e
Characteristic where the mesh values can be read.
x
Data structures
Control packet
#####If encryption is enabled, this packet must be encrypted using any of the keys where the box is checked.
In the case of the setup mode, only the Validate Setup command is available unencrypted.
Type
Name
Length
Description
uint 8
Type
1
Command type, see table below.
uint 8
Reserved
1
Not used: reserved for alignment.
uint 16
Length
2
Length of the payload in bytes.
uint 8
Payload
Length
Payload data, depends on type.
The AUG columns indicate which users have access to these commands if encryption is enabled.
Admin access means the packet is encrypted with the admin key.
A: Admin
U: User
G: Guest
Available command types:
Type nr
Type name
Payload type
Payload Description
A
U
G
0
Switch
uint 8
Switch power, 0 = OFF, 100 = FULL ON
x
x
x
1
PWM
uint 8
Set PWM to value, 0 = OFF, 100 = FULL ON
x
x
x
2
Set Time
uint 32
Set time to value, where value is seconds since 1970-01-01 00:00:00 UTC
x
x
3
Goto DFU
-
Reset device to DFU mode
x
4
Reset
uint 8
Reset device
x
5
Factory reset
uint 32
Reset device to factory setting, needs Code 0xdeadbeef as payload
Reset all errors which are set in the written bitmask.
x
Enable Scanner payload
Type
Name
Description
uint 8
enable
0 = OFF, other = ON
uint 16
delay
start scanner with delay in ms
Keep alive payload
Type
Name
Description
uint 8
Action
Action, 0 = No Change, 1 = Change
uint 8
Switch
Switch power, 0 = OFF, 100 = FULL ON
uint 16
Timeout
Timeout in seconds after which the Switch should be adjusted to the Switch value
Configuration packet
#####If encryption is enabled, this packet must be encrypted using the admin key.
Type
Name
Length
Description
uint 8
Type
1
Type, see table with configuration types below.
uint 8
OpCode
1
The op code determines if it's a write or a read operation, see table with op codes below
uint 16
Length
2
Length of the payload in bytes.
uint 8
Payload
Length
Payload data, depends on type.
Available configurations types:
Type nr
Type name
Payload type
Description
0
Device name
char []
Name of the device.
1
Device type
char []
Deprecated.
2
Room
uint 8
Deprecated.
3
Floor
uint 8
Floor number. Deprecated
4
Nearby timeout
uint 16
Time in ms before switching off when none is nearby
5
PWM period
uint 32
Sets PWM period in μs. Setting this to a wrong value may cause damage.
6
iBeacon major
uint 16
iBeacon major number.
7
iBeacon minor
uint 16
iBeacon minor number.
8
iBeacon UUID
uint 8 [16]
iBeacon UUID.
9
iBeacon Tx Power
int 8
iBeacon signal strength at 1 meter.
11
TX power
int 8
TX power, can be: -40, -30, -20, -16, -12, -8, -4, 0, or 4.
12
Advertisement interval
uint 16
Advertisement interval between 0x0020 and 0x4000 in units of 0.625 ms.
13
Passkey
uint 8 [6]
Passkey of the device: must be 6 digits.
14
Min env temp
int 8
If temperature (in degrees Celcius) goes below this value, send an alert (not implemented yet).
15
Max env temp
int 8
If temperature (in degrees Celcius) goes above this value, send an alert (not implemented yet).
16
Scan duration
uint 16
Scan duration in ms. Setting this too high may cause the device to reset during scanning.
17
Scan send delay
uint 16
Time in ms to wait before sending scan results over the mesh. Setting this too low may cause the device to reset during scanning.
18
Scan break duration
uint 16
Waiting time in ms between sending results and next scan. Setting this too low may cause the device to reset during scanning.
19
Boot delay
uint 16
Time to wait with radio after boot, Setting this too low may cause the device to reset on boot.
20
Max chip temp
int 8
If the chip temperature (in degrees Celcius) goes above this value, the power gets switched off.
21
Scan filter
uint 8
Filter out certain types of devices from the scan results (1 for GuideStones, 2 for CrownStones, 3 for both).
22
Scan filter fraction
uint 16
If scan filter is set, do not filter them out each every X scan results.
23
Current limit
uint 8
Set current limit to Deprecated
24
Mesh enabled
uint 8
Stores if mesh is enabled. read only
25
Encryption enabled
uint 8
Stores if encryption is enabled. read only
26
iBeacon enabled
uint 8
Stores if iBeacon is enabled. read only
27
Scanner enabled
uint 8
Stores if device scanning is enabled. read only
28
Continuous power measurement enabled
uint 8
Stores if continuous power measurement is enabled. read only
29
Tracker enabled
uint 8
Stores if device tracking is enabled. read only
30
ADC sample rate
...
TBD
31
Power sample burst interval
...
TBD
32
Power sample continuous interval
...
TBD
33
Power sample continuous number samples
...
TBD
34
Crownstone Identifier
uint 16
Crownstone identifier used in advertisement package
35
Admin encryption key
uint 8 [16]
16 byte key used to encrypt/decrypt owner access functions
36
Member encryption key
uint 8 [16]
16 byte key used to encrypt/decrypt member access functions
37
Guest encryption key
uint 8 [16]
16 byte key used to encrypt/decrypt guest access functions
38
Default ON
uint 8
Set's the default switch state to 255 if true, or to 0 if false. Value is 0 for false, or any other for true
39
Scan Interval
uint 16
Set the scan interval to ...
40
Scan Window
uint 16
Set the scan window to ...
41
Relay High Duration
uint 16
Set the time/duration that the relay is set to high
42
Low Tx Power
int 8
Set the tx power used when in low transmission power for bonding
43
Voltage Multiplier
float
Set the voltage multiplier (for power measurement)
44
Current Multiplier
float
Set the current multiplier (for power measurement)
45
Voltage Zero
int 32
Set the voltage zero level (for power measurement)
46
Current Zero
int 32
Set the current zero level (for power measurement)
47
Power Zero
int 32
Set the power zero level in mW (for power measurement)
48
Power Average Window
uint16
Deprecated
49
Mesh Access Address
uint32
The access address of the mesh messages. This ensures that mesh messages of other groups will not interfere with your group.
OpCodes:
OpCode
Name
Description
0
Read
Select the configuration setting for reading. will load it from storage, then write it to the Config Read Characteristic. Length and payload of the configuration packet will be ignored
1
Write
Write the configuration setting to storage.
Note: On the Config Read Characteristic, the OpCode is set to Read (0), and the length and payload will have actual data depending on the type.
State packet
Type
Name
Length
Description
uint 8
Type
1
Type, see table with configuration types below.
uint 8
OpCode
1
The op code determines if it's a write, read, or notify operation, see table with op codes below
Select the configuration setting for reading. will load it from storage, then write it to the Config Read Characteristic. Length and payload of the configuration packet will be ignored
1
Write
Write the state variable disabled
2
Notify
Enable/Disable notifications for state variable. Every time the state variable is updated, the new value is written to the State Read Characteristic. To use effectively, enable GATT Notifications on the State Read Characteristic. Length has to be 1, and payload is 0 = disable, other = enable
Note: On the State Read Characteristic, the OpCode is also set to distinguish between a one time read, and a continuous notification. In return, the length and payload will have actual data depending on the type.
Error Bitmask
Bit
Name
Description
0
Overcurrent
If this is 1, overcurrent was detected.
1
Overcurrent dimmer
If this is 1, overcurrent for the dimmer was detected.
2
Chip temperature
If this is 1, the chip temperature is too high.
3
Dimmer temperature
If this is 1, the dimmer temperature is too high.
4-31
Reserved
Reserved for future use.
Power samples packet
Type
Name
Length
Description
uint 16
numCurrentSamples
2
Number of current samples.
uint 16 []
currentSamples
numCurrentSamples * 2
Array of current samples.
uint 16
numVoltageSamples
2
Number of voltage samples.
uint 16 []
voltageSamples
numVoltageSamples * 2
Array of voltage samples.
uint 16
numCurrentTimeStamps
2
Number of current timestamps.
uint 32
firstCurrentTimeStamp
4
Timestamp of first current sample.
uint 32
lastCurrentTimeStamp
4
Timestamp of last current sample.
int 8 []
currentTimeDiffs
numCurrentTimeStamps-1
Array of differences with previous timestamp.
uint 16
numVoltageTimeStamps
2
Number of voltage timestamps.
uint 32
firstVoltageTimeStamp
4
Timestamp of first voltage sample.
uint 32
lastVoltageTimeStamp
4
Timestamp of last voltage sample.
int 8 []
voltageTimeDiffs
numVoltageTimeStamps-1
Array of differences with previous timestamp.
Power curve packet, deprecated
Type
Name
Length
Description
uint 16
numSamples
2
Number of current samples + voltage samples, including the first samples.
uint 16
firstCurrent
2
First current sample.
uint 16
lastCurrent
2
Last current sample.
uint 16
firstVoltage
2
First voltage sample.
uint 16
lastVoltage
2
Last voltage sample.
uint 32
firstTimeStamp
4
Timestamp of first current sample.
uint 32
lastTimeStamp
4
Timestamp of last sample.
int 8 []
currentDiffs
numSamples/2-1
Array of differences with previous current sample.
int 8 []
voltageDiffs
numSamples/2-1
Array of differences with previous voltage sample.
This packet is encrypted and sent as payload in the encrypted mesh packet.
Type
Name
Length
Description
uint 32
Message counter
4
The message counter used to identify the message. Counter values are kept up seperately per handle. Note: This value will be compared after decryption to the message counter of the encrypted mesh message to make sure the message was not tampered with.
Channel on which the keep alive messages are sent. A message consists of a global timeout and a number of keep alive items (on per stone which is addressed). If the length of the mesh control packet is 0, the existing keepalive message will be repeated.
Each stone sends it's state periodically over the mesh. The message is designed as a circular buffer and a new item is added at the end (throwing out the oldest if full)
Commands can be sent to one, multiple or all stones sharing the mesh network. Once a stone receives a command it will send a reply on the reply channel
This channel is used to send different switch commands with individual timeouts, switch states and intents to different crownstones in one message
Keep alive packet
If the length of the mesh control packet is 0, the existing keepalive message will be repeated. This is used to delay the existing time outs by people who do not have permission to change the state.
Type
Name
Length
Description
uint 16
Timeout
2
Timeout (in seconds), applies to all stones present in the list
The number of IDs provided as targets, 0 for broadcast
uint16 []
List of target IDs
Number of IDs
Crownstone Identifiers of the devices at which this message is aimed, for broadcast, no IDs are provided and the command follows directly after the Number of IDs element
uint 8
Command payload
N
The command payload data, which depends on the message type
Each mesh data message is notified in multiple pieces, as a notification can only be 20 bytes. The op code of the Mesh notification tells whether it is a single, or the first, last or a middle piece of a multipart message.
Type
Name
Length
Description
uint 16
Handle
2
Handle on which the messages was sent or received.
uint 8
Length
1
Length of the data of this part.
uint 8
Data
Length
Data of this part. If OpCode is Data, it is the length of the whole mesh message, otherwise it is the length of the current part.