Skip to content

Commit

Permalink
feat: gap proto extension before sesame (#688)
Browse files Browse the repository at this point in the history
* Extend Gap.proto

* Fix Gap.proto merge artifacts

* Extend Gatt.proto with GattClient and Response services

* Move DIS methods from Gap.proto to Gatt.proto

* Fix Gap.proto changes breaking backwards compatibility

* Add cs echo generation to Gap and Gatt proto

* Add request service only forwarding to  EchoForwarder

* Make proto files style consistent
  • Loading branch information
oguzcanoguz authored Aug 30, 2024
1 parent d272b1f commit d5efa72
Show file tree
Hide file tree
Showing 6 changed files with 320 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ amp-embedded-infra-lib is a young open source project and we love to receive con
* As amp-embedded-infra-lib core-team we have spent considerate effort to make our components testable; please make sure that you have test coverage for your changes as well. Inspiration can be drawn from existing components.
* One of the unique selling points of amp-embedded-infra-lib is not using any heap; don't use the heap in your changes. This excludes using most components from the standard template library, for which we provide heap-less alternatives.
* Ensure cross-platform compatibility for your changes.
* Adhere to the [Coding Standard C++ Embedded Projects]; when in doubt, look at the surrounding code that you are changing and stick to the local style.
* Adhere to the [Coding Standard C++ Embedded Projects](https://github.com/philips-software/amp-embedded-infra-lib/blob/main/documents/modules/ROOT/pages/CodingStandard.adoc); when in doubt, look at the surrounding code that you are changing and stick to the local style.
* Create issues for any major changes and enhancements that you wish to make. Discuss things transparently and get core-team feedback.

### Test are not optional
Expand Down
26 changes: 26 additions & 0 deletions documents/modules/ROOT/pages/Echo.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,32 @@ methods and their parameters. If an unsupported language is targeted,
then the compiler plug-in also has to generate code for encoding and
decoding the individual message.

== Style Guide

=== File Structure

All files should be ordered in the following manner:

1. Syntax
1. Imports (sorted)
1. Package
1. Everything else

=== Naming

All namings should be consistent and easy to read. The following table shows the naming conventions:

|===
| Identifier | Letter Case
| *File name* | MixedCase
| *Message name* | MixedCase
| *Field name* | camelCase
| *Enum type name* | MixedCase
| *Enum value name* | camelCase
| *Service name* | MixedCase
| *Method name* | MixedCase
|===

== Appendix: EchoAttributes.proto

[source,protobuf]
Expand Down
4 changes: 2 additions & 2 deletions services/ble/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
add_library(services.ble ${EMIL_EXCLUDE_FROM_ALL} STATIC)

protocol_buffer_echo_cpp(services.ble Gap.proto)
protocol_buffer_echo_all(services.ble Gap.proto)
protocol_buffer_csharp(services.ble Gap.proto)
protocol_buffer_java(services.ble Gap.proto)

protocol_buffer_echo_cpp(services.ble Gatt.proto)
protocol_buffer_echo_all(services.ble Gatt.proto)
protocol_buffer_csharp(services.ble Gatt.proto)
protocol_buffer_java(services.ble Gatt.proto)

Expand Down
175 changes: 175 additions & 0 deletions services/ble/Gap.proto
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
syntax = "proto3";

import "EchoAttributes.proto";

package gap;
option java_package = "com.philips.emil.protobufEcho";
option java_outer_classname = "GapProto";

message Address
{
bytes address = 1 [(bytes_size) = 6];
}

message State
{
enum Event
{
standby = 0;
scanning = 1;
connected = 2;
advertising = 3;
}
Event value = 1;
}

message IoCapabilities
{
enum IoCapabilitiesEnum
Expand Down Expand Up @@ -41,3 +60,159 @@ message AdvertisementType

AdvertisementTypeEnum type = 1;
}

message SecurityModeAndLevel
{
enum SecurityLevelEnum
{
none = 0;
unauthenticatedPairing = 1;
authenticatedPairing = 2;
authenticatedPairingWithLE = 3;
}

enum SecurityModeEnum
{
mode1 = 0;
mode2 = 1;
}

SecurityModeEnum mode = 1;
SecurityLevelEnum level = 2;
}

message AddressType
{
enum AddressTypeEnum
{
publicAddress = 0;
randomAddress = 1;
}

AddressTypeEnum type = 1;
}

message AdvertisementMode
{
AdvertisementType type = 1;
uint32 advInterval = 2;
}

message AdvertisementData
{
bytes data = 1 [(bytes_size) = 31];
}

message ConnectionParameters
{
Address address = 1;
AddressType addressType = 2;
}

message Passkey
{
int32 passkey = 1;
bool numericComparison = 2;
}

message PairingStatus
{
enum Error
{
passkeyEntryFailed = 0;
authenticationRequirementsNotMet = 1;
pairingNotSupported = 2;
insufficientEncryptionKeySize = 3;
numericComparisonFailed = 4;
timeout = 5;
encryptionFailed = 6;
unknown = 7;
}

Error error = 1;
};

message DiscoveredDevice
{
Address address = 1;
bytes data = 3 [(bytes_size) = 32];
bool isScanResponse = 5;
}

message DeviceDiscoveryFilter
{
enum Filter
{
address = 0;
advertisingData = 1;
}

Filter filter = 1;
bytes data = 2 [(bytes_size) = 32];
};

message BoolValue
{
bool value = 1;
}

message UInt32Value
{
uint32 value = 1;
}

service GapPeripheral
{
option (service_id) = 32;

rpc Advertise(AdvertisementMode) returns (Nothing) { option (method_id) = 1; }
rpc Standby(Nothing) returns (Nothing) { option (method_id) = 2; }
rpc SetAdvertisementData(AdvertisementData) returns (Nothing) { option (method_id) = 3; }
rpc SetScanResponseData(AdvertisementData) returns (Nothing) { option (method_id) = 4; }
rpc SetAllowPairing(BoolValue) returns (Nothing) { option (method_id) = 5; }
rpc SetSecurityMode(SecurityModeAndLevel) returns (Nothing) { option (method_id) = 6; }
rpc SetIoCapabilities(IoCapabilities) returns (Nothing) { option (method_id) = 7; }
rpc RemoveAllBonds(Nothing) returns (Nothing) { option (method_id) = 8; }
rpc GetResolvableAddress(Nothing) returns (Nothing) { option (method_id) = 9; }
}

service GapCentral
{
option (service_id) = 33;

rpc StartDeviceDiscovery(Nothing) returns (Nothing) { option (method_id) = 1; }
rpc StopDeviceDiscovery(Nothing) returns (Nothing) { option (method_id) = 2; }
rpc Connect(ConnectionParameters) returns (Nothing) { option (method_id) = 3; }
rpc Disconnect(Nothing) returns (Nothing) { option (method_id) = 4; }
rpc Pair(Nothing) returns (Nothing) { option (method_id) = 5; }
rpc SetSecurityMode(SecurityModeAndLevel) returns (Nothing) { option (method_id) = 6; }
rpc SetIoCapabilities(IoCapabilities) returns (Nothing) { option (method_id) = 7; }
rpc AuthenticateWithPasskey(UInt32Value) returns (Nothing) { option (method_id) = 8; }
rpc NumericComparisonConfirm(BoolValue) returns (Nothing) { option (method_id) = 9; }
rpc RemoveAllBonds(Nothing) returns (Nothing) { option (method_id) = 10; }
rpc SetDeviceDiscoveryFilter(DeviceDiscoveryFilter) returns (Nothing) { option (method_id) = 11; }
}

service GapPeripheralResponse
{
option (service_id) = 34;

rpc Done(Nothing) returns (Nothing) { option (method_id) = 1; }
rpc DeviceStarted(Nothing) returns (Nothing) { option (method_id) = 2; }
rpc StateChanged(State) returns (Nothing) { option (method_id) = 3; }
rpc ResolvableAddress(Address) returns (Nothing) { option (method_id) = 4; }
rpc DisplayPasskey(Passkey) returns (Nothing) { option (method_id) = 5; }
}

service GapCentralResponse
{
option (service_id) = 35;

rpc Done(Nothing) returns (Nothing) { option (method_id) = 1; }
rpc DeviceDiscovered(DiscoveredDevice) returns (Nothing) { option (method_id) = 2; }
rpc StateChanged(State) returns (Nothing) { option (method_id) = 3; }
rpc PairingSuccessfullyCompleted(Nothing) returns (Nothing) { option (method_id) = 4; }
rpc PairingFailed(PairingStatus) returns (Nothing) { option (method_id) = 5; }
rpc NumberOfBondsChanged(UInt32Value) returns (Nothing) { option (method_id) = 6; }
rpc DeviceStarted(Nothing) returns (Nothing) { option (method_id) = 7; }
}
111 changes: 111 additions & 0 deletions services/ble/Gatt.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,114 @@ message DisServiceData
bytes ieeeRegulatoryCertificationDataList = 8 [(bytes_size) = 32];
bytes pnpId = 9 [(bytes_size) = 7];
}

service GattServerDisService
{
option (service_id) = 132;

rpc SetDisServiceData(DisServiceData) returns(Nothing) { option (method_id) = 1; }
}

message MtuSize
{
uint32 value = 1;
}

message Handle
{
uint32 value = 1;
}

message CharacteristicData
{
Handle handle = 1;
bytes data = 2 [(bytes_size) = 512];
}

message HandleRange
{
Handle startHandle = 1;
Handle endHandle = 2;
}

message Service
{
bytes uuid = 1 [(bytes_size) = 16];
HandleRange handles = 2;
}

message Characteristic
{
bytes uuid = 1 [(bytes_size) = 16];
Handle handle = 2;
Handle valueHandle = 3;
uint32 properties = 4;
}

message Descriptr
//'Descriptor' keyword is not allowed by Echo code generator
{
bytes uuid = 1 [(bytes_size) = 16];
Handle handle = 2;
}

message GattResult
{
enum ResultEnum
{
Success = 0;
InsufficientAuthentication = 1;
UnknownError = 2;
}

ResultEnum result = 1;
}

message ReadResult
{
GattResult result = 1;
CharacteristicData data = 2;
}

service GattClient
{
option (service_id) = 134;

rpc MtuSizeExchangeRequest(Nothing) returns (Nothing) { option (method_id) = 1; }

rpc StartServiceDiscovery(Nothing) returns (Nothing) { option (method_id) = 2; }
rpc StopServiceDiscovery(Nothing) returns (Nothing) { option (method_id) = 3; }

rpc StartCharacteristicDiscovery(HandleRange) returns (Nothing) { option (method_id) = 4; }
rpc StopCharacteristicDiscovery(Nothing) returns (Nothing) { option (method_id) = 5; }

rpc StartDescriptorDiscovery(HandleRange) returns (Nothing) { option (method_id) = 6; }
rpc StopDescriptorDiscovery(Nothing) returns (Nothing) { option (method_id) = 7; }

rpc Read(Handle) returns (Nothing) { option (method_id) = 8; }
rpc Write(CharacteristicData) returns (Nothing) { option (method_id) = 9; }
rpc WriteWithoutResponse(CharacteristicData) returns (Nothing) { option (method_id) = 10; }
}

service GattClientResponse
{
option (service_id) = 135;

rpc MtuSizeExchangeComplete(MtuSize) returns (Nothing) { option (method_id) = 1; }

rpc ServiceDiscovered(Service) returns (Nothing) { option (method_id) = 2; }
rpc ServiceDiscoveryComplete(Nothing) returns (Nothing) { option (method_id) = 3; }

rpc CharacteristicDiscovered(Characteristic) returns (Nothing) { option (method_id) = 4; }
rpc CharacteristicDiscoveryComplete(Nothing) returns (Nothing) { option (method_id) = 5; }

rpc DescriptorDiscovered(Descriptr) returns (Nothing) { option (method_id) = 6; }
rpc DescriptorDiscoveryComplete(Nothing) returns (Nothing) { option (method_id) = 7; }

rpc ReadComplete(ReadResult) returns (Nothing) { option (method_id) = 8; }
rpc WriteComplete(GattResult) returns (Nothing) { option (method_id) = 9; }

rpc IndicationReceived(CharacteristicData) returns (Nothing) { option (method_id) = 10; }
rpc NotificationReceived(CharacteristicData) returns (Nothing) { option (method_id) = 11; }
}

5 changes: 5 additions & 0 deletions services/util/EchoInstantiation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ namespace main_
AddForwarder(to, responseId, from);
}

void AddRequest(uint32_t serviceId)
{
AddForwarder(from, serviceId, to);
}

void AddResponse(uint32_t responseId)
{
AddForwarder(to, responseId, from);
Expand Down

0 comments on commit d5efa72

Please sign in to comment.