2 * Copyright (c) 2011 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 __RD_NETWORK_H__
19 #define __RD_NETWORK_H__
21 #include <sys/types.h>
28 * @brief Enumeration for return type
31 NETWORK_ERROR_NONMONITOR = -9, /** < Process don't show watchdog popup */
32 NETWORK_ERROR_NOTIMPL = -7, /**< Not implemented yet error */
33 NETWORK_ERROR_UNINITIALIZED = -6, /**< Cgroup doen't mounted or daemon not started */
34 NETWORK_ERROR_NO_DATA = -5, /**< Success, but no data */
35 NETWORK_ERROR_INVALID_PARAMETER = -4,/**< Invalid parameter */
36 NETWORK_ERROR_OUT_OF_MEMORY = -3, /**< Out of memory */
37 NETWORK_ERROR_DB_FAILED = -2, /**< Database error */
38 NETWORK_ERROR_FAIL = -1, /**< General error */
39 NETWORK_ERROR_NONE = 0 /**< General success */
44 * @brief Enumeration for return type of the callback
47 NETWORK_CANCEL = 0, /**< cancel */
48 NETWORK_CONTINUE = 1, /**< continue */
52 * @brief Enumeration for the monitored process state
55 NETWORK_STATE_UNKNOWN = 0,
56 NETWORK_STATE_FOREGROUND = 1 << 1, /** < foreground state */
57 NETWORK_STATE_BACKGROUND = 1 << 2, /** < background state */
58 NETWORK_STATE_LAST_ELEM = 1 << 3
62 * @brief Enumeration for network restriction state
65 NETWORK_RESTRICTION_UNDEFINDED,
66 NETWORK_RESTRICTION_ACTIVATED, /** < restriction activated - means it
68 NETWORK_RESTRICTION_EXCLUDED, /** < restriction has been excluded -
69 means it was sent to kernel as
71 NETWORK_RESTRICTION_REMOVED, /** < restriction has been removed */
73 NETWORK_RESTRICTION_MAX_VALUE
74 } network_restriction_state;
77 * @brief Enumeration for network interface types
80 NETWORK_IFACE_UNKNOWN, /**< undefined iface */
81 NETWORK_IFACE_DATACALL, /**< mobile data */
82 NETWORK_IFACE_WIFI, /**< wifi data */
83 NETWORK_IFACE_WIRED, /**< wired interface */
84 NETWORK_IFACE_BLUETOOTH, /**< bluetooth interface */
85 NETWORK_IFACE_ALL, /**< enumerate all network interface types */
86 NETWORK_IFACE_LAST_ELEM
90 * @brief Structure for time interval
91 * @details It's time interval. Zero interval since 0 til 0 means entires interval.
96 } network_tm_interval_s;
99 * @brief Enumeration for network connection period type
100 * @details Last received/sent mean counting data from the first connection of each interface
103 NETWORK_CON_PERIOD_UNKNOWN, /**< Undefined period */
104 NETWORK_CON_PERIOD_LAST_RECEIVED_DATA, /**< Last received data */
105 NETWORK_CON_PERIOD_LAST_SENT_DATA, /**< Last sent data */
106 NETWORK_CON_PERIOD_TOTAL_RECEIVED_DATA, /**< Total received data */
107 NETWORK_CON_PERIOD_TOTAL_SENT_DATA, /**< Total sent data */
108 NETWORK_CON_PERIOD_LAST_ELEM
109 } network_connection_period_e;
112 * @brief Enumeration for network roaming type
115 NETWORK_ROAMING_UNKNOWN, /**< can't define roaming - roaming unknown */
116 NETWORK_ROAMING_ENABLE, /**< in roaming */
117 NETWORK_ROAMING_DISABLE, /**< not in roaming */
118 NETWORK_ROAMING_LAST_ELEM,
122 * @brief Enumeration for hardware network protocol types
125 NETWORK_PROTOCOL_NONE, /**< Network unknown */
126 NETWORK_PROTOCOL_DATACALL_NOSVC, /**< Network no service */
127 NETWORK_PROTOCOL_DATACALL_EMERGENCY, /**< Network emergency */
128 NETWORK_PROTOCOL_DATACALL_SEARCH, /**< Network search 1900 */
129 NETWORK_PROTOCOL_DATACALL_2G, /**< Network 2G */
130 NETWORK_PROTOCOL_DATACALL_2_5G, /**< Network 2.5G */
131 NETWORK_PROTOCOL_DATACALL_2_5G_EDGE, /**< Network EDGE */
132 NETWORK_PROTOCOL_DATACALL_3G, /**< Network UMTS */
133 NETWORK_PROTOCOL_DATACALL_HSDPA, /**< Network HSDPA */
134 NETWORK_PROTOCOL_DATACALL_LTE, /**< Network LTE */
135 NETWORK_PROTOCOL_MAX_ELEM
136 } network_hw_net_protocol_e;
139 * @brief Enumeration for the boolean option
140 * @details Description of the boolean option for enabling/disabling
141 * network interfaces and enabling/disabling some behaviar
144 NETWORK_OPTION_UNDEF,
145 NETWORK_OPTION_ENABLE,
146 NETWORK_OPTION_DISABLE
150 * @brief Structure for network option
151 * @details Set of the options.
152 * version - contains structure version
153 * wifi - enable/disable wifi, NETWORK_OPTION_UNDEF to leave option as is
154 * datacall - enable/disable datacall, NETWORK_OPTION_UNDEF to leave option as is
155 * network_timer - set period of the updating data from the kernel,
156 * 0 to leave option as is
157 * datacall_logging - enable/disable datacall_logging,
158 * NETWORK_OPTION_UNDEF to leave option as is
161 unsigned char version;
162 network_option_e wifi;
163 network_option_e datacall;
164 time_t network_timer;
165 network_option_e datacall_logging;
169 * @brief Set options, daemon will handle option setting.
170 * @param[in] options The network state option
172 * @return 0 on success, otherwise a negative error value
173 * @retval #NETWORK_ERROR_NONE Successful
174 * @retval #NETWORK_ERROR_FAIL General error
175 * @retval #NETWORK_ERROR_DB_FAILED Database error
176 * @retval #NETWORK_ERROR_OUT_OF_MEMORY Out of memory
177 * @retval #NETWORK_ERROR_INVALID_PARAMETER Invalid parameter
178 * @retval #NETWORK_ERROR_NO_DATA Success, but no data
179 * @retval #NETWORK_ERROR_UNINITIALIZED Cgroup doesn't mounted or daemon is not started
180 * @retval #NETWORK_ERROR_NOTIMPL No implemented yet error
181 * @retval #NETWORK_ERROR_NONMONITOR Process don't show watchdog popup
183 * @see #network_option_s
184 * @see #network_get_option
186 network_error_e network_set_option(const network_option_s *options);
189 * @brief Get performance control options.
190 * @param[out] options The network state option
192 * @return 0 on success, otherwise a negative error value
193 * @retval #NETWORK_ERROR_NONE Successful
194 * @retval #NETWORK_ERROR_FAIL General error
195 * @retval #NETWORK_ERROR_DB_FAILED Database error
196 * @retval #NETWORK_ERROR_OUT_OF_MEMORY Out of memory
197 * @retval #NETWORK_ERROR_INVALID_PARAMETER Invalid parameter
198 * @retval #NETWORK_ERROR_NO_DATA Success, but no data
199 * @retval #NETWORK_ERROR_UNINITIALIZED Cgroup doesn't mounted or daemon is not started
200 * @retval #NETWORK_ERROR_NOTIMPL No implemented yet error
201 * @retval #NETWORK_ERROR_NONMONITOR Process don't show watchdog popup
203 * @see #network_option_s
204 * @see #network_set_option
206 network_error_e network_get_option(network_option_s *options);
209 * @brief Make cgroup and put in it the given pid and generated classid
210 * @details If cgroup already exists function just put pid in it.
211 * @param[in] pid Process, that will be added to cgroup pkg name
212 * @param[in] pkg_name Package name
214 * @return 0 on success, otherwise a negative error value
215 * @retval #NETWORK_ERROR_NONE Successful
216 * @retval #NETWORK_ERROR_FAIL General error
217 * @retval #NETWORK_ERROR_DB_FAILED Database error
218 * @retval #NETWORK_ERROR_OUT_OF_MEMORY Out of memory
219 * @retval #NETWORK_ERROR_INVALID_PARAMETER Invalid parameter
220 * @retval #NETWORK_ERROR_NO_DATA Success, but no data
221 * @retval #NETWORK_ERROR_UNINITIALIZED Cgroup doesn't mounted or daemon is not started
222 * @retval #NETWORK_ERROR_NOTIMPL No implemented yet error
223 * @retval #NETWORK_ERROR_NONMONITOR Process don't show watchdog popup
225 * @see #network_get_classid_by_pkg_name
227 network_error_e network_make_cgroup_with_pid(const int pid,
228 const char *pkg_name);
231 * @brief Get classid from cgroup with name pkg_name
232 * @param[in] pkg_name Name of the cgroup
233 * @param[in] create In case of true - create cgroup if it's not exists
234 * @return a positive value is classid, otherwise a negative error value
235 * @retval #NETWORK_ERROR_NONE Successful
236 * @retval #NETWORK_ERROR_FAIL General error
237 * @retval #NETWORK_ERROR_DB_FAILED Database error
238 * @retval #NETWORK_ERROR_OUT_OF_MEMORY Out of memory
239 * @retval #NETWORK_ERROR_INVALID_PARAMETER Invalid parameter
240 * @retval #NETWORK_ERROR_NO_DATA Success, but no data
241 * @retval #NETWORK_ERROR_UNINITIALIZED Cgroup doesn't mounted or daemon is not started
242 * @retval #NETWORK_ERROR_NOTIMPL No implemented yet error
243 * @retval #NETWORK_ERROR_NONMONITOR Process don't show watchdog popup
245 * @see #network_make_cgroup_with_pid
247 u_int32_t network_get_classid_by_pkg_name(const char *pkg_name, int create);
250 * @brief Structure for network restriction information
252 * rs_type: foreground or background process
253 * iftype - interface type to apply restriction
254 * send_limit - amount number of engress bytes allowed for restriction
255 * rcv_limit - amount number of ingress bytes allowed for restriction
256 * old behaviour for send_limit & rcv_limit was 0
257 * snd_warning_limit - threshold for warning notification on engress bytes
258 * rcv_warning_limit - threshold for warning notification on ingress bytes
259 * value - WARNING_THRESHOLD_UNDEF means no threshold
260 * this limit is different from quota warning threshold,
261 * threshold means remaining, limit means occupaied
264 network_state_e rs_type;
265 network_iface_e iftype;
268 int snd_warning_limit;
269 int rcv_warning_limit;
270 } network_restriction_s;
273 * @brief Enumeration for restriction counter
281 * @brief Enumeration for holding data usage information
284 network_counter_s cnt;
285 network_restriction_s rst;
286 } network_common_info;
289 * @brief Set restriction information
290 * @details Set and apply restriction for application.
291 * It will create new restriction or modify existing.
292 * @param[in] app_id Application identifier, it's package name now
293 * @param[in] restriction Restriction to apply for application in foreground mode
294 * At least one of the restriction should be setted.
296 * @return 0 on success, otherwise a negative error value
297 * @retval #NETWORK_ERROR_NONE Successful
298 * @retval #NETWORK_ERROR_FAIL General error
299 * @retval #NETWORK_ERROR_DB_FAILED Database error
300 * @retval #NETWORK_ERROR_OUT_OF_MEMORY Out of memory
301 * @retval #NETWORK_ERROR_INVALID_PARAMETER Invalid parameter
302 * @retval #NETWORK_ERROR_NO_DATA Success, but no data
303 * @retval #NETWORK_ERROR_UNINITIALIZED Cgroup doesn't mounted or daemon is not started
304 * @retval #NETWORK_ERROR_NOTIMPL No implemented yet error
305 * @retval #NETWORK_ERROR_NONMONITOR Process don't show watchdog popup
307 * @see #network_restriction_s
308 * @see #network_remove_restriction
309 * @see #network_remove_restriction_by_iftype
311 network_error_e network_set_restriction(const char *app_id,
312 const network_restriction_s *restriction);
315 * @brief Structure for information on restrictions.
317 * app_id - application identification - copy it if you in
318 * callback function, don't store raw pointer on it
319 * iftype - type of network interface
323 network_iface_e iftype;
324 network_restriction_state rst_state;
327 } network_restriction_info_s;
330 * @brief callback for processing information of restrictions
332 typedef network_cb_ret_e(*network_restriction_cb)(
333 const network_restriction_info_s *info, void *user_data);
336 * @brief Restrictions enumerate function
337 * @param[in] restriction_db The callback is called for each application that restrcited now
338 * @param[in] user_data User data will be passed to the callback function
340 * @return 0 on success, otherwise a negative error value
341 * @retval #NETWORK_ERROR_NONE Successful
342 * @retval #NETWORK_ERROR_FAIL General error
343 * @retval #NETWORK_ERROR_DB_FAILED Database error
344 * @retval #NETWORK_ERROR_OUT_OF_MEMORY Out of memory
345 * @retval #NETWORK_ERROR_INVALID_PARAMETER Invalid parameter
346 * @retval #NETWORK_ERROR_NO_DATA Success, but no data
347 * @retval #NETWORK_ERROR_UNINITIALIZED Cgroup doesn't mounted or daemon is not started
348 * @retval #NETWORK_ERROR_NOTIMPL No implemented yet error
349 * @retval #NETWORK_ERROR_NONMONITOR Process don't show watchdog popup
351 * @see #network_restriction_cb
353 network_error_e network_restriction_foreach(network_restriction_cb restriction_cb,
357 * @brief Remove existing restriction for application
358 * @details Remove existing restriction for application
359 * It will delete restriction rule in kernel
360 * @param[in] app_id Application identifier, it's package name
362 * @return 0 on success, otherwise a negative error value
363 * @retval #NETWORK_ERROR_NONE Successful
364 * @retval #NETWORK_ERROR_FAIL General error
365 * @retval #NETWORK_ERROR_DB_FAILED Database error
366 * @retval #NETWORK_ERROR_OUT_OF_MEMORY Out of memory
367 * @retval #NETWORK_ERROR_INVALID_PARAMETER Invalid parameter
368 * @retval #NETWORK_ERROR_NO_DATA Success, but no data
369 * @retval #NETWORK_ERROR_UNINITIALIZED Cgroup doesn't mounted or daemon is not started
370 * @retval #NETWORK_ERROR_NOTIMPL No implemented yet error
371 * @retval #NETWORK_ERROR_NONMONITOR Process don't show watchdog popup
373 * @see #network_set_restriction
374 * @see #network_remove_restriction_by_iftype
376 network_error_e network_remove_restriction(const char *app_id);
379 * @brief Remove existing restriction for application from interface type
380 * @details Remove existing restriction for application
381 * It will delete restriction rule in kernel
382 * @param[in] app_id Application identifier, it's package name
383 * @param[in] iftype Interface type
385 * @return 0 on success, otherwise a negative error value
386 * @retval #NETWORK_ERROR_NONE Successful
387 * @retval #NETWORK_ERROR_FAIL General error
388 * @retval #NETWORK_ERROR_DB_FAILED Database error
389 * @retval #NETWORK_ERROR_OUT_OF_MEMORY Out of memory
390 * @retval #NETWORK_ERROR_INVALID_PARAMETER Invalid parameter
391 * @retval #NETWORK_ERROR_NO_DATA Success, but no data
392 * @retval #NETWORK_ERROR_UNINITIALIZED Cgroup doesn't mounted or daemon is not started
393 * @retval #NETWORK_ERROR_NOTIMPL No implemented yet error
394 * @retval #NETWORK_ERROR_NONMONITOR Process don't show watchdog popup
396 * @see #network_iface_e
397 * @see #network_set_restriction
398 * @see #network_remove_restriction_by_iftype
400 network_error_e network_remove_restriction_by_iftype(const char *app_id,
401 const network_iface_e iftype);
404 * @brief Exclude restriction for application
405 * @details Exclude restriction for application
406 * It will exclude restriction rule in kernel
407 * @param[in] app_id Application identifier, it's package name
409 * @return 0 on success, otherwise a negative error value
410 * @retval #NETWORK_ERROR_OK Successful
411 * @retval #NETWORK_ERROR_FAIL General error
412 * @retval #NETWORK_ERROR_DB_FAILED Database error
413 * @retval #NETWORK_ERROR_OUT_OF_MEMORY Out of memory
414 * @retval #NETWORK_ERROR_INVALID_PARAMETER Invalid parameter
415 * @retval #NETWORK_ERROR_NO_DATA Success, but no data
416 * @retval #NETWORK_ERROR_UNINITIALIZED Cgroup doesn't mounted or daemon is not started
417 * @retval #NETWORK_ERROR_NOTIMPL No implemented yet error
418 * @retval #NETWORK_ERROR_NONMONITOR Process don't show watchdog popup
420 * @see #network_set_restriction
421 * @see #network_exclude_restriction_by_iftype
423 network_error_e network_exclude_restriction(const char *app_id);
426 * @brief Exclude restriction for application from interface type
427 * @details Exclude restriction for application
428 * It will exclude restriction rule in kernel
429 * @param[in] app_id Application identifier, it's package name
430 * @param[in] iftype Interface type
432 * @return 0 on success, otherwise a negative error value
433 * @retval #NETWORK_ERROR_OK Successful
434 * @retval #NETWORK_ERROR_FAIL General error
435 * @retval #NETWORK_ERROR_DB_FAILED Database error
436 * @retval #NETWORK_ERROR_OUT_OF_MEMORY Out of memory
437 * @retval #NETWORK_ERROR_INVALID_PARAMETER Invalid parameter
438 * @retval #NETWORK_ERROR_NO_DATA Success, but no data
439 * @retval #NETWORK_ERROR_UNINITIALIZED Cgroup doesn't mounted or daemon is not started
440 * @retval #NETWORK_ERROR_NOTIMPL No implemented yet error
441 * @retval #NETWORK_ERROR_NONMONITOR Process don't show watchdog popup
443 * @see #network_iface_e
444 * @see #network_set_restriction
445 * @see #network_exclude_restriction_by_iftype
447 network_error_e network_exclude_restriction_by_iftype(
448 const char *app_id, const network_iface_e iftype);
451 * @brief Structure for network activity information
454 int type; /*<< ingress/egress */
458 } network_activity_info_s;
461 * @brief callback for network activity information of packet
463 typedef network_cb_ret_e(*network_activity_cb)(network_activity_info_s *info);
466 * @brief Register activity callback
467 * @details This function registering callback which invokes per every packet.
468 * Function creates new reading thread and returns.
469 * @param[in] activity_cb Invoked per every packet with NET_ACTIVITY channel
471 * @return 0 on success, otherwise a negative error value
472 * @retval #NETWORK_ERROR_NONE Successful
473 * @retval #NETWORK_ERROR_FAIL General error
474 * @retval #NETWORK_ERROR_DB_FAILED Database error
475 * @retval #NETWORK_ERROR_OUT_OF_MEMORY Out of memory
476 * @retval #NETWORK_ERROR_INVALID_PARAMETER Invalid parameter
477 * @retval #NETWORK_ERROR_NO_DATA Success, but no data
478 * @retval #NETWORK_ERROR_UNINITIALIZED Cgroup doesn't mounted or daemon is not started
479 * @retval #NETWORK_ERROR_NOTIMPL No implemented yet error
480 * @retval #NETWORK_ERROR_NONMONITOR Process don't show watchdog popup
482 * @see #network_activity_cb
484 network_error_e network_register_activity_cb(network_activity_cb activity_cb);
487 * @brief After invoking this function, application will be in the monitored scope
488 * @details It creates an appropriate cgroup,
489 * it generates classid for the network performance control.
490 * It creates a unit file for the systemd.
491 * @param[in] app_id Application identifier, it's package name now
492 * @param[in] pid Pid to put in to cgroup, or self pid of 0
494 * @return 0 on success, otherwise a negative error value
495 * @retval #NETWORK_ERROR_NONE Successful
496 * @retval #NETWORK_ERROR_FAIL General error
497 * @retval #NETWORK_ERROR_DB_FAILED Database error
498 * @retval #NETWORK_ERROR_OUT_OF_MEMORY Out of memory
499 * @retval #NETWORK_ERROR_INVALID_PARAMETER Invalid parameter
500 * @retval #NETWORK_ERROR_NO_DATA Success, but no data
501 * @retval #NETWORK_ERROR_UNINITIALIZED Cgroup doesn't mounted or daemon is not started
502 * @retval #NETWORK_ERROR_NOTIMPL No implemented yet error
503 * @retval #NETWORK_ERROR_NONMONITOR Process don't show watchdog popup
505 network_error_e network_join_app_performance(const char *app_id, const pid_t pid);
508 * @brief Update the resourced counters and stores it in the database.
509 * @details Updates going asynchronyusly, it mean client can't be sure was
510 * counters updated or not after this function finished.
511 * To handle finish of the update process client need to
512 * regist callback function
513 * @see network_register_update_cb.
514 * Next counters updating will procced according to resourced
515 * update period, unless another network_update_statisitcs is
518 * @return 0 on success, otherwise a negative error value
519 * @retval #NETWORK_ERROR_NONE Successful
520 * @retval #NETWORK_ERROR_FAIL General error
521 * @retval #NETWORK_ERROR_DB_FAILED Database error
522 * @retval #NETWORK_ERROR_OUT_OF_MEMORY Out of memory
523 * @retval #NETWORK_ERROR_INVALID_PARAMETER Invalid parameter
524 * @retval #NETWORK_ERROR_NO_DATA Success, but no data
525 * @retval #NETWORK_ERROR_UNINITIALIZED Cgroup doesn't mounted or daemon is not started
526 * @retval #NETWORK_ERROR_NOTIMPL No implemented yet error
527 * @retval #NETWORK_ERROR_NONMONITOR Process don't show watchdog popup
529 network_error_e network_update_statistics(void);
532 * @brief Counters update information
533 * @details This structure is needed to prevent client API from modification
534 * in case of any information about update will be required.
536 struct network_update_info {
541 * @brief Callback for update counters
543 typedef network_cb_ret_e(*network_update_cb)(
544 const struct network_update_info *info,
548 * @brief Register callback for update counters.
549 * @details Callback function will be called if
550 * network_update_statistics is requested.
551 * To stop callbacks invocation return NETWORK_CANCEL from
552 * callback function or call @see network_unregister_update_cb.
554 * @param[in] user_data pointer to any data given to callback function.
555 * Memory area should not be released until callback is unregistered.
557 * @return 0 on success, otherwise a negative error value
558 * @retval #NETWORK_ERROR_NONE Successful
559 * @retval #NETWORK_ERROR_FAIL General error
560 * @retval #NETWORK_ERROR_DB_FAILED Database error
561 * @retval #NETWORK_ERROR_OUT_OF_MEMORY Out of memory
562 * @retval #NETWORK_ERROR_INVALID_PARAMETER Invalid parameter
563 * @retval #NETWORK_ERROR_NO_DATA Success, but no data
564 * @retval #NETWORK_ERROR_UNINITIALIZED Cgroup doesn't mounted or daemon is not started
565 * @retval #NETWORK_ERROR_NOTIMPL No implemented yet error
566 * @retval #NETWORK_ERROR_NONMONITOR Process don't show watchdog popup
574 #include <rd-network.h>
576 network_cb_ret_e network_update(const struct network_update_info *info,
580 char *str_data = user_data;
581 printf("Callback updated. Stop yes/no?: ");
583 if (strcmp(buf, "yes") == 0)
584 return NETWORK_CANCEL;
586 printf("user data is %s\n", user_data);
588 return NETWORK_CONTINUE;
597 char *user_data = (char *)malloc(1024);
599 strncpy(user_data, "hello", 1023);
601 ret = network_register_update_cb(network_update, (void *)user_data);
603 network_update_statistics();
605 ecore_main_loop_begin();
613 network_error_e network_register_update_cb(network_update_cb update_cb,
617 * @brief Unregister update callback.
619 * @return 0 on success, otherwise a negative error value
620 * @retval #NETWORK_ERROR_NONE Successful
621 * @retval #NETWORK_ERROR_FAIL General error
622 * @retval #NETWORK_ERROR_DB_FAILED Database error
623 * @retval #NETWORK_ERROR_OUT_OF_MEMORY Out of memory
624 * @retval #NETWORK_ERROR_INVALID_PARAMETER Invalid parameter
625 * @retval #NETWORK_ERROR_NO_DATA Success, but no data
626 * @retval #NETWORK_ERROR_UNINITIALIZED Cgroup doesn't mounted or daemon is not started
627 * @retval #NETWORK_ERROR_NOTIMPL No implemented yet error
628 * @retval #NETWORK_ERROR_NONMONITOR Process don't show watchdog popup
630 void network_unregister_update_cb(void);
633 * @brief Structure for selection rule applied
636 unsigned char version;
639 network_iface_e iftype;
641 } network_selection_rule_s;
644 * @brief Bundle structure for bringing all together application identification and properties
646 * app_id - application identification - copy it if you in
647 * callback function, don't store raw pointer on it
648 * iface - interface name, NULL means all interfaces,
649 * don't store raw pointer on it in the callback function, copy it by value
650 * interval - time interval for given result, NULL means entire interval
651 * foreground - foreground restrictions and counters
652 * background - background restrictions and counters
656 network_iface_e iftype;
657 network_tm_interval_s *interval;
658 network_common_info foreground;
659 network_common_info background;
660 network_roaming_e roaming;
661 network_hw_net_protocol_e hw_net_protocol_type;
665 * @brief Callback for enumerate counters and restrictions
667 typedef network_cb_ret_e(*network_info_cb) (const network_info_s *info,
671 * @brief Data usage enumerate function
672 * @details The callback is called for each application that used network
673 * in between timestamps specified.
674 * If interface name is not specified, each application will only appear
675 * once with the total traffic used over all interfaces.
676 * @param[in] rule Selection rule
677 * @param[in] info_cb The callback is called for each application
678 * that used network in between timestamps specified
679 * @param[in] user_data User data will be passed to the callback function
681 * @return 0 on success, otherwise a negative error value
682 * @retval #NETWORK_ERROR_NONE Successful
683 * @retval #NETWORK_ERROR_FAIL General error
684 * @retval #NETWORK_ERROR_DB_FAILED Database error
685 * @retval #NETWORK_ERROR_OUT_OF_MEMORY Out of memory
686 * @retval #NETWORK_ERROR_INVALID_PARAMETER Invalid parameter
687 * @retval #NETWORK_ERROR_NO_DATA Success, but no data
688 * @retval #NETWORK_ERROR_UNINITIALIZED Cgroup doesn't mounted or daemon is not started
689 * @retval #NETWORK_ERROR_NOTIMPL No implemented yet error
690 * @retval #NETWORK_ERROR_NONMONITOR Process don't show watchdog popup
692 * @see #network_selection_rule_s
693 * @see #network_info_cb
694 * @see #network_details_foreach
696 network_error_e network_foreach(const network_selection_rule_s *rule,
697 network_info_cb info_cb, void *user_data);
700 * @brief Data usage details enumerate function
702 * If interface name is specified in rule, the callback will be called
703 * exactly 1 time with the total traffic counts for that interface
704 * by specified application in the specified time interval.
705 * If interface name is not specified, the callback will be called once
706 * for each interface used by application during the specified interval.
707 * It could be 0 if the application did not use any network interfaces
708 * during that period.
709 * @param[in] app_id Application id
710 * @param[in] rule Selection rule
711 * @param[in] info_cb The callback is called for each application
712 * that used network in between timestamps specified
713 * @param[in] user_data User data will be passed to the callback function
715 * @return 0 on success, otherwise a negative error value
716 * @retval #NETWORK_ERROR_NONE Successful
717 * @retval #NETWORK_ERROR_FAIL General error
718 * @retval #NETWORK_ERROR_DB_FAILED Database error
719 * @retval #NETWORK_ERROR_OUT_OF_MEMORY Out of memory
720 * @retval #NETWORK_ERROR_INVALID_PARAMETER Invalid parameter
721 * @retval #NETWORK_ERROR_NO_DATA Success, but no data
722 * @retval #NETWORK_ERROR_UNINITIALIZED Cgroup doesn't mounted or daemon is not started
723 * @retval #NETWORK_ERROR_NOTIMPL No implemented yet error
724 * @retval #NETWORK_ERROR_NONMONITOR Process don't show watchdog popup
726 * @see #network_selection_rule_s
727 * @see #network_info_cb
728 * @s22 #network_foreach
730 network_error_e network_details_foreach(const char *app_id,
731 network_selection_rule_s *rule,
732 network_info_cb info_cb,
736 * @brief Structure for reset rule
737 * @details It's statistics erasing description.
738 * app_id - Erase statistics per appropriate app_id.
739 * app_id can be NULL in this case erasing all datas
740 * iftype - Erase statistics per appropriate network interface type
741 * #network_iface_e, if iftype is NETWORK_IFACE_LAST_ELEM - erase all
742 * NETWORK_IFACE_UNKNOW - means undetermined interface on moment of storing data.
743 * interval - It's time interval, @see network_tm_interval_s.
744 * It should be set. Zero interval since 0 till 0 means entire interval.
745 * connection_state - It's mask on time interval.
746 * Possible variation LAST and TOTAL for send and received data.
749 unsigned char version;
751 network_iface_e iftype;
752 network_tm_interval_s *interval;
753 network_connection_period_e connection_state;
754 } network_reset_rule_s;
757 * @brief Reset data usage information
758 * @param[in] rule Reset rule. It's statistics erasing description
760 * @return 0 on success, otherwise a negative error value
761 * @retval #NETWORK_ERROR_NONE Successful
762 * @retval #NETWORK_ERROR_FAIL General error
763 * @retval #NETWORK_ERROR_DB_FAILED Database error
764 * @retval #NETWORK_ERROR_OUT_OF_MEMORY Out of memory
765 * @retval #NETWORK_ERROR_INVALID_PARAMETER Invalid parameter
766 * @retval #NETWORK_ERROR_NO_DATA Success, but no data
767 * @retval #NETWORK_ERROR_UNINITIALIZED Cgroup doesn't mounted or daemon is not started
768 * @retval #NETWORK_ERROR_NOTIMPL No implemented yet error
769 * @retval #NETWORK_ERROR_NONMONITOR Process don't show watchdog popup
771 * @see #network_reset_rule_s
773 network_error_e network_reset(const network_reset_rule_s *rule);
776 * @brief Reset filter for quota
778 * app_id is mandatory field
779 * iftype interface type, NETWORK_IFACE_UNKNOWN
780 * interface is not valid parameter, use NETWORK_IFACE_ALL instead
781 * roaming_type roaming type
782 * If user will not specify last 2 fields (UNKNOWN by default),
783 * neither quota with defined interface nor
784 * quota with defined roaming state will be removed.
788 network_iface_e iftype;
789 network_roaming_e roaming;
790 } network_quota_reset_rule_s;
793 * @brief Remove datausage quota by quota rule
794 * @param[in] rule reset filter for quota
796 * @return 0 on success, otherwise a negative error value
797 * @retval #NETWORK_ERROR_NONE Successful
798 * @retval #NETWORK_ERROR_FAIL General error
799 * @retval #NETWORK_ERROR_DB_FAILED Database error
800 * @retval #NETWORK_ERROR_OUT_OF_MEMORY Out of memory
801 * @retval #NETWORK_ERROR_INVALID_PARAMETER Invalid parameter
802 * @retval #NETWORK_ERROR_NO_DATA Success, but no data
803 * @retval #NETWORK_ERROR_UNINITIALIZED Cgroup doesn't mounted or daemon is not started
804 * @retval #NETWORK_ERROR_NOTIMPL No implemented yet error
805 * @retval #NETWORK_ERROR_NONMONITOR Process don't show watchdog popup
807 * @see #network_quota_reset_rule_s
808 * @see #network_set_quota
809 * @see #network_remove_quota_by_iftype
811 network_error_e network_remove_quota(
812 const network_quota_reset_rule_s *rule);
815 * @brief Remove datausage quota by quota rule
816 * @param[in] app_id Application id
817 * @param[in] iftype Interface type
819 * @return 0 on success, otherwise a negative error value
820 * @retval #NETWORK_ERROR_NONE Successful
821 * @retval #NETWORK_ERROR_FAIL General error
822 * @retval #NETWORK_ERROR_DB_FAILED Database error
823 * @retval #NETWORK_ERROR_OUT_OF_MEMORY Out of memory
824 * @retval #NETWORK_ERROR_INVALID_PARAMETER Invalid parameter
825 * @retval #NETWORK_ERROR_NO_DATA Success, but no data
826 * @retval #NETWORK_ERROR_UNINITIALIZED Cgroup doesn't mounted or daemon is not started
827 * @retval #NETWORK_ERROR_NOTIMPL No implemented yet error
828 * @retval #NETWORK_ERROR_NONMONITOR Process don't show watchdog popup
830 * @see #network_quota_reset_rule_s
831 * @see #network_set_quota
832 * @see #network_remove_quota
834 network_error_e network_remove_quota_by_iftype(
835 const char *app_id, const network_iface_e iftype);
838 * @brief Datausage quota
840 * time_period - time interval for quota, use predefined quota
841 * #network_quota_s_period_t
842 * snd_quota - quota for outcoming data
843 * rcv_quota - quota for incoming data
844 * warning_send_threshold - threshold for warning notification on engress bytes
845 * warning_rcv_threshold - threshold for warning notification on ingress bytes
846 * value - WARNING_THRESHOLD_UNDEF means no threshold
847 * - WARNING_THRESHOLD_DEFAULT means system-resource will be
848 * responsible for evaluation threshold value
849 * The threshold value is amount of bytes remaining till blocking
850 * quota_type - at present it can be foreground quota or background
851 * iftype - network interface type
852 * start_time - quota processing activation time, if NULL current time is used
858 int snd_warning_threshold;
859 int rcv_warning_threshold;
860 network_state_e quota_type;
861 network_iface_e iftype;
863 network_roaming_e roaming_type;
867 * @brief Set datausage quota
868 * @details This function will set time interval based quota for data usage
869 * Restriction will be applied in case of exceeding of the quota
870 * during time interval
871 * @param app_id[in] Application identifier, it's package name
872 * @param quotas[in] Time interval based restriction for data usage
874 * @return 0 on success, otherwise a negative error value
875 * @retval #NETWORK_ERROR_NONE Successful
876 * @retval #NETWORK_ERROR_FAIL General error
877 * @retval #NETWORK_ERROR_DB_FAILED Database error
878 * @retval #NETWORK_ERROR_OUT_OF_MEMORY Out of memory
879 * @retval #NETWORK_ERROR_INVALID_PARAMETER Invalid parameter
880 * @retval #NETWORK_ERROR_NO_DATA Success, but no data
881 * @retval #NETWORK_ERROR_UNINITIALIZED Cgroup doesn't mounted or daemon is not started
882 * @retval #NETWORK_ERROR_NOTIMPL No implemented yet error
883 * @retval #NETWORK_ERROR_NONMONITOR Process don't show watchdog popup
885 * @see #network_set_quota
886 * @see #network_remove_quota
887 * @see #network_remove_quota_by_iftype
889 network_error_e network_set_quota(const char *app_id,
890 const network_quota_s *quota);
895 * This function get restriction state.
896 * State can be following:
897 * NETWORK_RESTRICTION_UNDEFINDED - means restriction wasn't set
898 * NETWORK_RESTRICTION_ACTIVATED - means restriction activated
899 * NETWORK_RESTRICTION_EXCLUDED - restriction has been excluded
902 * #include <rd-network.h>
904 * int is_whole_network_restricted()
906 * network_restriction_state state;
907 * network_error_r ret_code = network_get_restriction_state(
908 * RESOURCED_ALL_APP, NETWORK_IFACE_ALL, &state);
909 * if (ret_code != NETWORK_ERROR_NONE &&
910 * state == NETWORK_RESTRICTION_ACTIVATED)
917 * @retval #NETWORK_ERROR_OK Successful
918 * @retval #NETWORK_ERROR_FAIL General error
919 * @retval #NETWORK_ERROR_DB_FAILED Database error
920 * @retval #NETWORK_ERROR_INVALID_PARAMETER Invalid parameter
922 * @see #network_iface_e
923 * @see #network_restriction_state
924 * @see #network_set_restriction
925 * @see #network_exclude_restriction_by_iftype
928 network_error_e network_get_restriction_state(const char *pkg_id,
929 network_iface_e iftype, network_restriction_state *state);
936 #endif // __RD_NETWORK_H__