| b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame] | 1 | #ifndef __CHL_AGT__ |
| 2 | #define __CHL_AGT__ |
| 3 | |
| 4 | #include "chl_agent_ubus.h" |
| 5 | #include "chl_agent_uci.h" |
| 6 | #include <chl.h> |
| 7 | |
| 8 | #define _FILE_ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) |
| 9 | |
| 10 | |
| 11 | enum AGT_LOG_LEVEL { |
| 12 | AGT_LOG_LEVEL_ERR, |
| 13 | AGT_LOG_LEVEL_WARN, |
| 14 | AGT_LOG_LEVEL_INFO, |
| 15 | AGT_LOG_LEVEL_DBG, |
| 16 | }; |
| 17 | |
| 18 | void print_console(enum AGT_LOG_LEVEL level, const char *fmt, ...); |
| 19 | |
| 20 | #ifdef AGT_USE_LOGCAT |
| 21 | #define AGT_PRINTF(f_, ...) RDBGMSG("%s:%d " f_, _FILE_ , \ |
| 22 | __LINE__, ##__VA_ARGS__) |
| 23 | #define AGT_DBG(f_, ...) RDBGMSG("%s:%d " f_, _FILE_ , __LINE__, ##__VA_ARGS__) |
| 24 | #define AGT_INFO(f_, ...) RINFOMSG("%s:%d " f_, _FILE_ , __LINE__, ##__VA_ARGS__) |
| 25 | #define AGT_WARN(f_, ...) RWARNMSG("%s:%d " f_, _FILE_ , __LINE__, ##__VA_ARGS__) |
| 26 | #define AGT_ERR(f_, ...) RERRMSG("%s:%d " f_, _FILE_ , __LINE__, ##__VA_ARGS__) |
| 27 | #else |
| 28 | |
| 29 | #define AGT_PRINTF(level, f_, ...) print_console(level,"%s:%d " f_, _FILE_ , __LINE__, ##__VA_ARGS__) |
| 30 | #define AGT_DBG(f_, ...) AGT_PRINTF(AGT_LOG_LEVEL_DBG, f_, ##__VA_ARGS__) |
| 31 | #define AGT_INFO(f_, ...) AGT_PRINTF(AGT_LOG_LEVEL_INFO, f_, ##__VA_ARGS__) |
| 32 | #define AGT_WARN(f_, ...) AGT_PRINTF(AGT_LOG_LEVEL_WARN, "WARNING: " f_, ##__VA_ARGS__) |
| 33 | #define AGT_ERR(f_, ...) AGT_PRINTF(AGT_LOG_LEVEL_ERR, "ERROR: " f_, ##__VA_ARGS__) |
| 34 | #endif |
| 35 | |
| 36 | #define max(a,b) \ |
| 37 | ({ __typeof__ (a) _a = (a); \ |
| 38 | __typeof__ (b) _b = (b); \ |
| 39 | _a > _b ? _a : _b; }) |
| 40 | |
| 41 | #define CMD_LEN 60 |
| 42 | |
| 43 | static inline char *pdp_action_to_str(enum pdp_action action) |
| 44 | { |
| 45 | switch(action) { |
| 46 | case ERR_VAL: |
| 47 | return "ERR_VAL"; |
| 48 | case DO_NOTHING: |
| 49 | return "DO_NOTHING"; |
| 50 | case CLOSE_PDP: |
| 51 | return "CLOSE_PDP"; |
| 52 | case OPEN_PDP: |
| 53 | return "OPEN_PDP"; |
| 54 | case CHECK_ROUTE: |
| 55 | return "CHECK_ROUTE"; |
| 56 | case CLOSE_OPEN_PDP: |
| 57 | return "CLOSE_OPEN_PDP"; |
| 58 | default: |
| 59 | return "Unknown"; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | int is_wifi_ld(); |
| 64 | int is_data_enabled(); |
| 65 | void print_configuration( struct agent_conf *conf); |
| 66 | void add_del_portforwarding( bool add , bool old_state, char *host_ip ); |
| 67 | void checkroute_pdps(struct agent_conf *new_conf); |
| 68 | void copy_pdps(struct agent_conf *new_conf); |
| 69 | void open_pdps(struct agent_conf *new_conf); |
| 70 | void close_pdps(); |
| 71 | void stop_agent(); |
| 72 | void ind_handler(int pdp_id, enum chl_nw_status nw_status); |
| 73 | void add_del_pdp_routes( struct agent_pdp *pdp, bool add); |
| 74 | int update_configuration(); |
| 75 | void update_routes(struct agent_pdp *new_pdp, |
| 76 | struct agent_pdp *cur_pdp); |
| 77 | enum pdp_action compare_pdp(struct agent_conf *new_conf,int i); |
| 78 | |
| 79 | int check_delta(struct agent_pdp *new_p, |
| 80 | struct agent_pdp *cur_p); |
| 81 | |
| 82 | #endif |