blob: c90e9c87796579b38248d1b5ec11fb0b9a8c86f6 [file] [log] [blame]
#ifndef __CHL_AGT_UBUS__
#define __CHL_AGT_UBUS__
#include <libubus.h>
#include "chl_agent.h"
#include "chl_agent_uci.h"
#include <chl.h>
#ifndef __maybe_unused
#define __maybe_unused __attribute__((unused))
#endif
#define CHL_REQ_TIMEOUT 20000
#define MAX_RESP_STR 50
#define CHL_MAX_RETRIES 20
int ubus_init(void);
int disable_chl_indications(void);
int enable_chl_indications(void);
void chl_agt_ubus_exit(int i);
int chl_agt_lookup_chl(void);
int add_chl_agt_obj(void);
int agt_register_pdp(struct agent_pdp *pdp, int num);
int agt_open_pdp( struct agent_pdp *pdp );
int agt_unregister_pdp( struct agent_pdp *pdp );
int agt_close_pdp( struct agent_pdp *pdp );
int agt_add_route( char *route, int pdp_id );
int agt_del_route( char *route, int pdp_id );
int agt_set_lte_dflt(struct agent_pdp *pdp);
/******************************************************************************
* defines and structs for ubus invoke chl register
******************************************************************************/
/* blob for register response */
enum chl_blob_reg_resp {
CHL_REG_REQ_STATUS, /*u32*/
CHL_REG_PDP_ID, /*u32*/
_CHL_REG_RESP_MAX
};
static const struct blobmsg_policy chl_reg_resp_pol[] = {
[CHL_REG_REQ_STATUS] = {
.name = "req_status",
.type = BLOBMSG_TYPE_INT32},
[CHL_REG_PDP_ID] = {
.name = CHL_ID_STR,
.type = BLOBMSG_TYPE_INT32},
};
enum chl_resp_table {
CHL_REG_TABLE, /*table*/
_CHL_REG_TABLE_MAX
};
static const struct blobmsg_policy chl_table_pol[] = {
[CHL_REG_TABLE] = {
.name = "response",
.type = BLOBMSG_TYPE_TABLE},
};
struct chl_agt_reg_response {
int req_status;
int id;
char method[20];
};
/******************************************************************************
* defines and structs for ubus invoke chl open
******************************************************************************/
struct chl_agt_open_response {
int req_status;
int nw_status;
int ril_status;
};
/* blob for open response */
enum chl_blob_open_resp {
CHL_OPEN_REQ_STATUS, /*u32*/
CHL_OPEN_NW_STATUS, /*u32*/
CHL_OPEN_RIL_STATUS, /*u32*/
_CHL_OPEN_RESP_MAX
};
static const struct blobmsg_policy chl_open_resp_pol[] = {
[CHL_OPEN_REQ_STATUS] = {
.name = "req_status",
.type = BLOBMSG_TYPE_INT32},
[CHL_OPEN_NW_STATUS] = {
.name = "nw_status",
.type = BLOBMSG_TYPE_INT32},
[CHL_OPEN_RIL_STATUS] = {
.name = "ril_status",
.type = BLOBMSG_TYPE_INT32},
};
static inline enum chl_req_status str_to_req_status(char *str)
{
if (!strcmp(str,"CHL_OK"))
return CHL_OK;
if (!strcmp(str,"CHL_INVALID_REQ"))
return CHL_INVALID_REQ;
if (!strcmp(str,"CHL_INTERNAL_ERROR"))
return CHL_INTERNAL_ERROR;
if (!strcmp(str,"CHL_ID_NOT_FOUND"))
return CHL_ID_NOT_FOUND;
if (!strcmp(str,"RIL_ERROR_OCCURED"))
return RIL_ERROR_OCCURED;
return -1;
}
static inline enum chl_nw_status str_to_nw_state(char *str)
{
if (!strcmp(str,"DATA_UNAVAILABLE"))
return DATA_UNAVAILABLE;
if (!strcmp(str,"DATA_AVAILABLE"))
return DATA_AVAILABLE;
if (!strcmp(str,"DATA_PENDING"))
return DATA_PENDING;
return -1;
}
/******************************************************************************
* defines and structs for ubus invoke chl unregister/close
******************************************************************************/
/* struct for unregister/close response */
struct chl_agt_response {
int req_status;
int nw_status;
};
/* blob for unregister/close response */
enum chl_blob_unreg_resp {
CHL_UNREG_REQ_STATUS, /*u32*/
CHL_UNREG_NW_STATUS, /*u32*/
_CHL_UNREG_RESP_MAX
};
static const struct blobmsg_policy chl_unregister_resp_pol[] = {
[CHL_UNREG_REQ_STATUS] = {
.name = "req_status",
.type = BLOBMSG_TYPE_INT32},
[CHL_UNREG_NW_STATUS] = {
.name = "nw_status",
.type = BLOBMSG_TYPE_INT32},
};
/******************************************************************************
* defines and structs for ubus invoke chl set_route/del_route
******************************************************************************/
struct chl_agt_route_response {
int req_status;
bool add;
};
static const struct blobmsg_policy chl_route_pol[] = {
[CHL_UNREG_REQ_STATUS] = {
.name = "req_status",
.type = BLOBMSG_TYPE_INT32},
};
/******************************************************************************
* defines and structs for ubus invoke chl set_lte_dflt
******************************************************************************/
enum chl_blob_lte_dflt_resp {
CHL_LTE_DFLT_REQ_STATUS, /*u32*/
_CHL_LTE_DFLT_RESP_MAX
};
static const struct blobmsg_policy chl_lte_dflt_pol[] = {
[CHL_LTE_DFLT_REQ_STATUS] = {
.name = "req_status",
.type = BLOBMSG_TYPE_INT32},
};
/******************************************************************************
* defines and structs for ubus chl indications
******************************************************************************/
enum chl_blob_ind_resp {
CHL_IND_ID, /*u32*/
CHL_IND_NW_STATUS, /*u32*/
_CHL_IND_RESP_MAX
};
static const struct blobmsg_policy chl_ind_pol[] = {
[CHL_IND_ID] = {
.name = CHL_RT_ID_STR,
.type = BLOBMSG_TYPE_INT32},
[CHL_IND_NW_STATUS] = {
.name = "nw_status",
.type = BLOBMSG_TYPE_INT32},
};
#endif