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,
90 /* Detection event types */
94 } uas_detection_type_e;
96 /* Device address information structure */
98 uas_address_type_e type;
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 */
114 unsigned int supported_techs;
118 uas_address_info_t *addr_list;
119 int discriminant; /**< Determines whether to judge PRESENCE/ABSENCE */
120 uas_ble_payload_t *payload;
123 /* Sensor information structure */
131 /* Active scan event types */
133 UAS_ACTIVE_DEVICE_FOUND = 0x01,
134 UAS_ACTIVE_SCAN_COMPLETED = 0x02
135 } uas_active_scan_event_e;
137 /* Callback to be invoked on plug-in's state changes (Ready <-> Not Ready) */
138 typedef void (*uas_state_changed_callback)(int state);
141 * Callback to be invoked on Presen/Absence detection is started/stopped by plug-in's
142 * [Param] state - 0 = detection stopped, 1 = detection started.
144 typedef void (*uas_detection_state_changed_callback)(int state);
147 * Callback to be invoked on Presen/Absence detection status during detection operation
148 * by plug-in's which do not support User identification.
150 typedef void (*uas_detection_status_changed_callback)(uas_detection_type_e type,
154 * Callback to be invoked on Presen/Absence detection by plug-in's which do
155 * not support User identification.
157 typedef void (*uas_detection_callback)(uas_detection_type_e type, void *sensor_info);
160 * Callback to be invoked on Presen/Absence detection by plug-in's which
161 * support User identification.
163 * [Param] device - Device for which Presence/Absence is detected.
165 typedef void (*uas_device_detection_callback)(uas_detection_type_e type,
166 uas_device_info_t *device);
169 * Callback to be invoked in response to add_device() API
171 * [Param] status - Operation status Success/Fail
172 * [Param] device - Device for which add_device() was invoked.
174 typedef void (*uas_device_added_callback)(int status, uas_device_info_t *device);
177 * Callback to be invoked in response to search_active_devices() API
179 * [Param] scan_event - UAS_ACTIVE_DEVICE_FOUND or, UAS_ACTIVE_SCAN_COMPLETED.
180 * [Param] device - Found registerd device info if event is UAS_ACTIVE_DEVICE_FOUND
181 * or, NULL if event is UAS_ACTIVE_SCAN_COMPLETED.
183 typedef void (*uas_device_active_scan_callback)(
184 uas_active_scan_event_e event, const uas_device_info_t *device);
186 /* UA plug-in callback structure */
188 uas_state_changed_callback state_changed_cb; /**< 0:Not ready 1:Ready */
189 uas_detection_state_changed_callback detection_state_cb; /**< 0:Stop 1:Start */
190 uas_detection_status_changed_callback detection_status_cb; /**< 1: change with param */
191 uas_detection_callback detected_cb; /**< For environmental sensors */
192 uas_device_detection_callback device_detected_cb; /**< For connectivity sensors */
193 uas_device_added_callback device_added_cb; /**< For connectivity sensors */
194 uas_device_active_scan_callback active_scan_cb; /**< For connectivity sensors */
198 /* [Sync API] To initialize senspor plug-in */
199 int (*init)(const uas_callbacks_t* callbacks);
201 /* [Sync API] To deinitialize senspor plug-in */
204 /* [Sync API] To get plug-in's current state (READY/NOT_READY) */
205 int (*get_state)(int *state);
208 * [Sync API] To get plug-in's detection capability to help check if
209 * the plug-in supports user detection (Able to identify individual User's
210 * Presence/Absence) or, it only support Presence/Absence detection of without
213 int (*get_capability)(uas_capability_e *capability);
216 * [Sync API] To send registered device list from user DB to plug-ins for
217 * user/device detection. Called whenever device list changes (On device addition/removal).
219 * [Param] devices - List of registered devices relavant to the plug-in's operation.
220 * For example, for WIFI plugin, list contains only devices that were registered/added
221 * for WIFI detection.
223 int (*set_registered_devices)(int num_devices,
224 uas_device_info_t *devices);
227 * [Async API] To Add/register device to be used for User Presence/Absence detection.
228 * uas_device_added_callback() will be called with result of the operation.
230 * [Param] device - Device to be added/registered.
233 int (*add_device)(uas_device_info_t *device);
236 * [Sync API] To remove/unregister device from the list used for User Presence/Absence
239 * [Param] device - Device to be removed/unregistered.
241 int (*remove_device)(uas_device_info_t *device);
243 /* [Sync API] To start (User) Presence/Absence detection.
245 * [Param] type - What kind of event we should detectn.
246 * This type may use bit-wise operation for instance, if we would like to detect
247 * presence and absence simultaneously, we can set type like following:
248 * -> type = UAS_PRESENCE | UAS_ABSENCE.
250 int (*start_detection)(unsigned int detection_type);
252 /* [Sync API] To stop (User) Presence/Absence detection.
254 * [Param] type - What kind of event we should stop.
255 * This type may use bit-wise operation.
257 int (*stop_detection)(unsigned int detection_type);
260 * [Sync API] To enable/disable suspend mode in plug-in. If suspend mode is
261 * enabled, subsequent call to start_detection() will trigger suspend mode operations
262 * for device detection.
263 * mode = 0 - Disable, mode = 1 - Enable
265 int (*set_low_power_mode)(int mode);
268 * [Sync API] To set detection window in plug-in.
270 * [Param] detection_window - Time in second for which User detection procedure is
273 int (*set_detection_window)(unsigned int detection_window);
276 * [Sync API] To set detection threshold value in plug-in.
278 * [Param] presence_threshold - A threshold value for detecting presence [Usage - Optional]
279 * Ex:- In the case of a light plugin, this value is used as a threshold value for
280 * detecting presence.
282 * [Param] absence_threshold - Threshold value for detecting absence [Usage - Optional]
283 * Ex:- In the case of a light plugin, this value is used as a threshold value for
286 int (*set_detection_threshold)(int presence_threshold, int absence_threshold);
289 * [Async API] To search for currently active devices in proximity.
291 * [Param] detection_period - Time in second for which User detection procedure is
294 * Once detection_period is over, list of current active devices will be returned using
295 * uas_active_devices_callback().
298 int (*scan_active_devices)(int detection_period);
301 * [Async API] To cancel the ongoing active devices search.
303 int (*cancel_active_device_scan)(void);
306 * [Sync API] To set iBeacon adv data in plug-in.
308 * [Param] adv_len - The value of length of iBeacon adv data to add.
310 * [Param] iadv - iBeacon adv data to be add.
312 int (*add_ibeacon_adv)(unsigned int adv_len, const char *iadv);
316 UAS_PLUGIN_ID_BLE = 0,
319 UAS_PLUGIN_ID_MOTION,
324 /** Identifier of module */
327 /** Name of this module */
330 /** Author/owner/implementor of the module */
333 /** Version of the module-specific plugin API */
337 int (*init)(uas_api_t **api);
339 /** Modules de-init */
343 #define UAS_MODULE_ADD(id, name, author, version, init, deinit) \
344 uas_module_t uas_module = { id, name, author, version, init, deinit };
349 #endif /* __UAM_PLUGIN_H__ */