@@ -71,6 +71,56 @@ ssize_t profile_write_process(bt_conn_t *conn,
7171 return len;
7272}
7373
74+ ssize_t profile_longwrite_process (struct bt_conn *conn,
75+ const struct bt_gatt_attr *attr,
76+ const void *buf, uint16_t len,
77+ uint16_t offset)
78+ {
79+ pr_info (LOG_MODULE_BLE, " %s1" , __FUNCTION__);
80+ BLEAttribute *bleattr = (BLEAttribute *)attr->user_data ;
81+ BLECharacteristic* blecharacteritic;
82+ BLEAttributeType type = bleattr->type ();
83+ BLECentralHelper central = BLEPeripheralRole::instance ()->central ();
84+ if (BLETypeCharacteristic != type)
85+ {
86+ return 0 ;
87+ }
88+
89+ blecharacteritic = (BLECharacteristic*)bleattr;
90+ blecharacteritic->setBuffer (*((BLEHelper *)¢ral), (const uint8_t *) buf, len, offset);
91+
92+ return len;
93+ }
94+
95+ int profile_longflush_process (struct bt_conn *conn,
96+ const struct bt_gatt_attr *attr,
97+ uint8_t flags)
98+ {
99+ BLEAttribute *bleattr = (BLEAttribute *)attr->user_data ;
100+ BLECharacteristic* blecharacteritic;
101+ BLEAttributeType type = bleattr->type ();
102+ BLECentralHelper central = BLEPeripheralRole::instance ()->central ();
103+ if (BLETypeCharacteristic != type)
104+ {
105+ return 0 ;
106+ }
107+
108+ blecharacteritic = (BLECharacteristic*)bleattr;
109+
110+ switch (flags) {
111+ case BT_GATT_FLUSH_DISCARD:
112+ /* Discard buffer reseting it back with data */
113+ blecharacteritic->discardBuffer ();
114+ return 0 ;
115+ case BT_GATT_FLUSH_SYNC:
116+ /* Sync buffer to data */
117+ blecharacteritic->syncupBuffer2Value (*((BLEHelper *)¢ral));
118+ return 0 ;
119+ }
120+
121+ return -EINVAL;
122+ }
123+
74124
75125// Only for central
76126uint8_t profile_notify_process (bt_conn_t *conn,
@@ -227,11 +277,21 @@ BLEProfile::addAttribute (BLEAttribute& attribute)
227277 memset (start, 0 , sizeof (bt_gatt_attr_t ));
228278 start->uuid = characteritic->uuid ();
229279 start->perm = characteritic->getPermission ();
230- start->read = profile_read_process;
231- start->write = profile_write_process;
232280 start->user_data = (void *)&attribute;
233281 characteritic->addCharacteristicValue (start);
282+ start->read = profile_read_process;
234283
284+ if (characteritic->longCharacteristic () == false )
285+ {
286+ // Normal characteristic MAX. 20
287+ start->write = profile_write_process;
288+ }
289+ else
290+ {
291+ // Long characteristic. MAX. 512
292+ start->write = profile_longwrite_process;
293+ start->flush = profile_longflush_process;
294+ }
235295 pr_info (LOG_MODULE_BLE, " desc-%p, uuid: 0x%x" , start, ((bt_uuid_16_t *) start->uuid )->val );
236296
237297 start++;
@@ -333,8 +393,8 @@ void BLEProfile::descriptorDiscoverRsp(const bt_gatt_attr_t *attr, BLEAttribute*
333393 // CCCD
334394 bt_gatt_attr_t *attr_chrc = attr_dec + 1 ;
335395 bt_gatt_attr_t *attr_cccd = attr_dec + 2 ;
336- bt_gatt_subscribe_params_t *sub_param_tmp = chrc->getSubscribeParams ();
337- bt_gatt_subscribe_params_t *sub_param = _sub_param + _sub_param_idx;
396+ bt_gatt_subscribe_params_t *sub_param_tmp = chrc->getSubscribeParams ();
397+ bt_gatt_subscribe_params_t *sub_param = _sub_param + _sub_param_idx;
338398 bt_conn_t *conn = bt_conn_lookup_addr_le (_peripheral->bt_le_address ());
339399 if (NULL == conn)
340400 {
0 commit comments