Skip to content
Snippets Groups Projects
Commit c345e132 authored by Hauke Mehrtens's avatar Hauke Mehrtens
Browse files

BLE: FileTrans: Use const service registration


The dynamic registration is not needed and it only has a limited number
of memory, use static service data for registration.

Signed-off-by: default avatarHauke Mehrtens <hauke@hauke-m.de>
parent 08d8d9a1
Branches patch-2
No related tags found
No related merge requests found
...@@ -81,6 +81,7 @@ enum { ...@@ -81,6 +81,7 @@ enum {
static const uint8_t fileTransSvc[] = { FILE_TRANS_UUID_SUFFIX, static const uint8_t fileTransSvc[] = { FILE_TRANS_UUID_SUFFIX,
0x00, 0x00,
FILE_TRANS_UUID_PREFIX }; FILE_TRANS_UUID_PREFIX };
static const uint16_t fileTransSvc_len = sizeof(fileTransSvc);
/* BLE File transfer Central TX configuration */ /* BLE File transfer Central TX configuration */
static const uint8_t txChConfig[] = { ATT_PROP_WRITE_NO_RSP, static const uint8_t txChConfig[] = { ATT_PROP_WRITE_NO_RSP,
...@@ -89,10 +90,14 @@ static const uint8_t txChConfig[] = { ATT_PROP_WRITE_NO_RSP, ...@@ -89,10 +90,14 @@ static const uint8_t txChConfig[] = { ATT_PROP_WRITE_NO_RSP,
FILE_TRANS_UUID_SUFFIX, FILE_TRANS_UUID_SUFFIX,
0x01, 0x01,
FILE_TRANS_UUID_PREFIX }; FILE_TRANS_UUID_PREFIX };
static const uint16_t txChConfig_len = sizeof(txChConfig);
/* BLE File transfer Central TX UUID */ /* BLE File transfer Central TX UUID */
static const uint8_t attTxChConfigUuid[] = { FILE_TRANS_UUID_SUFFIX, static const uint8_t attTxChConfigUuid[] = { FILE_TRANS_UUID_SUFFIX,
0x01, 0x01,
FILE_TRANS_UUID_PREFIX }; FILE_TRANS_UUID_PREFIX };
static uint8_t attTxChConfigValue[128];
static uint16_t attTxChConfigValue_len = sizeof(attTxChConfigUuid);
/* BLE File transfer Central RX configuration */ /* BLE File transfer Central RX configuration */
static const uint8_t rxChConfig[] = { ATT_PROP_READ | ATT_PROP_NOTIFY, static const uint8_t rxChConfig[] = { ATT_PROP_READ | ATT_PROP_NOTIFY,
...@@ -101,92 +106,76 @@ static const uint8_t rxChConfig[] = { ATT_PROP_READ | ATT_PROP_NOTIFY, ...@@ -101,92 +106,76 @@ static const uint8_t rxChConfig[] = { ATT_PROP_READ | ATT_PROP_NOTIFY,
FILE_TRANS_UUID_SUFFIX, FILE_TRANS_UUID_SUFFIX,
0x02, 0x02,
FILE_TRANS_UUID_PREFIX }; FILE_TRANS_UUID_PREFIX };
static const uint16_t rxChConfig_len = sizeof(rxChConfig);
/* BLE File transfer Central RX UUID */ /* BLE File transfer Central RX UUID */
static const uint8_t attRxChConfigUuid[] = { FILE_TRANS_UUID_SUFFIX, static const uint8_t attRxChConfigUuid[] = { FILE_TRANS_UUID_SUFFIX,
0x02, 0x02,
FILE_TRANS_UUID_PREFIX }; FILE_TRANS_UUID_PREFIX };
static uint8_t attRxChConfigValue[64];
static uint16_t attRxChConfigValue_len = sizeof(attRxChConfigUuid);
/* File descriptor of the currently transferred file */ /* File descriptor of the currently transferred file */
static int file_fd = -1; static int file_fd = -1;
/* /* Attribute list for uriCfg group */
* Create the BLE service description. static const attsAttr_t fileTransCfgList[] = {
*/ /* Service declaration */
static void *fileTransAddGroupDyn(void)
{ {
void *pSHdl; .pUuid = attPrimSvcUuid,
uint8_t initCcc[] = { UINT16_TO_BYTES(0x0000) }; .pValue = (uint8_t *)fileTransSvc,
.pLen = (uint16_t *)&fileTransSvc_len,
/* Create the service */ .maxLen = sizeof(fileTransSvc),
pSHdl = AttsDynCreateGroup(FILE_TRANS_START_HDL, FILE_TRANS_END_HDL); .settings = 0,
.permissions = ATTS_PERMIT_READ,
if (pSHdl != NULL) { },
/* Primary service */
AttsDynAddAttrConst(
pSHdl,
attPrimSvcUuid,
fileTransSvc,
sizeof(fileTransSvc),
0,
ATTS_PERMIT_READ
);
/* File transfer Central TX characteristic */ /* File transfer Central TX characteristic */
AttsDynAddAttrConst( {
pSHdl, .pUuid = attChUuid,
attChUuid, .pValue = (uint8_t *)txChConfig,
txChConfig, .pLen = (uint16_t *)&txChConfig_len,
sizeof(txChConfig), .maxLen = sizeof(txChConfig),
0, .settings = 0,
ATTS_PERMIT_READ .permissions = ATTS_PERMIT_READ,
); },
/* File transfer Central TX, this contains information about the real data */ /* File transfer Central TX, this contains information about the real data */
AttsDynAddAttr( {
pSHdl, .pUuid = attTxChConfigUuid,
attTxChConfigUuid, .pValue = attTxChConfigValue,
NULL, .pLen = &attTxChConfigValue_len,
0, /* use last biyte for null termination */
128, .maxLen = sizeof(attTxChConfigValue) - 1,
ATTS_SET_WRITE_CBACK | ATTS_SET_VARIABLE_LEN, .settings = ATTS_SET_WRITE_CBACK | ATTS_SET_VARIABLE_LEN,
ATTS_PERMIT_WRITE .permissions = ATTS_PERMIT_WRITE,
); },
/* File transfer Central RX characteristic */ /* File transfer Central RX characteristic */
AttsDynAddAttrConst( {
pSHdl, .pUuid = attChUuid,
attChUuid, .pValue = (uint8_t *)rxChConfig,
rxChConfig, .pLen = (uint16_t *)&rxChConfig_len,
sizeof(rxChConfig), .maxLen = sizeof(rxChConfig),
0, .settings = 0,
ATTS_PERMIT_READ .permissions = ATTS_PERMIT_READ,
); },
/* File transfer Central RX, this contains information about the real data */ /* File transfer Central RX, this contains information about the real data */
AttsDynAddAttr( {
pSHdl, .pUuid = attRxChConfigUuid,
attRxChConfigUuid, .pValue = attRxChConfigValue,
NULL, .pLen = &attRxChConfigValue_len,
0, .maxLen = sizeof(attRxChConfigValue),
64, .settings = ATTS_SET_READ_CBACK,
ATTS_SET_READ_CBACK, .permissions = ATTS_PERMIT_READ,
ATTS_PERMIT_READ },
);
/* File transfer Central RX notification channel */ /* File transfer Central RX notification channel */
AttsDynAddAttr( {
pSHdl, .pUuid = attCliChCfgUuid,
attCliChCfgUuid, .pValue = attRxChConfigValue,
initCcc, .pLen = &attRxChConfigValue_len,
sizeof(uint16_t), .maxLen = sizeof(attRxChConfigValue),
sizeof(uint16_t), .settings = ATTS_SET_CCC,
ATTS_SET_CCC, .permissions = ATTS_PERMIT_READ | ATTS_PERMIT_WRITE,
ATTS_PERMIT_READ | ATTS_PERMIT_WRITE },
); };
}
return pSHdl;
}
/** /**
* Send a repose with an optional CRC. * Send a repose with an optional CRC.
...@@ -424,11 +413,18 @@ static uint8_t readCallback( ...@@ -424,11 +413,18 @@ static uint8_t readCallback(
return ATT_SUCCESS; return ATT_SUCCESS;
} }
static attsGroup_t fileTransCfgGroup = {
.pAttr = (attsAttr_t *)fileTransCfgList,
.readCback = readCallback,
.writeCback = writeCallback,
.startHandle = FILE_TRANS_START_HDL,
.endHandle = FILE_TRANS_END_HDL,
};
/* /*
* This registers and starts the BLE file transfer service. * This registers and starts the BLE file transfer service.
*/ */
void bleFileTransfer_init(void) void bleFileTransfer_init(void)
{ {
void *pSHdl = fileTransAddGroupDyn(); AttsAddGroup(&fileTransCfgGroup);
AttsDynRegister(pSHdl, readCallback, writeCallback);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment