2 * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #ifndef __UAM_PLUGIN_H__
19 #define __UAM_PLUGIN_H__
25 /* To be used in case user_id is not known */
26 #define USER_ID_UNKNOWN_USER -1
28 /* UA Plugin states */
30 UAS_STATE_NOT_READY = 0x00,
34 /* Operating System types */
36 UAS_OS_TYPE_UNDEFINED = 0x00,
43 /* Supported technologies by device */
45 UAS_TECH_TYPE_NONE = 0x00,
46 UAS_TECH_TYPE_BT = 0x01,
47 UAS_TECH_TYPE_BLE = 0x02,
48 UAS_TECH_TYPE_WIFI = 0x04,
49 UAS_TECH_TYPE_P2P = 0x08,
52 /* Device Address types */
54 UAS_ADDR_TYPE_BT = 0x01,
63 /* UA plugin return status */
64 #define FOREACH_STATUS(STATUS) \
65 STATUS(UAS_STATUS_SUCCESS, 0x00) \
66 STATUS(UAS_STATUS_FAIL, 0x01) \
67 STATUS(UAS_STATUS_NOT_READY, 0x02) \
68 STATUS(UAS_STATUS_NOMEM, 0x03) \
69 STATUS(UAS_STATUS_BUSY, 0x04) \
70 STATUS(UAS_STATUS_ALREADY_DONE, 0x05) \
71 STATUS(UAS_STATUS_UNSUPPORTED, 0x06) \
73 #define GENERATE_STATUS_ENUM(ENUM, offset) ENUM = -offset,
74 #define GENERATE_STATUS_STRING(STRING, offset) #STRING,
77 FOREACH_STATUS(GENERATE_STATUS_ENUM)
82 * - User detection Not Supported,
83 * - User detection supported,
86 UAS_NOT_SUPPORT_USER, /**< This means that not including user_id */
87 UAS_SUPPORT_USER /**< This means that including user_id */
90 /* Detection event types */
92 UAS_PRESENCE = 0x01, /**< Presence event */
93 UAS_ABSENCE = 0x02 /**< Absence event */
94 } uas_detection_type_e;
96 /* Device address information structure */
98 uas_address_type_e type; /**< Address fype for the connectivity */
99 char *address; /**< Address data */
100 } uas_address_info_t;
102 /* Device ble payload information structure */
104 char service_id; /** Service Id */
105 char device_icon; /** Device icon */
106 char purpose; /** Purpose */
107 char *duid; /** DUID */
108 char *bt_mac; /** BT MAC Address */
111 /* Device information structure */
113 int user_id; /**< User ID for the DB */
114 unsigned int supported_techs; /**< Connectivity type */
115 char *device_id; /**< Device ID */
116 int os; /**< OS type (Tizen,Android, iOS) */
117 int num_addr; /**< The number of address list */
118 uas_address_info_t *addr_list; /**< Address list (IP, Subnet Mask, Gateway etc) */
119 int discriminant; /**< Determines whether to judge PRESENCE/ABSENCE */
120 unsigned long long last_seen; /**< Last seen time */
121 uas_ble_payload_t *payload; /**< BLE payload for BLE device filtering */
124 /* Sensor information structure */
126 unsigned int status; /**< Sensor status */
127 unsigned long long timestamp; /**< Last seen time */
128 int accuracy; /**< Accuracy */
129 int count; /**< How many sensor data are there */
130 double *values; /**< Sensor data */
133 /* Active scan event types */
135 UAS_ACTIVE_DEVICE_FOUND = 0x01,
136 UAS_ACTIVE_SCAN_COMPLETED = 0x02
137 } uas_active_scan_event_e;
139 /* Callback to be invoked on plug-in's state changes (Ready <-> Not Ready) */
140 typedef void (*uas_state_changed_callback)(int state);
143 * Callback to be invoked on Presen/Absence detection is started/stopped by plug-in's
144 * [Param] state - 0 = detection stopped, 1 = detection started.
146 typedef void (*uas_detection_state_changed_callback)(int state);
149 * Callback to be invoked on Presen/Absence detection status during detection operation
150 * by plug-in's which do not support User identification.
152 typedef void (*uas_detection_status_changed_callback)(uas_detection_type_e type,
156 * Callback to be invoked on Presen/Absence detection by plug-in's which do
157 * not support User identification.
159 typedef void (*uas_detection_callback)(uas_detection_type_e type, void *sensor_info);
162 * Callback to be invoked on Presen/Absence detection by plug-in's which
163 * support User identification.
165 * [Param] device - Device for which Presence/Absence is detected.
167 typedef void (*uas_device_detection_callback)(uas_detection_type_e type,
168 uas_device_info_t *device);
171 * Callback to be invoked in response to add_device() API
173 * [Param] status - Operation status Success/Fail
174 * [Param] device - Device for which add_device() was invoked.
176 typedef void (*uas_device_added_callback)(int status, uas_device_info_t *device);
179 * Callback to be invoked in response to search_active_devices() API
181 * [Param] scan_event - UAS_ACTIVE_DEVICE_FOUND or, UAS_ACTIVE_SCAN_COMPLETED.
182 * [Param] device - Found registerd device info if event is UAS_ACTIVE_DEVICE_FOUND
183 * or, NULL if event is UAS_ACTIVE_SCAN_COMPLETED.
185 typedef void (*uas_device_active_scan_callback)(
186 uas_active_scan_event_e event, const uas_device_info_t *device);
189 /* UA plug-in callback structure */
191 uas_state_changed_callback state_changed_cb; /**< 0:Not ready 1:Ready */
192 uas_detection_state_changed_callback detection_state_cb; /**< 0:Stop 1:Start */
193 uas_detection_status_changed_callback detection_status_cb; /**< 1: change with param */
194 uas_detection_callback detected_cb; /**< For environmental sensors */
195 uas_device_detection_callback device_detected_cb; /**< For connectivity sensors */
196 uas_device_added_callback device_added_cb; /**< For connectivity sensors */
197 uas_device_active_scan_callback device_active_scan_cb; /**< For connectivity sensors */
201 /* [Sync API] To initialize senspor plug-in */
202 int (*init)(const uas_callbacks_t* callbacks);
204 /* [Sync API] To deinitialize senspor plug-in */
207 /* [Sync API] To get plug-in's current state (READY/NOT_READY) */
208 int (*get_state)(int *state);
211 * [Sync API] To get plug-in's detection capability to help check if
212 * the plug-in supports user detection (Able to identify individual User's
213 * Presence/Absence) or, it only support Presence/Absence detection of without
216 int (*get_capability)(uas_capability_e *capability);
219 * [Sync API] To send registered device list from user DB to plug-ins for
220 * user/device detection. Called whenever device list changes (On device addition/removal).
222 * [Param] devices - List of registered devices relavant to the plug-in's operation.
223 * For example, for WIFI plugin, list contains only devices that were registered/added
224 * for WIFI detection.
226 int (*set_registered_devices)(int num_devices,
227 uas_device_info_t *devices);
230 * [Async API] To Add/register device to be used for User Presence/Absence detection.
231 * uas_device_added_callback() will be called with result of the operation.
233 * [Param] device - Device to be added/registered.
236 int (*add_device)(uas_device_info_t *device);
239 * [Sync API] To remove/unregister device from the list used for User Presence/Absence
242 * [Param] device - Device to be removed/unregistered.
244 int (*remove_device)(uas_device_info_t *device);
246 /* [Sync API] To start (User) Presence/Absence detection.
248 * [Param] type - What kind of event we should detectn.
249 * This type may use bit-wise operation for instance, if we would like to detect
250 * presence and absence simultaneously, we can set type like following:
251 * -> type = UAS_PRESENCE | UAS_ABSENCE.
253 int (*start_detection)(unsigned int detection_type);
255 /* [Sync API] To stop (User) Presence/Absence detection.
257 * [Param] type - What kind of event we should stop.
258 * This type may use bit-wise operation.
260 int (*stop_detection)(unsigned int detection_type);
263 * [Sync API] To enable/disable suspend mode in plug-in. If suspend mode is
264 * enabled, subsequent call to start_detection() will trigger suspend mode operations
265 * for device detection.
266 * mode = 0 - Disable, mode = 1 - Enable
268 int (*set_low_power_mode)(int mode);
271 * [Sync API] To set detection window in plug-in.
273 * [Param] detection_window - Time in second for which User detection procedure is
276 int (*set_detection_window)(unsigned int detection_window);
279 * [Sync API] To set detection threshold value in plug-in.
281 * [Param] presence_threshold - A threshold value for detecting presence [Usage - Optional]
282 * Ex:- In the case of a light plugin, this value is used as a threshold value for
283 * detecting presence.
285 * [Param] absence_threshold - Threshold value for detecting absence [Usage - Optional]
286 * Ex:- In the case of a light plugin, this value is used as a threshold value for
289 int (*set_detection_threshold)(int presence_threshold, int absence_threshold);
292 * [Async API] To search for currently active devices in proximity.
294 * [Param] detection_period - Time in second for which User detection procedure is
297 * Once detection_period is over, list of current active devices will be returned using
298 * uas_active_devices_callback().
301 int (*scan_active_devices)(int detection_period);
304 * [Async API] To cancel the ongoing active devices search.
306 int (*cancel_active_device_scan)(void);
309 * [Sync API] To set iBeacon adv data in plug-in.
311 * [Param] adv_len - The value of length of iBeacon adv data to add.
313 * [Param] iadv - iBeacon adv data to be add.
315 int (*add_ibeacon_adv)(unsigned int adv_len, const char *iadv);
319 UAS_PLUGIN_ID_BLE = 0,
322 UAS_PLUGIN_ID_MOTION,
327 /** Identifier of module */
330 /** Name of this module */
333 /** Author/owner/implementor of the module */
336 /** Version of the module-specific plugin API */
340 int (*init)(uas_api_t **api);
342 /** Modules de-init */
346 #define UAS_MODULE_ADD(id, name, author, version, init, deinit) \
347 uas_module_t uas_module = { id, name, author, version, init, deinit };
352 #endif /* __UAM_PLUGIN_H__ */