added security levels to CharacteristicConfig with linux implementation by gkong · Pull Request #413 · tinygo-org/bluetooth
This commit adds a new type - SecurityLevel - and adds instances of it to CharacteristicConfig, for each of: read, write, notify, and indicate.
The default (zero) value is no encryption, so existing user code should be unaffected.
A godoc-visible comment notes that setting a non-default value may result in the peer initiating a pairing operation.
This commit includes a linux implementation which has been tested on Alpine linux. It passes smoketest-linux. If user code specifies a non-default SecurityLevel on any other platform, it will be silently ignored.
Here is a working example CharacteristicConfig which includes a non-default security level:
{
Handle: &rxChx,
UUID: rxUUID,
Flags: bluetooth.CharacteristicWritePermission |
bluetooth.CharacteristicWriteWithoutResponsePermission,
WriteSecurity: bluetooth.SecurityEncryptedAuthenticated,
WriteEvent: func(client bluetooth.Connection, offset int, value []byte) {
fmt.Printf("RX (%d bytes): %s\n", len(value), string(value))
},
}