Skip to content

Commit

Permalink
fix(ble): return types
Browse files Browse the repository at this point in the history
  • Loading branch information
andelf committed Nov 21, 2023
1 parent 8ad1336 commit 727b929
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 27 deletions.
44 changes: 22 additions & 22 deletions src/ble/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,34 +53,34 @@ pub type BOOL = u8;
// UUID defined
extern "C" {
// GATT Services
pub static gapServiceUUID: [u8; 0usize];
pub static gattServiceUUID: [u8; 0usize];
pub static gapServiceUUID: [u8; 2];
pub static gattServiceUUID: [u8; 2];

// GATT Attribute Types
pub static primaryServiceUUID: [u8; 0usize];
pub static secondaryServiceUUID: [u8; 0usize];
pub static includeUUID: [u8; 0usize];
pub static characterUUID: [u8; 0usize];
pub static primaryServiceUUID: [u8; 2];
pub static secondaryServiceUUID: [u8; 2];
pub static includeUUID: [u8; 2];
pub static characterUUID: [u8; 2];

// GATT Characteristic Descriptors
pub static charExtPropsUUID: [u8; 0usize];
pub static charUserDescUUID: [u8; 0usize];
pub static clientCharCfgUUID: [u8; 0usize];
pub static servCharCfgUUID: [u8; 0usize];
pub static charFormatUUID: [u8; 0usize];
pub static charAggFormatUUID: [u8; 0usize];
pub static validRangeUUID: [u8; 0usize];
pub static extReportRefUUID: [u8; 0usize];
pub static reportRefUUID: [u8; 0usize];
pub static charExtPropsUUID: [u8; 2];
pub static charUserDescUUID: [u8; 2];
pub static clientCharCfgUUID: [u8; 2];
pub static servCharCfgUUID: [u8; 2];
pub static charFormatUUID: [u8; 2];
pub static charAggFormatUUID: [u8; 2];
pub static validRangeUUID: [u8; 2];
pub static extReportRefUUID: [u8; 2];
pub static reportRefUUID: [u8; 2];

// GATT Characteristic Types
pub static deviceNameUUID: [u8; 0usize];
pub static appearanceUUID: [u8; 0usize];
pub static periPrivacyFlagUUID: [u8; 0usize];
pub static reconnectAddrUUID: [u8; 0usize];
pub static periConnParamUUID: [u8; 0usize];
pub static serviceChangedUUID: [u8; 0usize];
pub static centAddrResUUID: [u8; 0usize];
pub static deviceNameUUID: [u8; 2];
pub static appearanceUUID: [u8; 2];
pub static periPrivacyFlagUUID: [u8; 2];
pub static reconnectAddrUUID: [u8; 2];
pub static periConnParamUUID: [u8; 2];
pub static serviceChangedUUID: [u8; 2];
pub static centAddrResUUID: [u8; 2];
}

/*** Opcode fields: bitmasks ***/
Expand Down
13 changes: 12 additions & 1 deletion src/ble/gap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,18 @@ extern "C" {
#[doc = " @brief used to cancel the HCI_LE_Periodic_Advertising_Create_Sync command while\n it is pending.\n\n @param None.\n\n @return bStatus_t: HCI Error Code.<BR>\n"]
pub fn GAPRole_CancelSync() -> bStatus_t;

}

// FUNCTIONS - Initialization and Configuration
extern "C" {
#[doc = " @brief Set a GAP Parameter value. Use this function to change the default GAP parameter values.\n\n @param paramID - parameter ID: @ref GAP_PARAMETER_ID_DEFINES\n @param paramValue - new param value\n\n @return SUCCESS or INVALIDPARAMETER (invalid paramID)"]
pub fn GAP_SetParamValue(paramID: u16, paramValue: u16) -> bStatus_t;

#[doc = " @brief Get a GAP Parameter value.\n\n @note This function is the same as GAP_PasskeyUpdate(), except that\n the passkey is passed in as a non-string format.\n\n @param paramID - parameter ID: @ref GAP_PARAMETER_ID_DEFINES\n\n @return GAP Parameter value or 0xFFFF if invalid"]
pub fn GAP_GetParamValue(paramID: u16) -> u16;
#[doc = " @brief Setup the device's address type. If ADDRTYPE_PRIVATE_RESOLVE is selected,\n the address will change periodically.\n\n @param addrType - @ref GAP_ADDR_TYPE_DEFINES\n @param pStaticAddr - Only used with ADDRTYPE_STATIC or ADDRTYPE_PRIVATE_NONRESOLVE type\n NULL to auto generate otherwise the application can specify the address value\n\n @return SUCCESS: address type updated,<BR>\n bleNotReady: Can't be called until GAP_DeviceInit() is called\n and the init process is completed\n bleIncorrectMode: can't change with an active connection,or INVALIDPARAMETER\n If return value isn't SUCCESS, the address type remains the same as before this call."]
pub fn GAP_ConfigDeviceAddr(addrType: u8, pStaticAddr: *mut u8) -> bStatus_t;
#[doc = " @brief Resolves a private address against an IRK.\n\n @param(in) pIRK - pointer to the IRK\n @param(in) pAddr - pointer to the Resolvable Private address\n\n @param(out) pIRK\n @param(out) pAddr\n\n @return SUCCESS: match,<BR>\n FAILURE: don't match,<BR>\n INVALIDPARAMETER: parameters invalid<BR>"]
pub fn GAP_ResolvePrivateAddr(pIRK: *mut u8, pAddr: *mut u8) -> bStatus_t;
#[doc = " @brief Setup or change advertising and scan response data.\n\n @note if the return status from this function is SUCCESS,the task isn't complete\n until the GAP_ADV_DATA_UPDATE_DONE_EVENT is sent to the calling application task.\n\n @param taskID - task ID of the app requesting the change\n @param adType - TRUE - advertisement data, FALSE - scan response data\n @param dataLen - Octet length of advertData\n @param pAdvertData - advertising or scan response data\n\n @return SUCCESS: data accepted\n bleIncorrectMode: invalid profile role"]
pub fn GAP_UpdateAdvertisingData(taskID: u8, adType: u8, dataLen: u16, pAdvertData: *mut u8) -> bStatus_t;
}
55 changes: 55 additions & 0 deletions src/ble/gatt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,61 @@

use super::ffi::tmos_event_hdr_t;

// ATT Error Codes
/// The attribute handle given was not valid on this server
pub const ATT_ERR_INVALID_HANDLE: u8 = 0x01;

/// The attribute cannot be read
pub const ATT_ERR_READ_NOT_PERMITTED: u8 = 0x02;

/// The attribute cannot be written
pub const ATT_ERR_WRITE_NOT_PERMITTED: u8 = 0x03;

/// The attribute PDU was invalid
pub const ATT_ERR_INVALID_PDU: u8 = 0x04;

/// The attribute requires authentication before it can be read or written
pub const ATT_ERR_INSUFFICIENT_AUTHEN: u8 = 0x05;

/// Attribute server does not support the request received from the client
pub const ATT_ERR_UNSUPPORTED_REQ: u8 = 0x06;

/// Offset specified was past the end of the attribute
pub const ATT_ERR_INVALID_OFFSET: u8 = 0x07;

/// The attribute requires authorization before it can be read or written
pub const ATT_ERR_INSUFFICIENT_AUTHOR: u8 = 0x08;

/// Too many prepare writes have been queued
pub const ATT_ERR_PREPARE_QUEUE_FULL: u8 = 0x09;

/// No attribute found within the given attribute handle range
pub const ATT_ERR_ATTR_NOT_FOUND: u8 = 0x0a;

/// The attribute cannot be read using the Read Blob Request
pub const ATT_ERR_ATTR_NOT_LONG: u8 = 0x0b;

/// The Encryption Key Size used for encrypting this link is insufficient
pub const ATT_ERR_INSUFFICIENT_KEY_SIZE: u8 = 0x0c;

/// The attribute value length is invalid for the operation
pub const ATT_ERR_INVALID_VALUE_SIZE: u8 = 0x0d;

/// The attribute request that was requested has encountered an error that was very unlikely, and therefore could not be completed as requested
pub const ATT_ERR_UNLIKELY: u8 = 0x0e;

/// The attribute requires encryption before it can be read or written
pub const ATT_ERR_INSUFFICIENT_ENCRYPT: u8 = 0x0f;

/// The attribute type is not a supported grouping attribute as defined by a higher layer specification
pub const ATT_ERR_UNSUPPORTED_GRP_TYPE: u8 = 0x10;

/// Insufficient Resources to complete the request
pub const ATT_ERR_INSUFFICIENT_RESOURCES: u8 = 0x11;

/// The attribute value is invalid for the operation
pub const ATT_ERR_INVALID_VALUE: u8 = 0x80;

// tmos event
#[doc = " GATT tmos GATT_MSG_EVENT message format. This message is used to forward an\n incoming attribute protocol/profile message up to upper layer application."]
#[repr(C)]
Expand Down
4 changes: 2 additions & 2 deletions src/ble/gattservapp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub struct GATTServApp;
impl GATTServApp {
#[inline]
pub fn register_service(
attrs: *const gattAttribute_t,
attrs: *mut gattAttribute_t,
num_attrs: u16,
enc_key_size: u8,
service_cbs: &'static gattServiceCBs_t,
Expand Down Expand Up @@ -172,7 +172,7 @@ mod ffi {
extern "C" {
#[doc = " @brief Register a service's attribute list and callback functions with\n the GATT Server Application.\n\n @param pAttrs - Array of attribute records to be registered\n @param numAttrs - Number of attributes in array\n @param encKeySize - Minimum encryption key size required by service (7-16 bytes)\n @param pServiceCBs - Service callback function pointers\n\n @return SUCCESS: Service registered successfully.<BR>\n INVALIDPARAMETER: Invalid service fields.<BR>\n FAILURE: Not enough attribute handles available.<BR>\n bleMemAllocError: Memory allocation error occurred.<BR>\n bleInvalidRange: Encryption key size's out of range.<BR>"]
pub fn GATTServApp_RegisterService(
pAttrs: *const gattAttribute_t,
pAttrs: *mut gattAttribute_t,
numAttrs: u16,
encKeySize: u8,
pServiceCBs: *const gattServiceCBs_t,
Expand Down
2 changes: 0 additions & 2 deletions src/ble/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ fn configure_pa(pa_config: PaConfig) {

core::mem::forget(tx_pin);
core::mem::forget(rx_pin);

println!("pa => {:x?}", PA_CONFIG);
}
}

Expand Down

0 comments on commit 727b929

Please sign in to comment.