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 secondary_key; /** Purpose */
74 char *device_uid; /** DEVICE_UID */
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 */
88 typedef struct uam_db_device_info {
89 int os; /**< OS type */
90 char *device_id; /**< Device ID */
91 GSList *tech_list; /**< Connectivity device info. list (i.e., BT/BLE/Wi-Fi/...)*/
92 unsigned int supported_techs; /**< bitmask to check how many connectivities are supported */
93 struct uam_db_user_info *user; /**< Owner infomation for these devices */
94 gboolean discriminant; /**< Determines whether to judge PRESENCE/ABSENCE */
95 } uam_db_device_info_t;
97 typedef struct uam_db_user_info {
98 int user_id; /**< User ID */
99 char *name; /**< User name */
100 char *account; /**< Account */
101 GSList *devices; /**< Device list */
102 unsigned long long last_seen; /**< Last seen time */
103 } uam_db_user_info_t;
107 UAM_ACTIVE_DEVICE_FOUND = 0x01, /**< Found devices using ARPing */
108 UAM_ACTIVE_SCAN_COMPLETED = 0x02 /**< Active ARPing done */
109 } uam_active_scan_event_e;
111 int _uam_core_add_user(int *user_id, const char *account, const char *name);
113 int _uam_core_remove_user(const char *account);
115 int _uam_core_update_user(uam_user_info_s *user);
117 int _uam_core_add_device(const char *account,
118 const uam_device_info_s *dev_info);
120 int _uam_core_remove_device(const char *account,
121 const uam_device_info_s *dev_info);
123 int _uam_core_remove_device_by_device_id(const char *device_id,
126 int _uam_core_remove_device_by_mac(const char *mac);
128 int _uam_core_get_default_user(uam_user_info_s *user_info);
130 int _uam_core_get_users(int *count, uam_user_info_s **user_list);
132 int _uam_core_get_user_by_account(const char *account, uam_user_info_s *user);
134 int _uam_core_get_devcie_by_device_id(
135 const char *device_id, int tech_type, uam_device_info_s *device);
137 int _uam_core_get_devcie_by_mac(const char *mac, uam_device_info_s *device);
139 int _uam_core_get_user_by_device_id(const char *device_id,
140 uam_user_info_s *user);
142 int _uam_core_get_user_by_mac(const char *mac, uam_user_info_s *user);
144 int _uam_core_get_devices(int *count, uam_device_info_s **device_list);
146 int _uam_core_get_user_devices(const char *account,
147 int *count, uam_device_info_s **device_list);
149 int _uam_core_is_device_added(uam_device_info_s *dev, gboolean *is_added);
151 int _uam_core_get_available_sensors(unsigned int *sensor_bitmask);
153 gboolean _uam_core_is_sensor_ready(unsigned int sensor);
155 int _uam_core_set_detection_threshold(unsigned int sensor,
156 int presence_threshold, int absence_threshold);
158 int _uam_core_start_presence_detection(const char *svc_name, char *sender,
159 unsigned int sensors);
161 int _uam_core_stop_presence_detection(const char *svc_name, char *sender,
162 unsigned int sensors);
164 int _uam_core_start_absence_detection(const char *svc_name, char *sender,
165 unsigned int sensors);
167 int _uam_core_stop_absence_detection(const char *svc_name, char *sender,
168 unsigned int sensors);
170 int _uam_core_set_low_power_mode(unsigned int bit_mask, gboolean mode);
172 int _uam_core_get_detection_window(unsigned int *window);
174 int _uam_core_set_detection_window(unsigned int window);
176 int _uam_core_init(void);
178 void _uam_core_deinit(void);
180 void _uam_core_handle_sensor_ready(unsigned int sensor, gboolean is_ready);
182 int _uam_core_handle_device_added(int status,
183 int user_id, const uam_device_info_s *dev_info);
185 int _uam_core_handle_presence_detected(unsigned int sensor,
186 int user_id, void *sensor_info);
188 void _uam_core_handle_absence_detected(unsigned int sensor,
189 int user_id, void *sensor_info);
191 void _uam_core_cleanup_monitor(char *name);
193 void _uam_core_reset_database(void);
195 unsigned int _uam_core_get_active_sensors(int detection_mode);
197 void _uam_core_handle_detection_started(unsigned int sensor);
199 void _uam_core_handle_detection_stopped(unsigned int sensor);
201 int _uam_core_start_active_device_scan(char *sender, unsigned int sensors,
202 int detection_period);
204 int _uam_core_stop_active_device_scan(char *sender, unsigned int sensors);
206 void _uam_core_handle_active_device(uam_active_scan_event_e event,
207 unsigned int sensor, const uam_device_info_s *dev_info);
209 int _uam_core_get_default_service(uam_service_info_s *service_info);
211 int _uam_core_register_service(uam_service_info_s *svc);
213 int _uam_core_update_service(uam_service_info_s *svc);
215 int _uam_core_unregister_service(const char *svc_name);
217 int _uam_core_get_service_devices(const char *svc_name, int *count,
218 uam_device_info_s **device_list);
220 int _uam_core_get_service_users(const char *svc_name, int *count,
221 uam_user_info_s **user_list);
223 int _uam_core_get_services(int *count, uam_service_info_s **service_list);
225 int _uam_core_service_add_user(const char *service_name, const char *account);
227 int _uam_core_service_remove_user(const char *service, const char *account);
229 int _uam_core_service_add_device(const char *service_name,
230 const char *device_id, int tech_type);
232 int _uam_core_service_remove_device(const char *service_name,
233 const char *device_id, int tech_type);
235 int _uam_core_service_set_device_discriminant(const char *service_name,
236 const char *device_id, int tech_type, gboolean discriminant);
238 int _uam_core_service_get_device_discriminant(const char *service_name,
239 const char *device_id, int tech_type, gboolean *discriminant);
241 int _uam_core_service_get_device_last_seen(const char *svc_name,
242 const char *device_id, int tech_type, unsigned long long *last_seen);
244 int _uam_core_set_service_detection_cycle(const char *svc_name,
247 int _uam_core_get_service_detection_cycle(const char *svc_name,
248 unsigned int *cycle);
250 int _uam_core_update_device(const uam_device_info_s *a_device);
252 int _uam_core_add_ibeacon_adv(unsigned int adv_len, const char *iadv);
254 void _uam_core_handle_status_changed(unsigned int sensor, void *info);
256 int _uam_core_add_payload(uam_ble_payload_s *payload, const char *device_id,
262 #endif /* __UAM_MANAGER_CORE_H__ */