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 */
125 unsigned int status; /**< Sensor status */
126 unsigned long long timestamp; /**< Timestamp */
127 int accuracy; /**< Accuracy */
128 int count; /**< How many sensor data are there */
129 double *values; /**< Sensor data */
132 /* Active scan event types */
134 UAS_ACTIVE_DEVICE_FOUND = 0x01,
135 UAS_ACTIVE_SCAN_COMPLETED = 0x02
136 } uas_active_scan_event_e;
138 /* Callback to be invoked on plug-in's state changes (Ready <-> Not Ready) */
139 typedef void (*uas_state_changed_callback)(int state);
142 * Callback to be invoked on Presen/Absence detection is started/stopped by plug-in's
143 * [Param] state - 0 = detection stopped, 1 = detection started.
145 typedef void (*uas_detection_state_changed_callback)(int state);
148 * Callback to be invoked on Presen/Absence detection status during detection operation
149 * by plug-in's which do not support User identification.
151 typedef void (*uas_detection_status_changed_callback)(uas_detection_type_e type,
155 * Callback to be invoked on Presen/Absence detection by plug-in's which do
156 * not support User identification.
158 typedef void (*uas_detection_callback)(uas_detection_type_e type, void *sensor_info);
161 * Callback to be invoked on Presen/Absence detection by plug-in's which
162 * support User identification.
164 * [Param] device - Device for which Presence/Absence is detected.
166 typedef void (*uas_device_detection_callback)(uas_detection_type_e type,
167 uas_device_info_t *device);
170 * Callback to be invoked in response to add_device() API
172 * [Param] status - Operation status Success/Fail
173 * [Param] device - Device for which add_device() was invoked.
175 typedef void (*uas_device_added_callback)(int status, uas_device_info_t *device);
178 * Callback to be invoked in response to search_active_devices() API
180 * [Param] scan_event - UAS_ACTIVE_DEVICE_FOUND or, UAS_ACTIVE_SCAN_COMPLETED.
181 * [Param] device - Found registerd device info if event is UAS_ACTIVE_DEVICE_FOUND
182 * or, NULL if event is UAS_ACTIVE_SCAN_COMPLETED.
184 typedef void (*uas_device_active_scan_callback)(
185 uas_active_scan_event_e event, const uas_device_info_t *device);
187 /* UA plug-in callback structure */
189 uas_state_changed_callback state_changed_cb; /**< 0:Not ready 1:Ready */
190 uas_detection_state_changed_callback detection_state_cb; /**< 0:Stop 1:Start */
191 uas_detection_status_changed_callback detection_status_cb; /**< 1: change with param */
192 uas_detection_callback detected_cb; /**< For environmental sensors */
193 uas_device_detection_callback device_detected_cb; /**< For connectivity sensors */
194 uas_device_added_callback device_added_cb; /**< For connectivity sensors */
195 uas_device_active_scan_callback active_scan_cb; /**< For connectivity sensors */
199 /* [Sync API] To initialize senspor plug-in */
200 int (*init)(const uas_callbacks_t* callbacks);
202 /* [Sync API] To deinitialize senspor plug-in */
205 /* [Sync API] To get plug-in's current state (READY/NOT_READY) */
206 int (*get_state)(int *state);
209 * [Sync API] To get plug-in's detection capability to help check if
210 * the plug-in supports user detection (Able to identify individual User's
211 * Presence/Absence) or, it only support Presence/Absence detection of without
214 int (*get_capability)(uas_capability_e *capability);
217 * [Sync API] To send registered device list from user DB to plug-ins for
218 * user/device detection. Called whenever device list changes (On device addition/removal).
220 * [Param] devices - List of registered devices relavant to the plug-in's operation.
221 * For example, for WIFI plugin, list contains only devices that were registered/added
222 * for WIFI detection.
224 int (*set_registered_devices)(int num_devices,
225 uas_device_info_t *devices);
228 * [Async API] To Add/register device to be used for User Presence/Absence detection.
229 * uas_device_added_callback() will be called with result of the operation.
231 * [Param] device - Device to be added/registered.
234 int (*add_device)(uas_device_info_t *device);
237 * [Sync API] To remove/unregister device from the list used for User Presence/Absence
240 * [Param] device - Device to be removed/unregistered.
242 int (*remove_device)(uas_device_info_t *device);
244 /* [Sync API] To start (User) Presence/Absence detection.
246 * [Param] type - What kind of event we should detectn.
247 * This type may use bit-wise operation for instance, if we would like to detect
248 * presence and absence simultaneously, we can set type like following:
249 * -> type = UAS_PRESENCE | UAS_ABSENCE.
251 int (*start_detection)(unsigned int detection_type);
253 /* [Sync API] To stop (User) Presence/Absence detection.
255 * [Param] type - What kind of event we should stop.
256 * This type may use bit-wise operation.
258 int (*stop_detection)(unsigned int detection_type);
261 * [Sync API] To enable/disable suspend mode in plug-in. If suspend mode is
262 * enabled, subsequent call to start_detection() will trigger suspend mode operations
263 * for device detection.
264 * mode = 0 - Disable, mode = 1 - Enable
266 int (*set_low_power_mode)(int mode);
269 * [Sync API] To set detection window in plug-in.
271 * [Param] detection_window - Time in second for which User detection procedure is
274 int (*set_detection_window)(unsigned int detection_window);
277 * [Sync API] To set detection threshold value in plug-in.
279 * [Param] presence_threshold - A threshold value for detecting presence [Usage - Optional]
280 * Ex:- In the case of a light plugin, this value is used as a threshold value for
281 * detecting presence.
283 * [Param] absence_threshold - Threshold value for detecting absence [Usage - Optional]
284 * Ex:- In the case of a light plugin, this value is used as a threshold value for
287 int (*set_detection_threshold)(int presence_threshold, int absence_threshold);
290 * [Async API] To search for currently active devices in proximity.
292 * [Param] detection_period - Time in second for which User detection procedure is
295 * Once detection_period is over, list of current active devices will be returned using
296 * uas_active_devices_callback().
299 int (*scan_active_devices)(int detection_period);
302 * [Async API] To cancel the ongoing active devices search.
304 int (*cancel_active_device_scan)(void);
307 * [Sync API] To set iBeacon adv data in plug-in.
309 * [Param] adv_len - The value of length of iBeacon adv data to add.
311 * [Param] iadv - iBeacon adv data to be add.
313 int (*add_ibeacon_adv)(unsigned int adv_len, const char *iadv);
317 UAS_PLUGIN_ID_BLE = 0,
320 UAS_PLUGIN_ID_MOTION,
325 /** Identifier of module */
328 /** Name of this module */
331 /** Author/owner/implementor of the module */
334 /** Version of the module-specific plugin API */
338 int (*init)(uas_api_t **api);
340 /** Modules de-init */
344 #define UAS_MODULE_ADD(id, name, author, version, init, deinit) \
345 uas_module_t uas_module = { id, name, author, version, init, deinit };
350 #endif /* __UAM_PLUGIN_H__ */