b.liu | 4e243dc | 2023-11-27 11:20:00 +0800 | [diff] [blame] | 1 | #ifndef __LYNQ_QSER_DATA_H__ |
| 2 | #define __LYNQ_QSER_DATA_H__ |
| 3 | #ifdef __cplusplus |
| 4 | extern "C" { |
| 5 | #endif |
| 6 | #include <stdbool.h> |
| 7 | #include <netinet/in.h> |
| 8 | |
| 9 | typedef enum { |
| 10 | QSER_DATA_CALL_ERROR_NONE = 0, |
| 11 | QSER_DATA_CALL_ERROR_INVALID_PARAMS, |
| 12 | } qser_data_call_error_e; |
| 13 | |
| 14 | typedef enum { |
| 15 | QSER_DATA_CALL_DISCONNECTED = 0, /*!< call is disconnected */ |
| 16 | QSER_DATA_CALL_CONNECTED, /*!< call is connected */ |
| 17 | } qser_data_call_state_e; |
| 18 | |
| 19 | typedef enum { |
| 20 | QSER_DATA_CALL_TYPE_IPV4 = 0, /*!< IPv4 call. */ |
| 21 | QSER_DATA_CALL_TYPE_IPV6, /*!< IPv6 call. */ |
| 22 | QSER_DATA_CALL_TYPE_IPV4V6, /*!< IPv4 and IPv6 call (Only used call start or stop). */ |
| 23 | } qser_data_call_ip_family_e; |
| 24 | |
| 25 | typedef enum { |
| 26 | QSER_APN_PDP_TYPE_IPV4 = 0, |
| 27 | QSER_APN_PDP_TYPE_PPP, |
| 28 | QSER_APN_PDP_TYPE_IPV6, |
| 29 | QSER_APN_PDP_TYPE_IPV4V6, |
| 30 | } qser_apn_pdp_type_e; |
| 31 | |
| 32 | typedef enum { |
| 33 | QSER_APN_AUTH_PROTO_DEFAULT = 0, |
| 34 | QSER_APN_AUTH_PROTO_NONE, |
| 35 | QSER_APN_AUTH_PROTO_PAP, |
| 36 | QSER_APN_AUTH_PROTO_CHAP, |
| 37 | QSER_APN_AUTH_PROTO_PAP_CHAP, |
| 38 | } qser_apn_auth_proto_e; |
| 39 | |
| 40 | #define QSER_APN_MAX_LIST 8 |
| 41 | #define QSER_APN_NAME_SIZE 150 |
| 42 | #define QSER_APN_USERNAME_SIZE 127 |
| 43 | #define QSER_APN_PASSWORD_SIZE 127 |
| 44 | |
| 45 | struct v4_address_status { |
| 46 | struct in_addr ip; /*!< Public IPv4 address. */ |
| 47 | struct in_addr gateway; /*!< Public IPv4 gateway. */ |
| 48 | struct in_addr pri_dns; /*!< Primary Domain Name Service IP address. */ |
| 49 | struct in_addr sec_dns; /*!< Secondary Domain Name Service IP address. */ |
| 50 | }; |
| 51 | |
| 52 | struct v6_address_status { |
| 53 | struct in6_addr ip; /*!< Public IPv6 address. */ |
| 54 | struct in6_addr gateway; /*!< Public IPv6 gateway. */ |
| 55 | struct in6_addr pri_dns; /*!< Primary Domain Name Service IPv6 address. */ |
| 56 | struct in6_addr sec_dns; /*!< Secondary Domain Name Service IPv6 address. */ |
| 57 | }; |
| 58 | |
| 59 | typedef struct { |
| 60 | char profile_idx; /*!< UMTS/CMDA profile ID. */ |
| 61 | char name[16]; /*!< Interface Name. */ |
| 62 | qser_data_call_ip_family_e ip_family; /*!< IP version. */ |
| 63 | qser_data_call_state_e state; /*!< The dial status. */ |
| 64 | qser_data_call_error_e err; /*!< The Reason code after data call disconnected. */ |
| 65 | union { |
| 66 | struct v4_address_status v4; /*!< IPv4 information. */ |
| 67 | struct v6_address_status v6; /*!< IPv6 information. */ |
| 68 | }; |
| 69 | } qser_data_call_state_s; |
| 70 | |
| 71 | /* |
| 72 | *!< Client callback function used to post event indications. |
| 73 | */ |
| 74 | typedef void (*qser_data_call_evt_cb_t)(qser_data_call_state_s *state); |
| 75 | |
| 76 | typedef struct { |
| 77 | char profile_idx; /*!< UMTS/CMDA profile ID. */ |
| 78 | bool reconnect; /*!< Whether to re-dial after disconnecting the network. */ |
| 79 | qser_data_call_ip_family_e ip_family; /*!< IP version. */ |
| 80 | char cdma_username[QSER_APN_USERNAME_SIZE]; /*!< Username used during data network authentication. */ |
| 81 | char cdma_password[QSER_APN_PASSWORD_SIZE]; /*!< Password to be used during data network authentication. */ |
| 82 | } qser_data_call_s; |
| 83 | |
| 84 | struct pkt_stats { |
| 85 | unsigned long pkts_tx; /*!< Number of packets transmitted. */ |
| 86 | unsigned long pkts_rx; /*!< Number of packets received. */ |
| 87 | long long bytes_tx; /*!< Number of bytes transmitted. */ |
| 88 | long long bytes_rx; /*!< Number of bytes received. */ |
| 89 | unsigned long pkts_dropped_tx; /*!< Number of transmit packets dropped. */ |
| 90 | unsigned long pkts_dropped_rx; /*!< Number of receive packets dropped. */ |
| 91 | }; |
| 92 | |
| 93 | struct v4_info { |
| 94 | char name[16]; /*!< Interface Name. */ |
| 95 | qser_data_call_state_e state; /*!< The dial status. */ |
| 96 | bool reconnect; /*!< re-dial flag. */ |
| 97 | struct v4_address_status addr; /*!< IPv4 IP Address information. */ |
| 98 | struct pkt_stats stats; /*!< IPv4 statics */ |
| 99 | }; |
| 100 | |
| 101 | struct v6_info { |
| 102 | char name[16]; /*!< Interface Name. */ |
| 103 | qser_data_call_state_e state; /*!< The dial status. */ |
| 104 | bool reconnect; /*!< re-dial flag. */ |
| 105 | struct v6_address_status addr; /*!< IPv6 IP Address information. */ |
| 106 | struct pkt_stats stats; /*!< IPv6 statics */ |
| 107 | }; |
| 108 | |
| 109 | typedef struct { |
| 110 | char profile_idx; /*!< UMTS/CDMA profile ID. */ |
| 111 | qser_data_call_ip_family_e ip_family; /*!< IP version. */ |
| 112 | struct v4_info v4; /*!< IPv4 information */ |
| 113 | struct v6_info v6; /*!< IPv6 information */ |
| 114 | } qser_data_call_info_s; |
| 115 | |
| 116 | typedef struct { |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame^] | 117 | unsigned char profile_idx; /*!< UMTS/CDMA profile ID. range: 0 - 7*/ |
b.liu | 4e243dc | 2023-11-27 11:20:00 +0800 | [diff] [blame] | 118 | qser_apn_pdp_type_e pdp_type; /*!< Packet Data Protocol (PDP) type specifies the type of data payload |
| 119 | exchanged over the airlink when the packet data session is |
| 120 | established with this profile. */ |
| 121 | qser_apn_auth_proto_e auth_proto; /*!< Authentication Protocol. */ |
| 122 | char apn_name[QSER_APN_NAME_SIZE]; /*!< A string parameter that is a logical name used to select the GGSN |
| 123 | and external packet data network. */ |
| 124 | char username[QSER_APN_USERNAME_SIZE]; /*!< Username used during data network authentication. */ |
| 125 | char password[QSER_APN_PASSWORD_SIZE]; /*!< Password to be used during data network authentication. */ |
| 126 | char apn_type[QSER_APN_NAME_SIZE]; |
| 127 | } qser_apn_info_s; |
| 128 | |
| 129 | typedef struct { |
| 130 | qser_apn_pdp_type_e pdp_type; /*!< Packet Data Protocol (PDP) type specifies the type of data payload |
| 131 | exchanged over the airlink when the packet data session is |
| 132 | established with this profile. */ |
| 133 | qser_apn_auth_proto_e auth_proto; /*!< Authentication Protocol. */ |
| 134 | char apn_name[QSER_APN_NAME_SIZE]; /*!< A string parameter that is a logical name used to select the GGSN |
| 135 | and external packet data network. */ |
| 136 | char username[QSER_APN_USERNAME_SIZE]; /*!< Username used during data network authentication. */ |
| 137 | char password[QSER_APN_PASSWORD_SIZE]; /*!< Password to be used during data network authentication. */ |
| 138 | char apn_type[QSER_APN_NAME_SIZE]; |
| 139 | } qser_apn_add_s; |
| 140 | |
| 141 | typedef struct { |
| 142 | int cnt; |
| 143 | qser_apn_info_s apn[QSER_APN_MAX_LIST]; |
| 144 | } qser_apn_info_list_s; |
| 145 | |
| 146 | |
| 147 | /** |
| 148 | * Initialization data call module, and callback function registered. |
| 149 | * |
| 150 | * @param [in] evt_cb callback fucntion |
| 151 | * |
| 152 | * @return |
| 153 | * On success, 0 is returned. On error, -1 is returned. |
| 154 | * |
| 155 | */ |
| 156 | extern int qser_data_call_init(qser_data_call_evt_cb_t evt_cb); |
| 157 | |
| 158 | /** |
| 159 | * Destroy data call module, and unregister callback funciton |
| 160 | * |
| 161 | * @param |
| 162 | * None |
| 163 | * |
| 164 | * @return |
| 165 | * On success, 0 is returned. On error, -1 is returned. |
| 166 | * |
| 167 | */ |
| 168 | extern void qser_data_call_destroy(void); |
| 169 | |
| 170 | /** |
| 171 | * Starts a data call. If profile index is zero, it will call CDMA profile. |
| 172 | * |
| 173 | * @param [in] data_call The data call parameters |
| 174 | * @param [out] error Error code returned by data call |
| 175 | * |
| 176 | * @return |
| 177 | * On success, 0 is returned. On error, -1 is returned. |
| 178 | * |
| 179 | */ |
| 180 | extern int qser_data_call_start(qser_data_call_s *data_call, qser_data_call_error_e *err); |
| 181 | |
| 182 | /** |
| 183 | * Stop a data call. |
| 184 | * |
| 185 | * @param [in] profile_idx UMTS/CDMA profile ID |
| 186 | * @param [in] ip_family IP Version |
| 187 | * @param [out] error Error code returned by data call |
| 188 | * |
| 189 | * @return |
| 190 | * On success, 0 is returned. On error, -1 is returned. |
| 191 | * |
| 192 | */ |
| 193 | extern int qser_data_call_stop(char profile_idx, qser_data_call_ip_family_e ip_family, qser_data_call_error_e *err); |
| 194 | |
| 195 | /** |
| 196 | * Get a data call information. |
| 197 | * |
| 198 | * @param [in] profile_idx UMTS/CDMA profile ID |
| 199 | * @param [in] ip_family IP Version |
| 200 | * @param [out] info The Data Call information |
| 201 | * @param [out] error Error code returned by data call |
| 202 | * |
| 203 | * @return |
| 204 | * On success, 0 is returned. On error, -1 is returned. |
| 205 | * |
| 206 | */ |
| 207 | extern int qser_data_call_info_get(char profile_idx, |
| 208 | qser_data_call_ip_family_e ip_family, |
| 209 | qser_data_call_info_s *info, |
| 210 | qser_data_call_error_e *err); |
| 211 | |
| 212 | /** |
| 213 | * Changes the settings in a configured profile. |
| 214 | * |
| 215 | * @param [in] apn the profile information. |
| 216 | * |
| 217 | * @return |
| 218 | * On success, 0 is returned. On error, -1 is returned, such apn not exist. |
| 219 | * |
| 220 | */ |
| 221 | extern int qser_apn_set(qser_apn_info_s *apn); |
| 222 | |
| 223 | /** |
| 224 | * Retrieves the settings from a configured profile. |
| 225 | * |
| 226 | * @param [in] profile_idx UMTS/CDMA profile ID |
| 227 | * @param [out] apn the profile information. |
| 228 | * |
| 229 | * @return |
| 230 | * On success, 0 is returned. On error, -1 is returned. |
| 231 | * |
| 232 | */ |
| 233 | extern int qser_apn_get(unsigned char profile_idx, qser_apn_info_s *apn); |
| 234 | |
| 235 | /** |
| 236 | * Retrieves the settings from a configured profile. |
| 237 | * |
| 238 | * @param [in] apn the profile information. |
| 239 | * @param [out] profile_idx UMTS/CDMA profile ID |
| 240 | * |
| 241 | * @return |
| 242 | * On success, 0 is returned. On error, -1 is returned. |
| 243 | * |
| 244 | */ |
| 245 | extern int qser_apn_add(qser_apn_add_s *apn, unsigned char *profile_idx); |
| 246 | |
| 247 | /** |
| 248 | * Delete a configured profile. |
| 249 | * |
| 250 | * @param [in] profile_idx UMTS/CDMA profile ID |
| 251 | * |
| 252 | * @return |
| 253 | * On success, 0 is returned. On error, -1 is returned. |
| 254 | * |
| 255 | */ |
| 256 | extern int qser_apn_del(unsigned char profile_idx); |
| 257 | |
| 258 | /** |
| 259 | * Retrieves the settings from a configured profile list. |
| 260 | * |
| 261 | * @param [out] apn_list the profile list information. |
| 262 | * |
| 263 | * @return |
| 264 | * On success, 0 is returned. On error, -1 is returned. |
| 265 | * |
| 266 | */ |
| 267 | extern int qser_apn_get_list(qser_apn_info_list_s *apn_list); |
| 268 | #ifdef __cplusplus |
| 269 | } |
| 270 | #endif |
| 271 | #endif |
| 272 | |