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_MANAGER_CORE_H__
19 #define __UAM_MANAGER_CORE_H__
31 UAM_ADDR_TYPE_BT = 0x01, /**< Bluetooth device address */
32 UAM_ADDR_TYPE_BLE, /**< BLE device adress */
33 UAM_ADDR_TYPE_WIFI, /**< Wi-Fi Infra. device address */
34 UAM_ADDR_TYPE_P2P, /**< Wi-Fi Direct device address */
35 UAM_ADDR_TYPE_IPv4, /**< IPv4 Address */
36 UAM_ADDR_TYPE_IPv6, /**< IPv6 Address */
40 #define UAM_DETECTION_WINDOW_DEFAULT 55 /* 55 seconds */
41 #define UAM_DETECTION_WINDOW_MAX 55 /* 55 seconds */
42 #define UAM_DETECTION_WINDOW_STEP 5 /* 5 seconds */
44 #define UAM_DETECTION_CYCLE_DEFAULT 900 /* 900 seconds */
45 #define UAM_DETECTION_CYCLE_MIN 60 /* 60 seconds */
49 unsigned int cycle; /**< Detection Cycle = Detection Period * cycle */
50 int remaining_time; /**< Time remaining up to detection_cycle (unit: sec) */
51 int presence_threshold; /**< PRESENCE threshold */
52 int absence_threshold; /**< ABSENCE threshold */
53 GSList *monitors; /**< Monitor handle list */
54 GSList *dev_techs; /**< Device list */
55 } uam_db_service_info_t;
58 char *device_id; /**< Device ID */
59 uam_tech_type_e tech_type; /**< Connectivity type */
60 char *service; /**< Connected service name */
61 int discriminant; /**< Service dependent discriminant */
62 unsigned long long last_seen; /**< Service dependent last seen time */
66 uam_addr_type_e addr_type; /**< Address type (i.e., BT/BLE/Wi-Fi/IPv4/IPv6) */
67 char *address; /**< Address */
68 } uam_db_address_info_t;
71 char primary_key; /** Primary key */
72 char device_icon; /** Device icon */
73 char purpose; /** Purpose */
74 char *duid; /** DUID */
75 char *bt_mac; /** BT MAC Address */
76 } uam_db_ble_payload_t;
79 uam_tech_type_e tech_type; /**< Connectivity type */
80 GSList *addresses; /**< Address list */
81 int presence_state; /**< PRESENCE or ABSENCE */
82 unsigned long long last_seen; /**< Last seen time */
83 gboolean discriminant; /**< Decide whether to detect device or not */
84 struct uam_db_device_info *device; /**< Device info which stored in the DB */
85 GSList *svc_list; /**< Service list */
86 uam_db_ble_payload_t *payload; /**< Filtering info when detecting the BLE payload */
89 typedef struct uam_db_device_info {
90 int os; /**< OS type */
91 char *device_id; /**< Device ID */
92 GSList *tech_list; /**< Connectivity device info. list (i.e., BT/BLE/Wi-Fi/...)*/
93 unsigned int supported_techs; /**< bitmask to check how many connectivities are supported */
94 struct uam_db_user_info *user; /**< Owner infomation for these devices */
95 gboolean discriminant; /**< Determines whether to judge PRESENCE/ABSENCE */
96 } uam_db_device_info_t;
98 typedef struct uam_db_user_info {
99 int user_id; /**< User ID */
100 char *name; /**< User name */
101 char *account; /**< Account */
102 GSList *devices; /**< Device list */
103 unsigned long long last_seen; /**< Last seen time */
104 } uam_db_user_info_t;
108 UAM_ACTIVE_DEVICE_FOUND = 0x01, /**< Found devices using ARPing */
109 UAM_ACTIVE_SCAN_COMPLETED = 0x02 /**< Active ARPing done */
110 } uam_active_scan_event_e;
112 int _uam_core_add_user(int *user_id, const char *account, const char *name);
114 int _uam_core_remove_user(const char *account);
116 int _uam_core_update_user(uam_user_info_s *user);
118 int _uam_core_add_device(const char *account,
119 const uam_device_info_s *dev_info);
121 int _uam_core_remove_device(const char *account,
122 const uam_device_info_s *dev_info);
124 int _uam_core_remove_device_by_device_id(const char *device_id,
127 int _uam_core_remove_device_by_mac(const char *mac);
129 int _uam_core_get_default_user(uam_user_info_s *user_info);
131 int _uam_core_get_users(int *count, uam_user_info_s **user_list);
133 int _uam_core_get_user_by_account(const char *account, uam_user_info_s *user);
135 int _uam_core_get_devcie_by_device_id(
136 const char *device_id, int tech_type, uam_device_info_s *device);
138 int _uam_core_get_devcie_by_mac(const char *mac, uam_device_info_s *device);
140 int _uam_core_get_user_by_device_id(const char *device_id,
141 uam_user_info_s *user);
143 int _uam_core_get_user_by_mac(const char *mac, uam_user_info_s *user);
145 int _uam_core_get_devices(int *count, uam_device_info_s **device_list);
147 int _uam_core_get_user_devices(const char *account,
148 int *count, uam_device_info_s **device_list);
150 int _uam_core_is_device_added(uam_device_info_s *dev, gboolean *is_added);
152 int _uam_core_get_available_sensors(unsigned int *sensor_bitmask);
154 gboolean _uam_core_is_sensor_ready(unsigned int sensor);
156 int _uam_core_set_detection_threshold(unsigned int sensor,
157 int presence_threshold, int absence_threshold);
159 int _uam_core_start_presence_detection(const char *svc_name, char *sender,
160 unsigned int sensors);
162 int _uam_core_stop_presence_detection(const char *svc_name, char *sender,
163 unsigned int sensors);
165 int _uam_core_start_absence_detection(const char *svc_name, char *sender,
166 unsigned int sensors);
168 int _uam_core_stop_absence_detection(const char *svc_name, char *sender,
169 unsigned int sensors);
171 int _uam_core_set_low_power_mode(unsigned int bit_mask, gboolean mode);
173 int _uam_core_get_detection_window(unsigned int *window);
175 int _uam_core_set_detection_window(unsigned int window);
177 int _uam_core_init(void);
179 void _uam_core_deinit(void);
181 void _uam_core_handle_sensor_ready(unsigned int sensor, gboolean is_ready);
183 int _uam_core_handle_device_added(int status,
184 int user_id, const uam_device_info_s *dev_info);
186 int _uam_core_handle_presence_detected(unsigned int sensor,
187 int user_id, void *sensor_info);
189 void _uam_core_handle_absence_detected(unsigned int sensor,
190 int user_id, void *sensor_info);
192 void _uam_core_cleanup_monitor(char *name);
194 void _uam_core_reset_database(void);
196 unsigned int _uam_core_get_active_sensors(int detection_mode);
198 void _uam_core_handle_detection_started(unsigned int sensor);
200 void _uam_core_handle_detection_stopped(unsigned int sensor);
202 int _uam_core_start_active_device_scan(char *sender, unsigned int sensors,
203 int detection_period);
205 int _uam_core_stop_active_device_scan(char *sender, unsigned int sensors);
207 void _uam_core_handle_active_device(uam_active_scan_event_e event,
208 unsigned int sensor, const uam_device_info_s *dev_info);
210 int _uam_core_get_default_service(uam_service_info_s *service_info);
212 int _uam_core_register_service(uam_service_info_s *svc);
214 int _uam_core_update_service(uam_service_info_s *svc);
216 int _uam_core_unregister_service(const char *svc_name);
218 int _uam_core_get_service_devices(const char *svc_name, int *count,
219 uam_device_info_s **device_list);
221 int _uam_core_get_service_users(const char *svc_name, int *count,
222 uam_user_info_s **user_list);
224 int _uam_core_get_services(int *count, uam_service_info_s **service_list);
226 int _uam_core_service_add_user(const char *service_name, const char *account);
228 int _uam_core_service_remove_user(const char *service, const char *account);
230 int _uam_core_service_add_device(const char *service_name,
231 const char *device_id, int tech_type);
233 int _uam_core_service_remove_device(const char *service_name,
234 const char *device_id, int tech_type);
236 int _uam_core_service_set_device_discriminant(const char *service_name,
237 const char *device_id, int tech_type, gboolean discriminant);
239 int _uam_core_service_get_device_discriminant(const char *service_name,
240 const char *device_id, int tech_type, gboolean *discriminant);
242 int _uam_core_service_get_device_last_seen(const char *svc_name,
243 const char *device_id, int tech_type, unsigned long long *last_seen);
245 int _uam_core_set_service_detection_cycle(const char *svc_name,
248 int _uam_core_get_service_detection_cycle(const char *svc_name,
249 unsigned int *cycle);
251 int _uam_core_update_device(const uam_device_info_s *a_device);
253 int _uam_core_add_ibeacon_adv(unsigned int adv_len, const char *iadv);
255 void _uam_core_handle_status_changed(unsigned int sensor, void *info);
260 #endif /* __UAM_MANAGER_CORE_H__ */