#include <libsoup/soup.h>
-#ifdef HPS_FEATURE
+#ifdef TIZEN_FEATURE_BT_HPS
#undef LOG_TAG
#define LOG_TAG "BLUETOOTH_HPS"
char *http_security_obj_path = NULL;
static GMainLoop *main_loop;
-static int property_sub_id = -1;
-static int adapter_sub_id = -1;
+static guint property_sub_id;
+static guint adapter_sub_id;
static http_request_state req_state;
#ifdef HPS_GATT_DB
static GDBusConnection *conn;
static GDBusConnection *g_conn;
static guint g_owner_id = 0;
-GDBusNodeInfo *hps_node_info = NULL;
char *g_uri = NULL;
char *g_header = NULL;
"</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)
{
- int i = 0;
- unsigned int addr[BLUETOOTH_ADDRESS_LENGTH] = { 0, };
+ char *ptr1, *ptr2, *ptr3, *ptr4, *ptr5;
if (addr_str == NULL || addr_str[0] == '\0')
return;
- i = sscanf(addr_str, "%X:%X:%X:%X:%X:%X", &addr[0], &addr[1], &addr[2], &addr[3], &addr[4], &addr[5]);
- if (i != BLUETOOTH_ADDRESS_LENGTH) {
- BT_ERR("Invalid format string - [%s]", addr_str);
- }
+ addr_hex->addr[0] = strtol(addr_str, &ptr5, 16);
+ addr_hex->addr[1] = strtol(ptr5 + 1, &ptr4, 16);
+ addr_hex->addr[2] = strtol(ptr4 + 1, &ptr3, 16);
+ addr_hex->addr[3] = strtol(ptr3 + 1, &ptr2, 16);
+ addr_hex->addr[4] = strtol(ptr2 + 1, &ptr1, 16);
+ addr_hex->addr[5] = strtol(ptr1 + 1, NULL, 16);
+}
+
+static char *__hps_convert_uuid_to_uuid128(const char *uuid)
+{
+ int len;
+ char *uuid128;
+
+ len = strlen(uuid);
+
+ switch (len) {
+ case 4:
+ /* UUID 16bits */
+ uuid128 = g_strdup_printf("0000%s-0000-1000-8000-00805F9B34FB", uuid);
+ break;
- for (i = 0; i < BLUETOOTH_ADDRESS_LENGTH; i++) {
- addr_hex->addr[i] = (unsigned char)addr[i];
+ case 8:
+ /* UUID 32bits */
+ uuid128 = g_strdup_printf("%s-0000-1000-8000-00805F9B34FB", uuid);
+ break;
+
+ case 36:
+ /* UUID 128bits */
+ uuid128 = strdup(uuid);
+ break;
+
+ default:
+ return NULL;
}
+
+ return uuid128;
}
static void _bt_hps_send_status_notification(unsigned short http_status,
BT_DBG("");
status[0] = http_status & 0xFF;
- status[1] = (http_status >> 8 )& 0xFF;
+ status[1] = (http_status >> 8) & 0xFF;
status[2] = data_status;
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);
NULL,
};
-static void _bt_hps_on_bus_acquired (GDBusConnection *connection, const gchar *name, gpointer user_data)
+static void _bt_hps_on_bus_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data)
{
+ GDBusNodeInfo *node_info = NULL;
guint object_id;
GError *error = NULL;
g_conn = connection;
+ node_info = g_dbus_node_info_new_for_xml(hps_introspection_xml, &error);
+ if (!node_info) {
+ BT_ERR("Failed to install: %s", error->message);
+ g_clear_error(&error);
+ return;
+ }
+
object_id = g_dbus_connection_register_object(connection, BT_HPS_OBJECT_PATH,
- hps_node_info->interfaces[0],
+ node_info->interfaces[0],
&hps_method_table,
NULL, NULL, &error);
+ g_dbus_node_info_unref(node_info);
if (object_id == 0) {
BT_ERR("Failed to register method table: %s", error->message);
g_error_free(error);
- g_dbus_node_info_unref(hps_node_info);
}
return;
}
-static void _bt_hps_on_name_acquired (GDBusConnection *connection,
+static void _bt_hps_on_name_acquired(GDBusConnection *connection,
const gchar *name,
- gpointer user_data)
+ gpointer user_data)
{
BT_DBG("");
return;
}
-static void _bt_hps_on_name_lost (GDBusConnection *connection,
+static void _bt_hps_on_name_lost(GDBusConnection *connection,
const gchar *name,
- gpointer user_data)
+ gpointer user_data)
{
BT_DBG("");
g_object_unref(g_conn);
g_conn = NULL;
- g_dbus_node_info_unref(hps_node_info);
g_bus_unown_name(g_owner_id);
return;
int _bt_hps_register_interface(void)
{
- GError *error = NULL;
guint owner_id;
BT_DBG("");
- hps_node_info = g_dbus_node_info_new_for_xml (hps_introspection_xml, &error);
- if (!hps_node_info) {
- BT_ERR("Failed to install: %s", error->message);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
BT_HPS_SERVICE_NAME,
G_BUS_NAME_OWNER_FLAGS_NONE,
g_object_unref(g_conn);
g_conn = NULL;
- g_dbus_node_info_unref(hps_node_info);
g_bus_unown_name(g_owner_id);
return;
for (tmp = hps_char_list; tmp != NULL; tmp = tmp->next) {
if (tmp->data) {
struct hps_char_info *char_info = tmp->data;
- if(!g_strcmp0(char_info->char_path, path))
+ if (!g_strcmp0(char_info->char_path, path))
return char_info;
}
}
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)
for (tmp = hps_char_list; tmp != NULL; tmp = tmp->next) {
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);
- if (char_info->char_value) {
- 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);
+ if (!g_strcmp0(char_info->char_path, obj_path)) {
+ gchar *data = NULL;
+ if (char_info->char_value == NULL) {
+ char_info->char_value = g_malloc0(offset + value_length);
+ char_info->value_length = offset + value_length;
+ } else if (char_info->value_length >= offset + value_length) {
+ /* Just change from offset */
+ memcpy(&char_info->char_value[offset], value, value_length);
+ } else {
+ /* Values crossing pervious allocated limit realloc */
+ data = g_memdup(char_info->char_value, char_info->value_length);
+ char_info->char_value = g_try_realloc(char_info->char_value, offset + value_length);
+ memcpy(char_info->char_value, data, char_info->value_length);
+ memcpy(&char_info->char_value[offset], value, value_length);
+ char_info->value_length = offset + value_length;
+ g_free(data);
}
+ hps_char_list = g_slist_insert_sorted(hps_char_list,
+ char_info, char_info_cmp);
return;
}
}
for (tmp = hps_notify_read_list; tmp != NULL; tmp = tmp->next) {
if (tmp->data) {
notify_read_info = tmp->data;
- if(!g_strcmp0(notify_read_info->char_path, obj_path)) {
+ if (!g_strcmp0(notify_read_info->char_path, obj_path)) {
notify_read_info->read_status = read_status;
notify_read_info->offset_status = offset_status;
notify_read_info->https_status = https_status;
- hps_notify_read_list = g_slist_insert_sorted (hps_notify_read_list,
+ hps_notify_read_list = g_slist_insert_sorted(hps_notify_read_list,
notify_read_info, notify_info_cmp);
return;
}
for (tmp = hps_notify_read_list; tmp != NULL; tmp = tmp->next) {
if (tmp->data) {
struct hps_notify_read_info *notify_read_info = tmp->data;
- if(!g_strcmp0(notify_read_info->char_path, obj_path)) {
+ if (!g_strcmp0(notify_read_info->char_path, obj_path))
return notify_read_info;
- }
}
}
for (tmp = hps_notify_read_list; tmp != NULL; tmp = tmp->next) {
if (tmp->data) {
struct hps_notify_read_info *notify_read_info = tmp->data;
- if(!g_strcmp0(notify_read_info->char_path, obj_path)) {
+ if (!g_strcmp0(notify_read_info->char_path, obj_path)) {
if (notify_read_info->char_path)
g_free(notify_read_info->char_path);
hps_notify_read_list = g_slist_delete_link(hps_notify_read_list, tmp->data);
}
#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)) {
+ if ((len < 1) || (len > MAX_URI_LENGTH)) {
BT_ERR("Wrong URI length %d", len);
return BLUETOOTH_ERROR_INTERNAL;
}
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)) {
+ if ((len < 1) || (len > MAX_HEADER_LENGTH)) {
BT_ERR("Wrong Header length %d", len);
return BLUETOOTH_ERROR_INTERNAL;
}
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)) {
+ if ((len < 1) || (len > MAX_ENTITY_LENGTH)) {
BT_ERR("Wrong Entity length %d", len);
return BLUETOOTH_ERROR_INTERNAL;
}
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;
guint offset = 0;
gboolean is_header = FALSE;
- if(!obj_path) {
+ if (!obj_path) {
BT_ERR("Wrong Obj path");
- return FALSE;
+ return data_status;
}
if (!g_strcmp0(http_hdr_obj_path, obj_path))
_bt_hps_set_notify_read_status(obj_path, offset + MAX_ENTITY_LENGTH,
data_status, notify_read_info->https_status);
*value = g_strdup(&info->char_value[offset]);
- *len = info->value_length;
+ *len = MAX_ENTITY_LENGTH;
} else if ((info->value_length - offset) > 0 &&
(info->value_length - offset) <= MAX_ENTITY_LENGTH) {
if (is_header)
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)) {
_hps_convert_address_to_hex(&addr_hex, device_address);
#endif
- if(hps_soup_session != session) {
+ if (hps_soup_session != session) {
BT_ERR("Wrong Session");
return;
}
- if(msg == NULL) {
+ if (msg == NULL) {
BT_ERR("Wrong Message");
return;
}
http_status = msg->status_code;
// Process Header in Response Body
- if(msg->response_headers) {
+ if (msg->response_headers) {
const char *content = NULL;
const char *length = NULL;
guint hdr_len = 0;
- length = soup_message_headers_get_one (msg->request_headers,
+ length = soup_message_headers_get_one(msg->request_headers,
"Content-Length");
// Check "Content-MD5" is the right name to get header content
- content = soup_message_headers_get_one (msg->response_headers,
+ content = soup_message_headers_get_one(msg->response_headers,
"Content-MD5");
if (content == NULL || length == NULL) {
BT_ERR("Wrong Response Header");
// 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 Status Code Characteristic
#ifdef HPS_GATT_DB
- data_status = (hdr_len > MAX_ENTITY_LENGTH ) ? DS_HEADER_TRUNCATED : DS_HEADER_RECEIVED;
- if (data_status == DS_BODY_TRUNCATED && SOUP_STATUS_IS_SUCCESSFUL(http_status)) {
- _bt_hps_set_notify_read_status(http_hdr_obj_path, data_status, 0, http_status);
- }
+ data_status = (hdr_len > MAX_ENTITY_LENGTH) ? DS_HEADER_TRUNCATED : DS_HEADER_RECEIVED;
+
+ if (data_status == DS_BODY_TRUNCATED && SOUP_STATUS_IS_SUCCESSFUL(http_status))
+ _bt_hps_set_notify_read_status(http_hdr_obj_path, 0, data_status, http_status);
+
_bt_hps_send_status_notification(http_status, data_status, &addr_hex);
#else
status[0] = http_status & 0x0F;
- status[1] = (http_status >> 8 )& 0x0F;
- status[2] = (hdr_len > MAX_HEADER_LENGTH ) ? DS_HEADER_TRUNCATED : DS_HEADER_RECEIVED;
+ status[1] = (http_status >> 8) & 0x0F;
+ status[2] = (hdr_len > MAX_HEADER_LENGTH) ? DS_HEADER_TRUNCATED : DS_HEADER_RECEIVED;
bluetooth_gatt_set_characteristic_value(http_status_obj_path, status, 3);
#endif
- }else {
+ } else {
BT_ERR("HEAD Response is NULL");
_bt_hps_send_status_notification(http_status, data_status, &addr_hex);
}
_hps_convert_address_to_hex(&addr_hex, device_address);
#endif
- if(hps_soup_session != session) {
+ if (hps_soup_session != session) {
BT_ERR("Wrong Session");
return;
}
- if(msg == NULL) {
+ if (msg == NULL) {
BT_ERR("Wrong Message");
return;
}
// Write Data to Status Code Characteristic
#ifndef HPS_GATT_DB
status[0] = http_status & 0x0F;
- status[1] = (http_status >> 8 )& 0x0F;
+ status[1] = (http_status >> 8) & 0x0F;
status[2] = DS_HEADER_RECEIVED;
bluetooth_gatt_set_characteristic_value(http_status_obj_path, status, 3);
#else
_hps_convert_address_to_hex(&addr_hex, device_address);
#endif
- if(hps_soup_session != session) {
+ if (hps_soup_session != session) {
BT_ERR("Wrong Session");
return;
}
- if(msg == NULL) {
+ if (msg == NULL) {
BT_ERR("Wrong Message");
return;
}
http_status = msg->status_code;
// Process Entity Body in Response Message
- if(msg->response_body) {
+ if (msg->response_body) {
- body = soup_message_body_flatten (msg->response_body);
+ body = soup_message_body_flatten(msg->response_body);
if (body == NULL) {
BT_ERR("Wrong Response Body");
#ifdef HPS_GATT_DB
}
// 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
// Write Data to Status Code Characteristic
#ifdef HPS_GATT_DB
- data_status = (body->length > MAX_ENTITY_LENGTH ) ? DS_BODY_TRUNCATED : DS_BODY_RECEIVED;
- if (data_status == DS_BODY_TRUNCATED && SOUP_STATUS_IS_SUCCESSFUL(http_status)) {
- _bt_hps_set_notify_read_status(http_entity_obj_path, data_status, 0, http_status);
- }
+ data_status = (body->length > MAX_ENTITY_LENGTH) ? DS_BODY_TRUNCATED : DS_BODY_RECEIVED;
+
+ if (data_status == DS_BODY_TRUNCATED && SOUP_STATUS_IS_SUCCESSFUL(http_status))
+ _bt_hps_set_notify_read_status(http_entity_obj_path, 0, data_status, http_status);
+
_bt_hps_send_status_notification(http_status, data_status, &addr_hex);
#else
status[0] = http_status & 0x0F;
- status[1] = (http_status >> 8 )& 0x0F;
- status[2] = (body->length > MAX_HEADER_LENGTH ) ? DS_BODY_TRUNCATED : DS_BODY_TRUNCATED;
+ status[1] = (http_status >> 8) & 0x0F;
+ status[2] = (body->length > MAX_HEADER_LENGTH) ? DS_BODY_TRUNCATED : DS_BODY_TRUNCATED;
bluetooth_gatt_set_characteristic_value(http_status_obj_path, status, 3);
#endif
soup_buffer_free(body);
- }else {
+ } else {
BT_ERR("GET Response Body is NULL");
#ifdef HPS_GATT_DB
_bt_hps_send_status_notification(http_status, data_status, &addr_hex);
}
// Process Header in Response Body
- if(msg->response_headers) {
+ if (msg->response_headers) {
const char *content = NULL;
const char *length = NULL;
guint hdr_len = 0;
- length = soup_message_headers_get_one (msg->request_headers,
+ length = soup_message_headers_get_one(msg->request_headers,
"Content-Length");
// Check "Content-MD5" is the right name to get header content
- content = soup_message_headers_get_one (msg->response_headers,
+ content = soup_message_headers_get_one(msg->response_headers,
"Content-MD5");
if (content == NULL || length == NULL) {
BT_ERR("Wrong Response Header");
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
// Write Data to Status Code Characteristic
#ifdef HPS_GATT_DB
- data_status = (hdr_len > MAX_HEADER_LENGTH ) ? DS_HEADER_TRUNCATED : DS_HEADER_RECEIVED;
- if (data_status == DS_HEADER_TRUNCATED && SOUP_STATUS_IS_SUCCESSFUL(http_status)) {
- _bt_hps_set_notify_read_status(http_hdr_obj_path, data_status, 0, http_status);
- }
+ data_status = (hdr_len > MAX_HEADER_LENGTH) ? DS_HEADER_TRUNCATED : DS_HEADER_RECEIVED;
+
+ if (data_status == DS_HEADER_TRUNCATED && SOUP_STATUS_IS_SUCCESSFUL(http_status))
+ _bt_hps_set_notify_read_status(http_hdr_obj_path, 0, data_status, http_status);
+
_bt_hps_send_status_notification(http_status, data_status, &addr_hex);
#else
status[0] = http_status & 0x0F;
- status[1] = (http_status >> 8 )& 0x0F;
- status[2] = (hdr_len > MAX_HEADER_LENGTH ) ? DS_HEADER_TRUNCATED : DS_HEADER_RECEIVED;
+ status[1] = (http_status >> 8) & 0x0F;
+ status[2] = (hdr_len > MAX_HEADER_LENGTH) ? DS_HEADER_TRUNCATED : DS_HEADER_RECEIVED;
bluetooth_gatt_set_characteristic_value(http_status_obj_path, status, 3);
#endif
- }else {
+ } else {
BT_ERR("GET Response Header is NULL");
#ifdef HPS_GATT_DB
_bt_hps_send_status_notification(http_status, data_status, &addr_hex);
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) {
- case HTTP_GET_REQUEST:
- if(req_state == HTTP_REQ_STATE_EXECUTED) {
- req_state = HTTP_REQ_STATE_INPROGRESS;
- hps_soup_msg = soup_message_new("GET", g_uri);
+ switch (opcode) {
+ case HTTP_GET_REQUEST:
+ if (req_state == HTTP_REQ_STATE_EXECUTED) {
+ req_state = HTTP_REQ_STATE_INPROGRESS;
+ hps_soup_msg = soup_message_new("GET", g_uri);
#ifdef HPS_GATT_DB
- g_object_ref (hps_soup_msg);
- soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_get_response_cb, addr);
+ g_object_ref(hps_soup_msg);
+ soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_get_response_cb, addr);
#else
- soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_get_response_cb, NULL);
+ soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_get_response_cb, NULL);
#endif
- } else {
- BT_ERR("HTTP GET request in progress, message dropped");
+ } else {
+ BT_ERR("HTTP GET request in progress, message dropped");
+ result = BLUETOOTH_ERROR_INTERNAL;
+ }
+ break;
+
+ case HTTP_POST_REQUEST:
+ if (req_state == HTTP_REQ_STATE_EXECUTED) {
+ req_state = HTTP_REQ_STATE_INPROGRESS;
+ hps_soup_msg = soup_message_new("POST", g_uri);
+ if (hps_soup_msg == NULL || g_entity == NULL) {
+ BT_ERR("Soup Message NULL");
result = BLUETOOTH_ERROR_INTERNAL;
+ req_state = HTTP_REQ_STATE_EXECUTED;
+ break;
}
- break;
-
- case HTTP_POST_REQUEST:
- if(req_state == HTTP_REQ_STATE_EXECUTED) {
- req_state = HTTP_REQ_STATE_INPROGRESS;
- hps_soup_msg = soup_message_new("POST", g_uri);
- if(hps_soup_msg == NULL || g_entity == NULL) {
- BT_ERR("Soup Message NULL");
- result = BLUETOOTH_ERROR_INTERNAL;
- req_state = HTTP_REQ_STATE_EXECUTED;
- break;
- }
- soup_message_set_request (hps_soup_msg, "text/xml", SOUP_MEMORY_COPY,
- g_entity, strlen (g_entity));
+ soup_message_set_request(hps_soup_msg, "text/xml", SOUP_MEMORY_COPY,
+ g_entity, strlen(g_entity));
#ifdef HPS_GATT_DB
- g_object_ref (hps_soup_msg);
- soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_http_response_cb, addr);
+ g_object_ref(hps_soup_msg);
+ soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_http_response_cb, addr);
#else
- soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_http_response_cb, NULL);
+ soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_http_response_cb, NULL);
#endif
- } else {
- BT_ERR("HTTP POST request in progress, message dropped");
+ } else {
+ BT_ERR("HTTP POST request in progress, message dropped");
+ result = BLUETOOTH_ERROR_INTERNAL;
+ }
+ break;
+
+ case HTTP_HEAD_REQUEST:
+ if (req_state == HTTP_REQ_STATE_EXECUTED) {
+ req_state = HTTP_REQ_STATE_INPROGRESS;
+ hps_soup_msg = soup_message_new("HEAD", g_uri);
+ if (hps_soup_msg == NULL) {
+ BT_ERR("Soup Message NULL");
result = BLUETOOTH_ERROR_INTERNAL;
+ req_state = HTTP_REQ_STATE_EXECUTED;
+ break;
}
- break;
-
- case HTTP_HEAD_REQUEST:
- if(req_state == HTTP_REQ_STATE_EXECUTED) {
- req_state = HTTP_REQ_STATE_INPROGRESS;
- hps_soup_msg = soup_message_new("HEAD", g_uri);
- if(hps_soup_msg == NULL) {
- BT_ERR("Soup Message NULL");
- result = BLUETOOTH_ERROR_INTERNAL;
- req_state = HTTP_REQ_STATE_EXECUTED;
- break;
- }
#ifdef HPS_GATT_DB
- g_object_ref (hps_soup_msg);
- soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_head_response_cb, addr);
+ g_object_ref(hps_soup_msg);
+ soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_head_response_cb, addr);
#else
- soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_head_response_cb, NULL);
+ soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_head_response_cb, NULL);
#endif
- } else {
- BT_ERR("HTTP HEAD request in progress, message dropped");
+ } else {
+ BT_ERR("HTTP HEAD request in progress, message dropped");
+ result = BLUETOOTH_ERROR_INTERNAL;
+ }
+ break;
+
+ case HTTP_PUT_REQUEST:
+ if (req_state == HTTP_REQ_STATE_EXECUTED) {
+ SoupBuffer *buf;
+ req_state = HTTP_REQ_STATE_INPROGRESS;
+ hps_soup_msg = soup_message_new("PUT", g_uri);
+ if (hps_soup_msg == NULL || g_entity == NULL) {
+ BT_ERR("Soup Message NULL");
result = BLUETOOTH_ERROR_INTERNAL;
+ req_state = HTTP_REQ_STATE_EXECUTED;
+ break;
}
- break;
-
- case HTTP_PUT_REQUEST:
- if(req_state == HTTP_REQ_STATE_EXECUTED) {
- SoupBuffer *buf;
- req_state = HTTP_REQ_STATE_INPROGRESS;
- hps_soup_msg = soup_message_new("PUT", g_uri);
- if(hps_soup_msg == NULL || g_entity == NULL) {
- BT_ERR("Soup Message NULL");
- result = BLUETOOTH_ERROR_INTERNAL;
- req_state = HTTP_REQ_STATE_EXECUTED;
- break;
- }
- buf = soup_buffer_new (SOUP_MEMORY_TAKE, g_entity, strlen (g_entity));
- soup_message_body_append_buffer (hps_soup_msg->request_body, buf);
- soup_message_body_set_accumulate (hps_soup_msg->request_body, FALSE);
+ buf = soup_buffer_new(SOUP_MEMORY_TAKE, g_entity, strlen(g_entity));
+ soup_message_body_append_buffer(hps_soup_msg->request_body, buf);
+ soup_message_body_set_accumulate(hps_soup_msg->request_body, FALSE);
#ifdef HPS_GATT_DB
- g_object_ref (hps_soup_msg);
- soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_http_response_cb, addr);
+ g_object_ref(hps_soup_msg);
+ soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_http_response_cb, addr);
#else
- soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_http_response_cb, NULL);
+ soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_http_response_cb, NULL);
#endif
- } else {
- BT_ERR("HTTP PUT request in progress, message dropped");
+ } else {
+ BT_ERR("HTTP PUT request in progress, message dropped");
+ result = BLUETOOTH_ERROR_INTERNAL;
+ }
+ break;
+
+ case HTTP_DELETE_REQUEST:
+ if (req_state == HTTP_REQ_STATE_EXECUTED) {
+ req_state = HTTP_REQ_STATE_INPROGRESS;
+ hps_soup_msg = soup_message_new("DELETE", g_uri);
+ if (hps_soup_msg == NULL) {
+ BT_ERR("Soup Message NULL");
result = BLUETOOTH_ERROR_INTERNAL;
+ req_state = HTTP_REQ_STATE_EXECUTED;
+ break;
}
- break;
-
- case HTTP_DELETE_REQUEST:
- if(req_state == HTTP_REQ_STATE_EXECUTED) {
- req_state = HTTP_REQ_STATE_INPROGRESS;
- hps_soup_msg = soup_message_new("DELETE", g_uri);
- if(hps_soup_msg == NULL) {
- BT_ERR("Soup Message NULL");
- result = BLUETOOTH_ERROR_INTERNAL;
- req_state = HTTP_REQ_STATE_EXECUTED;
- break;
- }
#ifdef HPS_GATT_DB
- g_object_ref (hps_soup_msg);
- soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_http_response_cb, addr);
+ g_object_ref(hps_soup_msg);
+ soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_http_response_cb, addr);
#else
- soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_http_response_cb, NULL);
+ soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_http_response_cb, NULL);
#endif
- } else {
- BT_ERR("HTTP DELETE request in progress, message dropped");
+ } else {
+ BT_ERR("HTTP DELETE request in progress, message dropped");
+ result = BLUETOOTH_ERROR_INTERNAL;
+ }
+ break;
+
+ case HTTPS_GET_REQUEST:
+ if (req_state == HTTP_REQ_STATE_EXECUTED) {
+ req_state = HTTP_REQ_STATE_INPROGRESS;
+ hps_soup_msg = soup_message_new("GET", g_uri);
+ if (hps_soup_msg == NULL) {
+ BT_ERR("Soup Message NULL");
result = BLUETOOTH_ERROR_INTERNAL;
+ req_state = HTTP_REQ_STATE_EXECUTED;
+ break;
}
- break;
-
- case HTTPS_GET_REQUEST:
- if(req_state == HTTP_REQ_STATE_EXECUTED) {
- req_state = HTTP_REQ_STATE_INPROGRESS;
- hps_soup_msg = soup_message_new("GET", g_uri);
- if(hps_soup_msg == NULL) {
- BT_ERR("Soup Message NULL");
- result = BLUETOOTH_ERROR_INTERNAL;
- req_state = HTTP_REQ_STATE_EXECUTED;
- break;
- }
#ifdef HPS_GATT_DB
- g_object_ref (hps_soup_msg);
- soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_get_response_cb, addr);
+ g_object_ref(hps_soup_msg);
+ soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_get_response_cb, addr);
#else
- soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_get_response_cb, NULL);
+ soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_get_response_cb, NULL);
#endif
- https_status = soup_message_get_https_status (hps_soup_msg, &cert, &flags);
+ 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);
+ bluetooth_gatt_set_characteristic_value(http_security_obj_path, (char *)&https_status, 1);
#endif
- } else {
- BT_ERR("HTTPS GET request in progress, message dropped");
+ } else {
+ BT_ERR("HTTPS GET request in progress, message dropped");
+ result = BLUETOOTH_ERROR_INTERNAL;
+ }
+ break;
+
+ case HTTPS_HEAD_REQUEST:
+ if (req_state == HTTP_REQ_STATE_EXECUTED) {
+ req_state = HTTP_REQ_STATE_INPROGRESS;
+ hps_soup_msg = soup_message_new("HEAD", g_uri);
+ if (hps_soup_msg == NULL) {
+ BT_ERR("Soup Message NULL");
result = BLUETOOTH_ERROR_INTERNAL;
+ req_state = HTTP_REQ_STATE_EXECUTED;
+ break;
}
- break;
-
- case HTTPS_HEAD_REQUEST:
- if(req_state == HTTP_REQ_STATE_EXECUTED) {
- req_state = HTTP_REQ_STATE_INPROGRESS;
- hps_soup_msg = soup_message_new("HEAD", g_uri);
- if(hps_soup_msg == NULL) {
- BT_ERR("Soup Message NULL");
- result = BLUETOOTH_ERROR_INTERNAL;
- req_state = HTTP_REQ_STATE_EXECUTED;
- break;
- }
#ifdef HPS_GATT_DB
- g_object_ref (hps_soup_msg);
- soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_head_response_cb, addr);
+ g_object_ref(hps_soup_msg);
+ soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_head_response_cb, addr);
#else
- soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_head_response_cb, NULL);
+ soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_head_response_cb, NULL);
#endif
- https_status = soup_message_get_https_status (hps_soup_msg, &cert, &flags);
+ 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);
+ bluetooth_gatt_set_characteristic_value(http_security_obj_path, (char *)&https_status, 1);
#endif
- } else {
- BT_ERR("HTTPS HEAD request in progress, message dropped");
+ } else {
+ BT_ERR("HTTPS HEAD request in progress, message dropped");
+ result = BLUETOOTH_ERROR_INTERNAL;
+ }
+ break;
+
+ case HTTPS_POST_REQUEST:
+ if (req_state == HTTP_REQ_STATE_EXECUTED) {
+ req_state = HTTP_REQ_STATE_INPROGRESS;
+ hps_soup_msg = soup_message_new("POST", g_uri);
+ if (hps_soup_msg == NULL) {
+ BT_ERR("Soup Message NULL");
result = BLUETOOTH_ERROR_INTERNAL;
+ req_state = HTTP_REQ_STATE_EXECUTED;
+ break;
}
- break;
-
- case HTTPS_POST_REQUEST:
- if(req_state == HTTP_REQ_STATE_EXECUTED) {
- req_state = HTTP_REQ_STATE_INPROGRESS;
- hps_soup_msg = soup_message_new("POST", g_uri);
- if(hps_soup_msg == NULL) {
- BT_ERR("Soup Message NULL");
- result = BLUETOOTH_ERROR_INTERNAL;
- req_state = HTTP_REQ_STATE_EXECUTED;
- break;
- }
- soup_message_set_request (hps_soup_msg, "text/xml", SOUP_MEMORY_STATIC,
- g_entity, strlen (g_entity));
+ soup_message_set_request(hps_soup_msg, "text/xml", SOUP_MEMORY_STATIC,
+ g_entity, strlen(g_entity));
#ifdef HPS_GATT_DB
- g_object_ref (hps_soup_msg);
- soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_http_response_cb, addr);
+ g_object_ref(hps_soup_msg);
+ soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_http_response_cb, addr);
#else
- soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_http_response_cb, NULL);
+ soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_http_response_cb, NULL);
#endif
- https_status = soup_message_get_https_status (hps_soup_msg, &cert, &flags);
+ 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);
+ bluetooth_gatt_set_characteristic_value(http_security_obj_path, (char *)&https_status, 1);
#endif
- } else {
- BT_ERR("HTTPS POST request in progress, message dropped");
+ } else {
+ BT_ERR("HTTPS POST request in progress, message dropped");
+ result = BLUETOOTH_ERROR_INTERNAL;
+ }
+ break;
+
+ case HTTPS_PUT_REQUEST:
+ if (req_state == HTTP_REQ_STATE_EXECUTED) {
+ SoupBuffer *buf;
+ req_state = HTTP_REQ_STATE_INPROGRESS;
+ hps_soup_msg = soup_message_new("PUT", g_uri);
+ if (hps_soup_msg == NULL) {
+ BT_ERR("Soup Message NULL");
result = BLUETOOTH_ERROR_INTERNAL;
+ req_state = HTTP_REQ_STATE_EXECUTED;
+ break;
}
- break;
-
- case HTTPS_PUT_REQUEST:
- if(req_state == HTTP_REQ_STATE_EXECUTED) {
- SoupBuffer *buf;
- req_state = HTTP_REQ_STATE_INPROGRESS;
- hps_soup_msg = soup_message_new("PUT", g_uri);
- if(hps_soup_msg == NULL) {
- BT_ERR("Soup Message NULL");
- result = BLUETOOTH_ERROR_INTERNAL;
- req_state = HTTP_REQ_STATE_EXECUTED;
- break;
- }
- buf = soup_buffer_new (SOUP_MEMORY_TAKE, g_entity, strlen (g_entity));
- soup_message_body_append_buffer (hps_soup_msg->request_body, buf);
- soup_message_body_set_accumulate (hps_soup_msg->request_body, FALSE);
+ buf = soup_buffer_new(SOUP_MEMORY_TAKE, g_entity, strlen(g_entity));
+ soup_message_body_append_buffer(hps_soup_msg->request_body, buf);
+ soup_message_body_set_accumulate(hps_soup_msg->request_body, FALSE);
#ifdef HPS_GATT_DB
- g_object_ref (hps_soup_msg);
- soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_http_response_cb, addr);
+ g_object_ref(hps_soup_msg);
+ soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_http_response_cb, addr);
#else
- soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_http_response_cb, NULL);
+ soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_http_response_cb, NULL);
#endif
- https_status = soup_message_get_https_status (hps_soup_msg, &cert, &flags);
+ 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);
+ bluetooth_gatt_set_characteristic_value(http_security_obj_path, (char *)&https_status, 1);
#endif
- } else {
- BT_ERR("HTTPS PUT request in progress, message dropped");
+ } else {
+ BT_ERR("HTTPS PUT request in progress, message dropped");
+ result = BLUETOOTH_ERROR_INTERNAL;
+ }
+ break;
+
+ case HTTPS_DELETE_REQUEST:
+ if (req_state == HTTP_REQ_STATE_EXECUTED) {
+ req_state = HTTP_REQ_STATE_INPROGRESS;
+ hps_soup_msg = soup_message_new("DELETE", g_uri);
+ if (hps_soup_msg == NULL) {
+ BT_ERR("Soup Message NULL");
result = BLUETOOTH_ERROR_INTERNAL;
+ req_state = HTTP_REQ_STATE_EXECUTED;
+ break;
}
- break;
-
- case HTTPS_DELETE_REQUEST:
- if(req_state == HTTP_REQ_STATE_EXECUTED) {
- req_state = HTTP_REQ_STATE_INPROGRESS;
- hps_soup_msg = soup_message_new("DELETE", g_uri);
- if(hps_soup_msg == NULL) {
- BT_ERR("Soup Message NULL");
- result = BLUETOOTH_ERROR_INTERNAL;
- req_state = HTTP_REQ_STATE_EXECUTED;
- break;
- }
#ifdef HPS_GATT_DB
- g_object_ref (hps_soup_msg);
- soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_http_response_cb, addr);
+ g_object_ref(hps_soup_msg);
+ soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_http_response_cb, addr);
#else
- soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_http_response_cb, NULL);
+ soup_session_queue_message(hps_soup_session, hps_soup_msg, _bt_hps_http_response_cb, NULL);
#endif
- https_status = soup_message_get_https_status (hps_soup_msg, &cert, &flags);
+ 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);
+ bluetooth_gatt_set_characteristic_value(http_security_obj_path, (char *)&https_status, 1);
#endif
- } else {
- BT_ERR("HTTPS DELETE request in progress, message dropped");
+ } else {
+ BT_ERR("HTTPS DELETE request in progress, message dropped");
+ result = BLUETOOTH_ERROR_INTERNAL;
+ }
+ break;
+
+ case HTTP_REQUEST_CANCEL:
+ /* Cancel the outstanding request */
+ if (req_state == HTTP_REQ_STATE_INPROGRESS) {
+ req_state = HTTP_REQ_STATE_IDLE;
+ if (hps_soup_msg == NULL) {
+ BT_ERR("Soup Message NULL");
result = BLUETOOTH_ERROR_INTERNAL;
+ req_state = HTTP_REQ_STATE_EXECUTED;
+ break;
}
- break;
-
- case HTTP_REQUEST_CANCEL:
- /* Cancel the outstanding request */
- if(req_state == HTTP_REQ_STATE_INPROGRESS) {
- req_state = HTTP_REQ_STATE_IDLE;
- if(hps_soup_msg == NULL) {
- BT_ERR("Soup Message NULL");
- result = BLUETOOTH_ERROR_INTERNAL;
- req_state = HTTP_REQ_STATE_EXECUTED;
- break;
- }
- soup_session_cancel_message (hps_soup_session, hps_soup_msg, SOUP_STATUS_CANCELLED);
- hps_soup_msg = NULL;
- }
- break;
+ soup_session_cancel_message(hps_soup_session, hps_soup_msg, SOUP_STATUS_CANCELLED);
+ hps_soup_msg = NULL;
+ }
+ break;
- default:
- BT_ERR("Unknown opcode %0x", opcode);
- result = BLUETOOTH_ERROR_INTERNAL;
- break;
+ default:
+ BT_ERR("Unknown opcode %0x", opcode);
+ result = BLUETOOTH_ERROR_INTERNAL;
+ break;
}
return result;
}
-void _bt_hps_security_read_cb (char *value, int len)
+void _bt_hps_security_read_cb(char *value, int len)
{
BT_INFO("HPS Client Read the value");
return;
const char * svc_handle = NULL;
GVariant *var = NULL;
GVariant *val = NULL;
- g_variant_iter_init (&value_iter, msg);
+ g_variant_iter_init(&value_iter, msg);
while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &var))) {
- if(property == NULL) {
- BT_ERR("Property NULL");
- return;
- }
-
if (!g_strcmp0(property, "WriteValue")) {
int len = 0;
BT_INFO("WriteValue");
- BT_INFO("Type '%s'\n", g_variant_get_type_string (var));
+ BT_INFO("Type '%s'\n", g_variant_get_type_string(var));
if (var) {
gchar *addr = NULL;
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)) {
+ if (!g_strcmp0(char_path, http_uri_obj_path)) {
/* Retrive URI */
- result = _bt_hps_uri_write_cb(value, len);
- } else if(!g_strcmp0(char_path, http_hdr_obj_path)) {
+ 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);
- } else if(!g_strcmp0(char_path, http_entity_obj_path)) {
+ 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);
- } else if(!g_strcmp0(char_path, http_cp_obj_path)) {
+ 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 {
BT_ERR("Wrong Object Path %s", char_path);
int len = 0;
int data_status = -1;
BT_INFO("ReadValue");
- BT_INFO("Type '%s'\n", g_variant_get_type_string (var));
+ BT_INFO("Type '%s'\n", g_variant_get_type_string(var));
g_variant_get(var, "(&s&s&syq)", &char_path, &svc_handle,
&addr, &req_id, &offset);
} 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)
GVariant *val = NULL;
int result = BLUETOOTH_ERROR_NONE;
GVariant *param = NULL;
- g_variant_iter_init (&value_iter, msg);
+ g_variant_iter_init(&value_iter, msg);
char_handle = g_strdup(path);
while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
- if(property == NULL) {
+ if (property == NULL) {
BT_ERR("Property NULL");
- return;
+ break;
}
if (strcasecmp(property, "ChangedValue") == 0) {
int len = 0;
GByteArray *gp_byte_array = NULL;
- BT_INFO("Type '%s'\n", g_variant_get_type_string (val));
+ BT_INFO("Type '%s'\n", g_variant_get_type_string(val));
if (val) {
gp_byte_array = g_byte_array_new();
len = g_variant_get_size(val);
BT_DBG("Len = %d", len);
- g_byte_array_append (gp_byte_array,
- (const guint8 *) g_variant_get_data(val), len);
+ g_byte_array_append(gp_byte_array,
+ (const guint8 *)g_variant_get_data(val), len);
if (gp_byte_array->len != 0) {
- GVariant *byte_array = NULL;
- byte_array = g_variant_new_from_data(
- G_VARIANT_TYPE_BYTESTRING,
- gp_byte_array->data,
- gp_byte_array->len,
- TRUE, NULL, NULL);
- param = g_variant_new("(is@ay)", result, char_handle,
- byte_array);
-
- if(strcmp(path, http_uri_obj_path)) {
+ if (strcmp(path, http_uri_obj_path)) {
//Retrive URI
_bt_hps_uri_write_cb(NULL, len);
- } else if(strcmp(path, http_hdr_obj_path)) {
+ } else if (strcmp(path, http_hdr_obj_path)) {
//Retrive HEADER
_bt_hps_http_header_write_cb(NULL, len);
- } else if(strcmp(path, http_entity_obj_path)) {
+ } else if (strcmp(path, http_entity_obj_path)) {
//Retrive ENTITY BODY
_bt_hps_entity_body_write_cb(NULL, len);
- } else if(strcmp(path, http_cp_obj_path)) {
+ } else if (strcmp(path, http_cp_obj_path)) {
_bt_hps_control_point_write_cb(NULL, len);
- } else if(strcmp(path, http_security_obj_path)) {
+ } else if (strcmp(path, http_security_obj_path)) {
_bt_hps_security_read_cb(NULL, len);
} else {
BT_ERR("Wrong Object Path %s", path);
BT_ERR("Array Len 0");
}
g_byte_array_free(gp_byte_array, TRUE);
- }else {
+ } else {
BT_ERR("val==NULL");
}
}
void _bt_hps_deinit_event_receiver(void)
{
BT_DBG("");
- g_dbus_connection_signal_unsubscribe(conn, property_sub_id);
- g_dbus_connection_signal_unsubscribe(conn, adapter_sub_id);
+
+ if (conn == NULL)
+ return;
+
+ if (property_sub_id > 0) {
+ g_dbus_connection_signal_unsubscribe(conn, property_sub_id);
+ property_sub_id = 0;
+ }
+
+ if (adapter_sub_id) {
+ g_dbus_connection_signal_unsubscribe(conn, adapter_sub_id);
+ adapter_sub_id = 0;
+ }
+
conn = NULL;
+
return;
}
int ret;
BT_DBG("");
- // Temporary UUID is used. SIG have not yet defined the UUID yet
- guint8 data[4] = {0x03, 0x02, 0x00, 0x19};
+ guint8 data[4] = {0x03, 0x02, 0x23, 0x18};
bluetooth_advertising_data_t adv;
BT_DBG("%x %x %x %x", data[0], data[1], data[2], data[3]);
memcpy(adv.data, data, sizeof(data));
ret = bluetooth_set_advertising_data(0, &adv, sizeof(data));
- if(ret != BLUETOOTH_ERROR_NONE) {
+ if (ret != BLUETOOTH_ERROR_NONE) {
BT_ERR("Failed to set ADV data %d", ret);
return ret;
}
ret = bluetooth_set_advertising(0, TRUE);
- if(ret != BLUETOOTH_ERROR_NONE) {
+ if (ret != BLUETOOTH_ERROR_NONE) {
BT_ERR("Failed to set ADV %d", ret);
return ret;
}
BT_DBG("");
ret = bluetooth_gatt_init();
- if(ret != BLUETOOTH_ERROR_NONE) {
+ if (ret != BLUETOOTH_ERROR_NONE) {
BT_ERR("Failed to Init GATT %d", ret);
goto fail;
}
- service_uuid = g_strdup(HPS_UUID);
+ service_uuid = __hps_convert_uuid_to_uuid128(HPS_UUID);
ret = bluetooth_gatt_add_service(service_uuid, &hps_obj_path);
- if(ret != BLUETOOTH_ERROR_NONE) {
+ if (ret != BLUETOOTH_ERROR_NONE) {
BT_ERR("Failed to add service %d", ret);
goto fail;
}
/* Characteristic URI */
- props = BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_READ |
- BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_WRITE;
- char_uuid = g_strdup(HTTP_URI_UUID);
+ props = BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_WRITE;
+ char_uuid = __hps_convert_uuid_to_uuid128(HTTP_URI_UUID);
ret = bluetooth_gatt_add_new_characteristic(hps_obj_path, char_uuid, 0, props, &http_uri_obj_path);
- if(ret != BLUETOOTH_ERROR_NONE) {
+ if (ret != BLUETOOTH_ERROR_NONE) {
BT_ERR("Failed to add new char %d", ret);
goto fail;
}
#ifdef HPS_GATT_DB
ret = bluetooth_gatt_set_characteristic_value(http_uri_obj_path, value, MAX_URI_LENGTH);
- if(ret != BLUETOOTH_ERROR_NONE) {
+ if (ret != BLUETOOTH_ERROR_NONE) {
BT_ERR("Failed to add new char %d", ret);
goto fail;
}
/* 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 */
props = BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_READ |
BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_WRITE;
- char_uuid = g_strdup(HTTP_HDR_UUID);
+ char_uuid = __hps_convert_uuid_to_uuid128(HTTP_HDR_UUID);
ret = bluetooth_gatt_add_new_characteristic(hps_obj_path, char_uuid, 0, props, &http_hdr_obj_path);
- if(ret != BLUETOOTH_ERROR_NONE) {
+ if (ret != BLUETOOTH_ERROR_NONE) {
BT_ERR("Failed to add new char %d", ret);
goto fail;
}
#ifdef HPS_GATT_DB
ret = bluetooth_gatt_set_characteristic_value(http_hdr_obj_path, value, MAX_HEADER_LENGTH);
- if(ret != BLUETOOTH_ERROR_NONE) {
+ if (ret != BLUETOOTH_ERROR_NONE) {
BT_ERR("Failed to add new char %d", ret);
goto fail;
}
/* 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 */
props = BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_READ |
BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_WRITE;
- char_uuid = g_strdup(HTTP_ENTITY_UUID);
+ char_uuid = __hps_convert_uuid_to_uuid128(HTTP_ENTITY_UUID);
ret = bluetooth_gatt_add_new_characteristic(hps_obj_path, char_uuid, 0, props, &http_entity_obj_path);
- if(ret != BLUETOOTH_ERROR_NONE) {
+ if (ret != BLUETOOTH_ERROR_NONE) {
BT_ERR("Failed to add new char %d", ret);
goto fail;
}
#ifdef HPS_GATT_DB
ret = bluetooth_gatt_set_characteristic_value(http_entity_obj_path, value, MAX_ENTITY_LENGTH);
- if(ret != BLUETOOTH_ERROR_NONE) {
+ if (ret != BLUETOOTH_ERROR_NONE) {
BT_ERR("Failed to add new char %d", ret);
goto fail;
}
/* 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 */
- props = BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_READ |
- BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_WRITE;
- char_uuid = g_strdup(HTTP_CP_UUID);
+ props = BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_WRITE;
+ char_uuid = __hps_convert_uuid_to_uuid128(HTTP_CP_UUID);
ret = bluetooth_gatt_add_new_characteristic(hps_obj_path, char_uuid, 0, props, &http_cp_obj_path);
- if(ret != BLUETOOTH_ERROR_NONE) {
+ if (ret != BLUETOOTH_ERROR_NONE) {
BT_ERR("Failed to add new char %d", ret);
goto fail;
}
#ifdef HPS_GATT_DB
ret = bluetooth_gatt_set_characteristic_value(http_cp_obj_path, &cp, 1);
- if(ret != BLUETOOTH_ERROR_NONE) {
+ if (ret != BLUETOOTH_ERROR_NONE) {
BT_ERR("Failed to add new char %d", ret);
goto fail;
}
/* 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 */
- props = BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_READ |
- BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_WRITE |
- BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_NOTIFY;
- char_uuid = g_strdup(HTTP_STATUS_UUID);
+ props = BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_NOTIFY;
+ char_uuid = __hps_convert_uuid_to_uuid128(HTTP_STATUS_UUID);
ret = bluetooth_gatt_add_new_characteristic(hps_obj_path, char_uuid, 0, props, &http_status_obj_path);
- if(ret != BLUETOOTH_ERROR_NONE) {
+ if (ret != BLUETOOTH_ERROR_NONE) {
BT_ERR("Failed to add new char %d", ret);
goto fail;
}
#ifdef HPS_GATT_DB
ret = bluetooth_gatt_set_characteristic_value(http_status_obj_path, status, 3);
- if(ret != BLUETOOTH_ERROR_NONE) {
+ if (ret != BLUETOOTH_ERROR_NONE) {
BT_ERR("Failed to add new char %d", ret);
goto fail;
}
#endif
- desc_uuid = g_strdup(HTTP_STATUS_CCC_DESC_UUID);
+ desc_uuid = __hps_convert_uuid_to_uuid128(HTTP_STATUS_CCC_DESC_UUID);
ret = bluetooth_gatt_add_descriptor(http_status_obj_path, desc_uuid,
(BLUETOOTH_GATT_PERMISSION_READ | BLUETOOTH_GATT_PERMISSION_WRITE),
&http_status_desc_obj_path);
- if(ret != BLUETOOTH_ERROR_NONE) {
+ if (ret != BLUETOOTH_ERROR_NONE) {
BT_ERR("Failed to add new char descriptor %d", ret);
goto fail;
}
/* 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 */
- props = BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_READ |
- BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_WRITE;
- char_uuid = g_strdup(HTTP_SECURITY_UUID);
+ props = BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_READ;
+ char_uuid = __hps_convert_uuid_to_uuid128(HTTP_SECURITY_UUID);
ret = bluetooth_gatt_add_new_characteristic(hps_obj_path, char_uuid, 0, props, &http_security_obj_path);
- if(ret != BLUETOOTH_ERROR_NONE) {
+ if (ret != BLUETOOTH_ERROR_NONE) {
BT_ERR("Failed to add new char %d", ret);
goto fail;
}
#ifdef HPS_GATT_DB
ret = bluetooth_gatt_set_characteristic_value(http_security_obj_path, &cp, 1);
- if(ret != BLUETOOTH_ERROR_NONE) {
+ if (ret != BLUETOOTH_ERROR_NONE) {
BT_ERR("Failed to add new char %d", ret);
goto fail;
}
/* 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);
- if(ret != BLUETOOTH_ERROR_NONE) {
+ if (ret != BLUETOOTH_ERROR_NONE) {
BT_ERR("Failed to register service %d", ret);
goto fail;
}
ret = bluetooth_gatt_register_application();
- if(ret != BLUETOOTH_ERROR_NONE) {
+ if (ret != BLUETOOTH_ERROR_NONE) {
BT_ERR("Failed to register application %d", ret);
goto fail;
}
{
BT_DBG("");
- switch(sig) {
- case SIGTERM:
- BT_DBG("caught signal - sigterm\n");
- break;
- case SIGINT:
- BT_DBG("caught signal - sigint\n");
- break;
- case SIGKILL:
- BT_DBG("caught signal - sigkill\n");
- break;
- default:
- BT_DBG("caught signal %d and ignored\n",sig);
- break;
+ switch (sig) {
+ case SIGTERM:
+ BT_DBG("caught signal - sigterm\n");
+ break;
+ case SIGINT:
+ BT_DBG("caught signal - sigint\n");
+ break;
+ case SIGKILL:
+ BT_DBG("caught signal - sigkill\n");
+ break;
+ default:
+ BT_DBG("caught signal %d and ignored\n", sig);
+ break;
}
}
int ret;
BT_DBG("");
- if(g_uri != NULL) {
+ if (g_uri != NULL) {
g_free(g_uri);
g_uri = NULL;
}
- if(g_header != NULL) {
+ if (g_header != NULL) {
g_free(g_header);
g_header = NULL;
}
- if(g_entity != NULL) {
+ if (g_entity != NULL) {
g_free(g_entity);
g_entity = NULL;
}
soup_session_abort(hps_soup_session);
- g_assert_cmpint(G_OBJECT (hps_soup_session)->ref_count, ==, 1);
+ g_assert_cmpint(G_OBJECT(hps_soup_session)->ref_count, ==, 1);
g_object_unref(hps_soup_session);
#ifdef HPS_GATT_DB
#endif
ret = bluetooth_gatt_deinit();
- if(ret != BLUETOOTH_ERROR_NONE) {
+ if (ret != BLUETOOTH_ERROR_NONE)
BT_ERR("Failed to Deinit GATT %d", ret);
- }
ret = bluetooth_unregister_callback();
- if(ret != BLUETOOTH_ERROR_NONE) {
+ if (ret != BLUETOOTH_ERROR_NONE)
BT_ERR("Failed to Unregister callback %d", ret);
- }
_bt_hps_deinit_event_receiver();
_bt_hps_unregister_interface();
- if (main_loop != NULL) {
+ if (main_loop != NULL)
g_main_loop_quit(main_loop);
- }
}
void bt_hps_event_callback(int event, bluetooth_event_param_t* param,
sigaction(SIGKILL, &sa, NULL);
#ifndef HPS_GATT_DB
- if(bluetooth_register_callback(bt_hps_event_callback, NULL) != BLUETOOTH_ERROR_NONE) {
+ if (bluetooth_register_callback(bt_hps_event_callback, NULL) != BLUETOOTH_ERROR_NONE) {
BT_ERR("bluetooth_register_callback returned failiure");
return -3;
}
return -5;
}
- hps_soup_session = soup_session_async_new();
+ hps_soup_session = soup_session_new();
if (hps_soup_session == NULL) {
BT_ERR("Failed to soup_session_async_new");
return -6;
BT_DBG("g_main_loop_quit called!");
- if (main_loop != NULL) {
+ if (main_loop != NULL)
g_main_loop_unref(main_loop);
- }
return 0;
}