"</node>";
#ifdef HPS_GATT_DB
-static void _bt_hps_set_char_value(const char *obj_path, const char* value, int value_length);
+static void _bt_hps_set_char_value(const char *obj_path, const char* value, int value_length, int offset);
static void _hps_convert_address_to_hex(bluetooth_device_address_t *addr_hex, const char *addr_str)
{
BT_DBG("Status %d %04x", http_status, http_status);
/* Store the status value */
- _bt_hps_set_char_value(http_status_obj_path, status, 3);
+ _bt_hps_set_char_value(http_status_obj_path, status, 3, 0);
/* Send unicast notification */
ret = bluetooth_gatt_server_set_notification(http_status_obj_path, unicast_address);
return g_strcmp0(attrib1->char_path, attrib2->char_path);
}
-static void _bt_hps_set_char_value(const char *obj_path, const char* value, int value_length)
+static void _bt_hps_set_char_value(const char *obj_path, const char* value, int value_length, int offset)
{
GSList *tmp = NULL;
if (!value)
if (tmp->data) {
struct hps_char_info *char_info = tmp->data;
if (!g_strcmp0(char_info->char_path, obj_path)) {
- char_info->char_value = g_try_realloc(char_info->char_value, value_length);
+ gchar *str = NULL;
+ if (offset > 0) {
+ str = g_strdup(char_info->char_value);
+ char_info->char_value = g_try_realloc(char_info->char_value, offset + value_length);
+ } else {
+ char_info->char_value = g_try_realloc(char_info->char_value, value_length);
+ }
if (char_info->char_value) {
- memcpy(char_info->char_value, value, value_length);
- char_info->value_length = value_length;
+ if (str) {
+ memcpy(char_info->char_value, str, strlen(str));
+ g_free(str);
+ }
+ if (offset > 0) {
+ memcpy(&char_info->char_value[offset], value, value_length);
+ char_info->value_length = offset + value_length;
+ } else {
+ memcpy(char_info->char_value, value, value_length);
+ char_info->value_length = value_length;
+ }
hps_char_list = g_slist_insert_sorted(hps_char_list,
char_info, char_info_cmp);
}
}
#endif
-int _bt_hps_uri_write_cb(char *uri, int len)
+int _bt_hps_uri_write_cb(char *uri, int len, int offset)
{
if ((len < 1) || (len > MAX_URI_LENGTH)) {
BT_ERR("Wrong URI length %d", len);
g_free(g_uri);
g_uri = g_strndup(uri, len);
#ifdef HPS_GATT_DB
- _bt_hps_set_char_value(http_uri_obj_path, g_uri, len);
+ _bt_hps_set_char_value(http_uri_obj_path, g_uri, len, offset);
#endif
return BLUETOOTH_ERROR_NONE;
}
-int _bt_hps_http_header_write_cb(char *header, int len)
+int _bt_hps_http_header_write_cb(char *header, int len, int offset)
{
if ((len < 1) || (len > MAX_HEADER_LENGTH)) {
BT_ERR("Wrong Header length %d", len);
g_free(g_header);
g_header = g_strndup(header, len);
#ifdef HPS_GATT_DB
- _bt_hps_set_char_value(http_hdr_obj_path, g_header, len);
+ _bt_hps_set_char_value(http_hdr_obj_path, g_header, len, offset);
#endif
return BLUETOOTH_ERROR_NONE;
}
-int _bt_hps_entity_body_write_cb(char *entity, int len)
+int _bt_hps_entity_body_write_cb(char *entity, int len, int offset)
{
if ((len < 1) || (len > MAX_ENTITY_LENGTH)) {
BT_ERR("Wrong Entity length %d", len);
g_free(g_entity);
g_entity = g_strndup(entity, len);
#ifdef HPS_GATT_DB
- _bt_hps_set_char_value(http_entity_obj_path, g_entity, len);
+ _bt_hps_set_char_value(http_entity_obj_path, g_entity, len, offset);
#endif
return BLUETOOTH_ERROR_NONE;
data_status = DS_BODY_RECEIVED;
_bt_hps_set_notify_read_status(obj_path, offset, data_status, notify_read_info->https_status);
*value = g_strdup(&info->char_value[offset]);
- *len = info->value_length;
+ *len = info->value_length - offset;
}
} else if (notify_read_info && (notify_read_info->read_status == DS_BODY_RECEIVED ||
notify_read_info->read_status == DS_HEADER_RECEIVED)) {
// Write Data to Header Characteristic
#ifdef HPS_GATT_DB
- _bt_hps_set_char_value(http_hdr_obj_path, content, hdr_len);
+ _bt_hps_set_char_value(http_hdr_obj_path, content, hdr_len, 0);
#else
bluetooth_gatt_set_characteristic_value(http_hdr_obj_path, content, hdr_len);
#endif
}
// Write Data to Entity Body Characteristic
#ifdef HPS_GATT_DB
- _bt_hps_set_char_value(http_entity_obj_path, body->data, body->length);
+ _bt_hps_set_char_value(http_entity_obj_path, body->data, body->length, 0);
#else
bluetooth_gatt_set_characteristic_value(http_entity_obj_path, body->data, body->length);
#endif
hdr_len = soup_message_headers_get_content_length(msg->response_headers);
// Write Data to Header Characteristic
#ifdef HPS_GATT_DB
- _bt_hps_set_char_value(http_hdr_obj_path, content, hdr_len);
+ _bt_hps_set_char_value(http_hdr_obj_path, content, hdr_len, 0);
#else
bluetooth_gatt_set_characteristic_value(http_hdr_obj_path, content, hdr_len);
#endif
BT_INFO("Opcode %0x", opcode);
#ifdef HPS_GATT_DB
- _bt_hps_set_char_value(http_cp_obj_path, value, len);
+ _bt_hps_set_char_value(http_cp_obj_path, value, len, 0);
#endif
switch (opcode) {
#endif
https_status = soup_message_get_https_status(hps_soup_msg, &cert, &flags);
#ifdef HPS_GATT_DB
- _bt_hps_set_char_value(http_security_obj_path, (const char *)&https_status, 1);
+ _bt_hps_set_char_value(http_security_obj_path, (const char *)&https_status, 1, 0);
#else
bluetooth_gatt_set_characteristic_value(http_security_obj_path, (char *)&https_status, 1);
#endif
#endif
https_status = soup_message_get_https_status(hps_soup_msg, &cert, &flags);
#ifdef HPS_GATT_DB
- _bt_hps_set_char_value(http_security_obj_path, (const char *)&https_status, 1);
+ _bt_hps_set_char_value(http_security_obj_path, (const char *)&https_status, 1, 0);
#else
bluetooth_gatt_set_characteristic_value(http_security_obj_path, (char *)&https_status, 1);
#endif
#endif
https_status = soup_message_get_https_status(hps_soup_msg, &cert, &flags);
#ifdef HPS_GATT_DB
- _bt_hps_set_char_value(http_security_obj_path, (const char *)&https_status, 1);
+ _bt_hps_set_char_value(http_security_obj_path, (const char *)&https_status, 1, 0);
#else
bluetooth_gatt_set_characteristic_value(http_security_obj_path, (char *)&https_status, 1);
#endif
#endif
https_status = soup_message_get_https_status(hps_soup_msg, &cert, &flags);
#ifdef HPS_GATT_DB
- _bt_hps_set_char_value(http_security_obj_path, (const char *)&https_status, 1);
+ _bt_hps_set_char_value(http_security_obj_path, (const char *)&https_status, 1, 0);
#else
bluetooth_gatt_set_characteristic_value(http_security_obj_path, (char *)&https_status, 1);
#endif
https_status = soup_message_get_https_status(hps_soup_msg, &cert, &flags);
#ifdef HPS_GATT_DB
- _bt_hps_set_char_value(http_security_obj_path, (const char *)&https_status, 1);
+ _bt_hps_set_char_value(http_security_obj_path, (const char *)&https_status, 1, 0);
#else
bluetooth_gatt_set_characteristic_value(http_security_obj_path, (char *)&https_status, 1);
#endif
len = g_variant_get_size(val);
- BT_DBG("Len = %d", len);
+ BT_DBG("Len = %d, Offset = %d", len, offset);
value = (char *) g_variant_get_data(val);
if (len != 0) {
if (!g_strcmp0(char_path, http_uri_obj_path)) {
/* Retrive URI */
- result = _bt_hps_uri_write_cb(value, len);
+ result = _bt_hps_uri_write_cb(value, len, offset);;
} else if (!g_strcmp0(char_path, http_hdr_obj_path)) {
/* Retrive HEADER */
- result = _bt_hps_http_header_write_cb(value, len);
+ result = _bt_hps_http_header_write_cb(value, len, offset);
} else if (!g_strcmp0(char_path, http_entity_obj_path)) {
/* Retrive ENTITY BODY */
- result = _bt_hps_entity_body_write_cb(value, len);
+ result = _bt_hps_entity_body_write_cb(value, len, offset);
} else if (!g_strcmp0(char_path, http_cp_obj_path)) {
result = _bt_hps_control_point_write_cb(value, len, addr);
} else {
} else {
if (data_status == DS_BODY_RECEIVED ||
data_status == DS_HEADER_RECEIVED) {
- _bt_hps_set_char_value(char_path, NULL, 0);
+ _bt_hps_set_char_value(char_path, NULL, 0, 0);
}
}
if (value)
/* Store requets information */
char_info = g_new0(struct hps_char_info, 1);
char_info->char_path = g_strdup(http_uri_obj_path);
- _bt_hps_set_char_value(http_uri_obj_path, value, MAX_URI_LENGTH);
hps_char_list = g_slist_append(hps_char_list, char_info);
+ _bt_hps_set_char_value(http_uri_obj_path, value, MAX_URI_LENGTH, 0);
#endif
/* Characteristic HTTP Headers */
/* Store Characterisitc information */
char_info = g_new0(struct hps_char_info, 1);
char_info->char_path = g_strdup(http_hdr_obj_path);
- _bt_hps_set_char_value(http_hdr_obj_path, value, MAX_HEADER_LENGTH);
hps_char_list = g_slist_append(hps_char_list, char_info);
+ _bt_hps_set_char_value(http_hdr_obj_path, value, MAX_HEADER_LENGTH, 0);
#endif
/* Characteristic HTTP Entity Body */
/* Store Characterisitc information */
char_info = g_new0(struct hps_char_info, 1);
char_info->char_path = g_strdup(http_entity_obj_path);
- _bt_hps_set_char_value(http_entity_obj_path, value, MAX_ENTITY_LENGTH);
hps_char_list = g_slist_append(hps_char_list, char_info);
+ _bt_hps_set_char_value(http_entity_obj_path, value, MAX_ENTITY_LENGTH, 0);
#endif
/* Characteristic HTTP Control Point */
/* Store Characterisitc information */
char_info = g_new0(struct hps_char_info, 1);
char_info->char_path = g_strdup(http_cp_obj_path);
- _bt_hps_set_char_value(http_cp_obj_path, &cp, 1);
hps_char_list = g_slist_append(hps_char_list, char_info);
+ _bt_hps_set_char_value(http_cp_obj_path, &cp, 1, 0);
#endif
/* Characteristic HTTP Status Code */
/* Store Characterisitc information */
char_info = g_new0(struct hps_char_info, 1);
char_info->char_path = g_strdup(http_status_obj_path);
- _bt_hps_set_char_value(http_status_obj_path, status, 3);
hps_char_list = g_slist_append(hps_char_list, char_info);
+ _bt_hps_set_char_value(http_status_obj_path, status, 3, 0);
#endif
/* Characteristic HTTPS Security */
/* Store Characterisitc information */
char_info = g_new0(struct hps_char_info, 1);
char_info->char_path = g_strdup(http_security_obj_path);
- _bt_hps_set_char_value(http_security_obj_path, &cp, 1);
hps_char_list = g_slist_append(hps_char_list, char_info);
+ _bt_hps_set_char_value(http_security_obj_path, &cp, 1, 0);
#endif
ret = bluetooth_gatt_register_service(hps_obj_path);