Merge the code from private
[platform/core/connectivity/bluetooth-frwk.git] / include / bluetooth-hid-api.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *              http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #ifndef __BLUETOOTH_HID_API_H
19 #define __BLUETOOTH_HID_API_H
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25
26 #define HID_ADDRESS_LENGTH 6
27
28 #define HID_ERROR_NONE                  ((int)0)
29
30 #define HID_ERROR_BASE                  ((int)0)
31 #define HID_ERROR_ALREADY_INITIALIZED   ((int)HID_ERROR_BASE - 0x01)
32 #define HID_ERROR_NOT_INITIALIZED       ((int)HID_ERROR_BASE - 0x01)
33 #define HID_ERROR_NOT_PAIRED            ((int)HID_ERROR_BASE - 0x02)
34 #define HID_ERROR_INTERNAL              ((int)HID_ERROR_BASE - 0x03)
35 #define HID_ERROR_INVALID_PARAM         ((int)HID_ERROR_BASE - 0x04)
36 #define HID_ERROR_NOT_ENABLED           ((int)HID_ERROR_BASE - 0x05)
37 #define HID_ERROR_CONNECTION_FAILED     ((int)HID_ERROR_BASE - 0x06)
38
39 typedef struct {
40         int event;
41         int result;
42         void *param_data;
43         void *user_data;
44 } hid_event_param_t;
45
46 typedef struct {
47         unsigned char btcode;
48         unsigned char rep_id;
49         unsigned char button;
50         signed char axis_x;
51         signed char axis_y;
52         signed char axis_z;
53 } hid_send_mouse_event_t;
54
55 typedef struct {
56         unsigned char   btcode;
57         unsigned char   rep_id;
58         unsigned char   modify;
59         unsigned char   key[8];
60 } hid_send_key_event_t;
61
62 typedef struct {
63         unsigned char   btcode;
64         unsigned char   rep_id;
65         unsigned short  key[3];
66 } hid_send_rc_key_event_t;
67
68 typedef void (*hid_cb_func_ptr)(int, hid_event_param_t *, void *);
69
70 typedef struct {
71         unsigned char addr[HID_ADDRESS_LENGTH];
72 } hid_device_address_t;
73
74
75 /**
76  * @fn int bluetooth_hid_init(hid_cb_func_ptr callback_ptr, void *user_data)
77  * @brief Initialize HID service and register the callback
78  *
79  * This function is a synchronous call.
80  *
81  * @return  HID_ERROR_NONE  - Success \n
82  *              HID_ERROR_ALREADY_INITIALIZED - Aready Initialized \n
83  *              HID_ERROR_INTERNAL - Internal Error \n
84  *              HID_ERROR_NOT_ENABLED - Not enabled \n
85  *
86  * @remark      None
87  *
88  */
89 int bluetooth_hid_init(hid_cb_func_ptr callback_ptr, void *user_data);
90
91 /**
92  * @fn int bluetooth_hid_deinit(void)
93  * @brief Initialize HID service and register the callback
94  *
95  * This function is a synchronous call.
96  *
97  * @return  HID_ERROR_NONE  - Success \n
98  *              HID_ERROR_NOT_INITIALIZED - Not Initialiezed \n
99  *
100  * @remark      None
101  *
102  */
103 int bluetooth_hid_deinit(void);
104
105
106 /**
107  * @fn int bluetooth_hid_connect(hid_device_address_t *device_address)
108  *
109  * @brief Connect the HID device in the peer
110  *
111  * This function is a asynchronous call.
112  * The HID connect request is responded by BLUETOOTH_HID_CONNECTED event.
113  *
114  * @return  HID_ERROR_NONE  - Success \n
115  *              HID_ERROR_INVALID_PARAM - Invalid parameter \n
116  *              HID_ERROR_NOT_INITIALIZED - Internal Error \n
117  *              HID_ERROR_NOT_ENABLED - Not enabled \n
118  *              HID_ERROR_INTERNAL - Not enabled \n
119  *              HID_ERROR_NOT_PAIRED - Not enabled \n
120  *              HID_ERROR_CONNECTION_FAILED - Connection Fail \n
121  *
122  * @exception   None
123  * @param[in]  device_address   This indicates an address of the device with which the pairing
124  *                              should be initiated
125  * @remark      None
126  */
127 int bluetooth_hid_connect(hid_device_address_t *device_address);
128
129 /**
130  * @fn int bluetooth_hid_disconnect(hid_device_address_t *device_address)
131  *
132  * @brief Disconnect the HID device in the peer
133  *
134  * This function is a asynchronous call.
135  * The HID connect request is responded by BLUETOOTH_HID_DISCONNECTED event.
136  *
137  * @return  HID_ERROR_NONE  - Success \n
138  *              HID_ERROR_INVALID_PARAM - Invalid parameter \n
139  *              HID_ERROR_NOT_INITIALIZED - Internal Error \n
140  *              HID_ERROR_NOT_ENABLED - Not enabled \n
141  *              HID_ERROR_INTERNAL - Not enabled \n
142  *              HID_ERROR_NOT_PAIRED - Not enabled \n
143  *              HID_ERROR_CONNECTION_FAILED - Connection Fail \n
144  *
145  * @exception   None
146  * @param[in]  device_address   This indicates an address of the device with which the pairing
147  *                              should be initiated
148  * @remark      None
149  */
150 int bluetooth_hid_disconnect(hid_device_address_t *device_address);
151
152 int bluetooth_hid_enable_barcode_feature(void);
153
154 /**
155  * @fn int bluetooth_hid_device_init(hid_cb_func_ptr callback_ptr, void *user_data)
156  * @brief Initialize HID Device service and register the callback
157  *
158  * This function is a synchronous call.
159  *
160  * @return  HID_ERROR_NONE  - Success \n
161  *              HID_ERROR_ALREADY_INITIALIZED - Aready Initialized \n
162  *              HID_ERROR_INTERNAL - Internal Error \n
163  *              HID_ERROR_NOT_ENABLED - Not enabled \n
164  *
165  * @remark      None
166  *
167  */
168 int bluetooth_hid_device_init(hid_cb_func_ptr callback, void *user_data);
169
170 /**
171  * @fn int bluetooth_hid_device_deinit(void)
172  * @brief Initialize HID service and register the callback
173  *
174  * This function is a synchronous call.
175  *
176  * @return  HID_ERROR_NONE  - Success \n
177  *              HID_ERROR_NOT_INITIALIZED - Not Initialiezed \n
178  *
179  * @remark      None
180  *
181  */
182 int bluetooth_hid_device_deinit();
183
184 /**
185  * @fn int bluetooth_hid_device_activate()
186  *
187  * @brief Register the HID Device UUID with bluez with RegisterProfile.
188  *
189  * This function is a asynchronous call.
190  *
191  * @return  HID_ERROR_NONE  - Success \n
192  *              HID_ERROR_NOT_INITIALIZED - Internal Error \n
193  *              HID_ERROR_NOT_ENABLED - Not enabled \n
194  *              HID_ERROR_INTERNAL - Not enabled \n
195  *
196  * @exception   None
197  * @remark      None
198  */
199 int bluetooth_hid_device_activate(void);
200
201 /**
202  * @fn int bluetooth_hid_device_deactivate()
203  *
204  * @brief Unregister the HID Device UUID with bluez with UnRegisterProfile.
205  *
206  * This function is a asynchronous call.
207  *
208  * @return  HID_ERROR_NONE  - Success \n
209  *              HID_ERROR_NOT_INITIALIZED - Internal Error \n
210  *              HID_ERROR_NOT_ENABLED - Not enabled \n
211  *              HID_ERROR_INTERNAL - Not enabled \n
212  *
213  * @exception   None
214  * @remark      None
215  */
216 int bluetooth_hid_device_deactivate(void);
217
218 /**
219  * @fn int bluetooth_hid_device_connect(const char *remote_addr)
220  *
221  * @brief Initiate the connection for HID device role with remote device
222  * address specified as parameter.
223  *
224  * This function is a asynchronous call.
225  *
226  * @return  HID_ERROR_NONE  - Success \n
227  *
228  * @exception   None
229  * @param[in]  remote_addr   device address of remote device.
230  * @remark      None
231  */
232 int bluetooth_hid_device_connect(const char *remote_addr);
233 /**
234  * @fn int bluetooth_hid_device_disconnect()
235  *
236  * @brief Terminate the connection with HID host device with DisconnectProfile.
237  *
238  * This function is a asynchronous call.
239  *
240  * @return  HID_ERROR_NONE  - Success \n
241  *              HID_ERROR_NOT_INITIALIZED - Internal Error \n
242  *              HID_ERROR_NOT_ENABLED - Not enabled \n
243  *              HID_ERROR_INTERNAL - Not enabled \n
244  *
245  * @exception   None
246  * @param[in]  remote_addr   device address of remote device.
247  * @remark      None
248  */
249
250 int bluetooth_hid_device_disconnect(const char *remote_addr);
251
252 /**
253  * @fn int bluetooth_hid_send_mouse_event(hid_send_mouse_event_t send_event)
254  *
255  * @brief write the event data on the socket.
256  *
257  * This function is a asynchronous call.
258  *
259  * @return  HID_ERROR_NONE  - Success \n
260  *              HID_ERROR_INVALID_PARAM - Invalid parameter \n
261  *              HID_ERROR_NOT_INITIALIZED - Internal Error \n
262  *              HID_ERROR_NOT_ENABLED - Not enabled \n
263  *              HID_ERROR_INTERNAL - Not enabled \n
264  *
265  * @exception   None
266  * @param[in]  remote_addr   device address of remote device.
267  * @param[in]  send_event   This indicates the event data to send to remote device.
268  * @remark      None
269  */
270 int bluetooth_hid_device_send_mouse_event(const char *remote_addr,
271                 hid_send_mouse_event_t send_event);
272
273 /**
274  * @fn int bluetooth_hid_device_send_key_event(hid_send_key_event_t send_event)
275  *
276  * @brief write the event data on the socket.
277  *
278  * This function is a asynchronous call.
279  *
280  * @return  HID_ERROR_NONE  - Success \n
281  *              HID_ERROR_INVALID_PARAM - Invalid parameter \n
282  *              HID_ERROR_NOT_INITIALIZED - Internal Error \n
283  *              HID_ERROR_NOT_ENABLED - Not enabled \n
284  *              HID_ERROR_INTERNAL - Not enabled \n
285  *
286  * @exception   None
287  * @param[in]  remote_addr   device address of remote device.
288  * @param[in]  send_event   This indicates the event data to send to remote device.
289  * @remark      None
290  */
291 int bluetooth_hid_device_send_key_event(const char *remote_addr,
292                 hid_send_key_event_t send_event);
293
294 /**
295  * @fn int bluetooth_hid_device_send_rc_key_event(
296  *              const char *remote_addr, hid_send_rc_key_event_t send_event)
297  *
298  * @brief write the event data on the socket.
299  *
300  * This function is a asynchronous call.
301  *
302  * @return  HID_ERROR_NONE  - Success \n
303  *              HID_ERROR_INVALID_PARAM - Invalid parameter \n
304  *              HID_ERROR_NOT_INITIALIZED - Internal Error \n
305  *              HID_ERROR_NOT_ENABLED - Not enabled \n
306  *              HID_ERROR_INTERNAL - Not enabled \n
307  *
308  * @exception   None
309  * @param[in]  remote_addr   device address of remote device.
310  * @param[in]  send_event   This indicates the event data to send to remote device.
311  * @remark      None
312  */
313 int bluetooth_hid_device_send_rc_key_event(const char *remote_addr,
314                                         hid_send_rc_key_event_t send_event);
315 /**
316  * @fn int bluetooth_hid_device_reply_to_report(const char *remote_addr,
317  *                      bt_hid_header_type_t htype,
318  *                      bt_hid_param_type_t ptype,
319  *                      char *buffer)
320  *
321  * @brief write the event data on the socket.
322  *
323  * This function is a asynchronous call.
324  *
325  * @return  HID_ERROR_NONE  - Success \n
326  *              HID_ERROR_INVALID_PARAM - Invalid parameter \n
327  *              HID_ERROR_NOT_INITIALIZED - Internal Error \n
328  *              HID_ERROR_NOT_ENABLED - Not enabled \n
329  *              HID_ERROR_INTERNAL - Not enabled \n
330  *
331  * @exception   None
332  * @param[in]  remote_addr   device address of remote device.
333  * @param[in]  htype   header type to be present in response
334  * @param[in]  ptype   Parameter type to be present in response.
335  * @param[in]  buffer   Data need to be send in reponse payload.
336  * @remark      None
337  */
338 int bluetooth_hid_device_reply_to_report(const char *remote_addr,
339                 bt_hid_header_type_t htype,
340                 bt_hid_param_type_t ptype,
341                 const char *data,
342                 unsigned int data_len);
343
344 #ifdef __cplusplus
345 }
346 #endif
347 #endif /* __BLUETOOTH_HID_API_H */