HID: Add API to send RC key event 27/77827/1
authorAtul Rai <a.rai@samsung.com>
Fri, 1 Jul 2016 08:12:16 +0000 (17:12 +0900)
committerAtul Rai <a.rai@samsung.com>
Fri, 1 Jul 2016 08:12:16 +0000 (17:12 +0900)
This patch adds new bluetooth API to send RC key event
data to remote device over socket.

Change-Id: I6985b2193245b6caa680ac62eb3060aeb3281437
Signed-off-by: Atul Rai <a.rai@samsung.com>
bt-api/bt-hid-device.c
include/bluetooth-hid-api.h

index 9494ec1..116c0fd 100755 (executable)
@@ -647,6 +647,53 @@ BT_EXPORT_API int bluetooth_hid_device_send_key_event(const char *remote_addr,
        return written;
 }
 
+BT_EXPORT_API int bluetooth_hid_device_send_rc_key_event(const char *remote_addr,
+                                       hid_send_rc_key_event_t send_event)
+{
+       int result;
+       int written = 0;
+       int socket_fd;
+       hid_connected_device_info_t *info = NULL;
+
+       switch (privilege_token_send_key) {
+       case 0:
+               result = _bt_check_privilege(BT_BLUEZ_SERVICE, BT_HID_DEVICE_SEND_KEY_EVENT);
+
+               if (result == BLUETOOTH_ERROR_NONE) {
+                       privilege_token_send_key = 1; /* Have a permission */
+               } else if (result == BLUETOOTH_ERROR_PERMISSION_DEINED) {
+                       BT_ERR("Don't have a privilege to use this API");
+                       privilege_token_send_key = -1; /* Don't have a permission */
+                       return BLUETOOTH_ERROR_PERMISSION_DEINED;
+               } else {
+                       /* Just break - It is not related with permission error */
+               }
+               break;
+       case 1:
+               /* Already have a privilege */
+               break;
+       case -1:
+               return BLUETOOTH_ERROR_PERMISSION_DEINED;
+       default:
+               /* Invalid privilge token value */
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       info = __find_hid_info_with_address(remote_addr);
+       if (info == NULL) {
+               BT_ERR("Connection Information not found");
+               return BLUETOOTH_ERROR_INVALID_PARAM;
+       }
+
+       if (info->intr_fd != -1 && info->ctrl_fd == -1)
+               socket_fd = info->intr_fd;
+       else
+               socket_fd = info->ctrl_fd;
+
+       written = write(socket_fd, &send_event, sizeof(send_event));
+       return written;
+}
+
 BT_EXPORT_API int bluetooth_hid_device_reply_to_report(const char *remote_addr,
                                bluetooth_hid_header_type_t htype,
                                bluetooth_hid_param_type_t ptype,
index 47782c5..2ecc8f0 100755 (executable)
@@ -59,6 +59,12 @@ typedef struct {
        unsigned char   key[8];
 } hid_send_key_event_t;
 
+typedef struct {
+       unsigned char   btcode;
+       unsigned char   rep_id;
+       unsigned short  key[3];
+} hid_send_rc_key_event_t;
+
 typedef void (*hid_cb_func_ptr)(int, hid_event_param_t *, void *);
 
 typedef struct {
@@ -284,6 +290,27 @@ int bluetooth_hid_device_send_key_event(const char *remote_addr,
                hid_send_key_event_t send_event);
 
 /**
+ * @fn int bluetooth_hid_device_send_rc_key_event(
+ *             const char *remote_addr, hid_send_rc_key_event_t send_event)
+ *
+ * @brief write the event data on the socket.
+ *
+ * This function is a asynchronous call.
+ *
+ * @return  HID_ERROR_NONE  - Success \n
+ *              HID_ERROR_INVALID_PARAM - Invalid parameter \n
+ *              HID_ERROR_NOT_INITIALIZED - Internal Error \n
+ *              HID_ERROR_NOT_ENABLED - Not enabled \n
+ *              HID_ERROR_INTERNAL - Not enabled \n
+ *
+ * @exception   None
+ * @param[in]  remote_addr   device address of remote device.
+ * @param[in]  send_event   This indicates the event data to send to remote device.
+ * @remark      None
+ */
+int bluetooth_hid_device_send_rc_key_event(const char *remote_addr,
+                                       hid_send_rc_key_event_t send_event);
+/**
  * @fn int bluetooth_hid_device_reply_to_report(const char *remote_addr,
  *                     bluetooth_hid_header_type_t htype,
  *                     bluetooth_hid_param_type_t ptype,