Skip to content

Commit

Permalink
[FIX] Proper validation of iface data before export
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukasz Baj committed Oct 3, 2017
1 parent e2f8c02 commit 1364458
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 39 deletions.
19 changes: 17 additions & 2 deletions metadata_exporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
#define MD_INPUT_MAX (__MD_INPUT_MAX - 1)
#define MD_WRITER_MAX (__MD_WRITER_MAX - 1)

#define META_IFACE_INVALID 0x81

#define META_TYPE_INTERFACE 0x01
#define META_TYPE_CONNECTION 0x02
#define META_TYPE_POS 0x04
Expand All @@ -55,6 +53,23 @@
#define META_TYPE_RADIO 0x08
#define META_TYPE_SYSTEM 0x10

#define DEFAULT_RSSI -127
#define DEFAULT_RSRQ 0
#define DEFAULT_RSRP 0
#define DEFAULT_LTE_BAND 0
#define DEFAULT_LTE_FREQ 0
#define DEFAULT_LTE_PCI -1
#define DEFAULT_ENODEBID -1
#define DEFAULT_ECIO 0
#define DEFAULT_RSCP 0
#define DEFAULT_MCCMNC 0
#define DEFAULT_LAC -1
#define DEFAULT_CID -1
#define DEFAULT_LTE_PCI -1
#define DEFAULT_MODE -1
#define DEFAULT_SUBMODE -1
#define DEFAULT_DEVICE_STATE -1

enum iface_event {
IFACE_EVENT_DEV_STATE=1,
IFACE_EVENT_MODE_CHANGE,
Expand Down
18 changes: 10 additions & 8 deletions metadata_input_nl_zmq_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,14 +545,16 @@ void init_iface_event(struct md_iface_event *mie)
mie->md_type = META_TYPE_INTERFACE;
mie->lac = -1;
mie->cid = -1;
mie->rscp = (int16_t) META_IFACE_INVALID;
mie->lte_rsrp = (int16_t) META_IFACE_INVALID;
mie->rssi = (int8_t) META_IFACE_INVALID;
mie->ecio = (int8_t) META_IFACE_INVALID;
mie->lte_rssi = (int8_t) META_IFACE_INVALID;
mie->lte_rsrq = (int8_t) META_IFACE_INVALID;
mie->lte_pci = 0xFFFF;
mie->enodeb_id = -1;
mie->rscp = DEFAULT_RSCP;
mie->lte_rsrp = DEFAULT_RSRP;
mie->rssi = DEFAULT_RSSI;
mie->ecio = DEFAULT_ECIO;
mie->lte_rssi = DEFAULT_RSSI;
mie->lte_rsrq = DEFAULT_RSRQ;
mie->lte_pci = DEFAULT_LTE_PCI;
mie->enodeb_id = DEFAULT_ENODEBID;
mie->device_mode = DEFAULT_MODE;
mie->device_submode = DEFAULT_SUBMODE;
}

void init_conn_event(struct md_conn_event* mce)
Expand Down
30 changes: 15 additions & 15 deletions metadata_writer_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,32 +119,32 @@ static void md_file_handle_iface_event(struct md_writer_file *mwf,
md_file_add_json_string(obj, "imsi", mie->imsi) ||
md_file_add_json_string(obj, "imei", mie->imei) ||
md_file_add_json_string(obj, "isp_name", mie->isp_name) ||
md_file_add_json_int(obj, "mode", mie->device_mode) ||
md_file_add_json_int(obj, "submode", mie->device_submode) ||
md_file_add_json_int(obj, "cid", mie->cid) ||
md_file_add_json_int(obj, "enodeb_id", mie->enodeb_id) ||
md_file_add_json_int(obj, "lac", mie->lac) ||
md_file_add_json_int(obj, "device_state", mie->device_state)) {
(mie->device_mode != DEFAULT_MODE && md_file_add_json_int(obj, "mode", mie->device_mode)) ||
(mie->device_submode != DEFAULT_SUBMODE && md_file_add_json_int(obj, "submode", mie->device_submode)) ||
(mie->cid != DEFAULT_CID && md_file_add_json_int(obj, "cid", mie->cid)) ||
(mie->enodeb_id != DEFAULT_ENODEBID && md_file_add_json_int(obj, "enodeb_id", mie->enodeb_id)) ||
(mie->lac != DEFAULT_LAC && md_file_add_json_int(obj, "lac", mie->lac)) ||
(mie->device_state != DEFAULT_DEVICE_STATE && md_file_add_json_int(obj, "device_state", mie->device_state))) {
META_PRINT_SYSLOG(mwf->parent, LOG_ERR, "md_file_handle_iface_event: Can't create iface values to object!");
json_object_put(obj);
return;
}

if (mie->device_mode != 5) {
if (md_file_add_json_int(obj, "rssi", mie->rssi) ||
md_file_add_json_int(obj, "rscp", mie->rscp) ||
md_file_add_json_int(obj, "ecio", mie->ecio)) {
if ((mie->rssi != DEFAULT_RSSI && md_file_add_json_int(obj, "rssi", mie->rssi)) ||
(mie->rscp != DEFAULT_RSCP && md_file_add_json_int(obj, "rscp", mie->rscp)) ||
(mie->ecio != DEFAULT_ECIO && md_file_add_json_int(obj, "ecio", mie->ecio))) {
META_PRINT_SYSLOG(mwf->parent, LOG_ERR, "md_file_handle_iface_event: Can't add non-LTE values to object!");
json_object_put(obj);
return;
}
} else { // LTE
if (md_file_add_json_int(obj, "lte_rssi", mie->lte_rssi) ||
md_file_add_json_int(obj, "lte_rsrp", mie->lte_rsrp) ||
md_file_add_json_int(obj, "lte_rsrq", mie->lte_rsrq) ||
md_file_add_json_int(obj, "lte_freq", mie->lte_freq) ||
md_file_add_json_int(obj, "lte_pci", mie->lte_pci) ||
md_file_add_json_int(obj, "lte_band", mie->lte_band)) {
if ((mie->lte_rssi != DEFAULT_RSSI && md_file_add_json_int(obj, "lte_rssi", mie->lte_rssi)) ||
(mie->lte_rsrp != DEFAULT_RSRP && md_file_add_json_int(obj, "lte_rsrp", mie->lte_rsrp)) ||
(mie->lte_rsrq != DEFAULT_RSRQ && md_file_add_json_int(obj, "lte_rsrq", mie->lte_rsrq)) ||
(mie->lte_freq != DEFAULT_LTE_FREQ && md_file_add_json_int(obj, "lte_freq", mie->lte_freq)) ||
(mie->lte_pci != DEFAULT_LTE_PCI && md_file_add_json_int(obj, "lte_pci", mie->lte_pci)) ||
(mie->lte_band != DEFAULT_LTE_BAND && md_file_add_json_int(obj, "lte_band", mie->lte_band))) {
META_PRINT_SYSLOG(mwf->parent, LOG_ERR, "md_file_handle_iface_event: Can't add LTE values to object!");
json_object_put(obj);
return;
Expand Down
28 changes: 14 additions & 14 deletions metadata_writer_zeromq.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,44 +408,44 @@ static json_object *md_zeromq_writer_create_iface_json(const struct md_writer_ze
(mie->nw_mccmnc &&
!md_zeromq_writer_create_json_int64(obj, mwz->keys[MD_ZMQ_KEY_NW_MCCMNC],
mie->nw_mccmnc)) ||
((mie->cid > -1 && mie->lac > -1) &&
((mie->cid != DEFAULT_CID && mie->lac != DEFAULT_LAC) &&
(!md_zeromq_writer_create_json_int(obj, mwz->keys[MD_ZMQ_KEY_LAC],
mie->lac) ||
!md_zeromq_writer_create_json_int(obj, mwz->keys[MD_ZMQ_KEY_CID],
mie->cid))) ||
(mie->rscp != (int16_t) META_IFACE_INVALID &&
(mie->rscp != DEFAULT_RSCP &&
!md_zeromq_writer_create_json_int(obj, mwz->keys[MD_ZMQ_KEY_RSCP],
mie->rscp)) ||
(mie->lte_rsrp != (int16_t) META_IFACE_INVALID &&
(mie->lte_rsrp != DEFAULT_RSRP &&
!md_zeromq_writer_create_json_int(obj, mwz->keys[MD_ZMQ_KEY_LTE_RSRP],
mie->lte_rsrp)) ||
(mie->lte_freq &&
(mie->lte_freq != DEFAULT_LTE_FREQ &&
!md_zeromq_writer_create_json_int(obj, mwz->keys[MD_ZMQ_KEY_LTE_FREQ],
mie->lte_freq)) ||
(mie->rssi != (int8_t) META_IFACE_INVALID &&
(mie->rssi != DEFAULT_RSSI &&
!md_zeromq_writer_create_json_int(obj, mwz->keys[MD_ZMQ_KEY_RSSI],
mie->rssi)) ||
(mie->ecio != (int8_t) META_IFACE_INVALID &&
(mie->ecio != DEFAULT_ECIO &&
!md_zeromq_writer_create_json_int(obj, mwz->keys[MD_ZMQ_KEY_ECIO],
mie->ecio)) ||
(mie->lte_rssi != (int8_t) META_IFACE_INVALID &&
(mie->lte_rssi != DEFAULT_RSSI &&
!md_zeromq_writer_create_json_int(obj, mwz->keys[MD_ZMQ_KEY_LTE_RSSI],
mie->lte_rssi)) ||
(mie->lte_rsrq != (int8_t) META_IFACE_INVALID &&
(mie->lte_rsrq != DEFAULT_RSRQ &&
!md_zeromq_writer_create_json_int(obj, mwz->keys[MD_ZMQ_KEY_LTE_RSRQ],
mie->lte_rsrq)) ||
(mie->device_mode && !md_zeromq_writer_create_json_int(obj,
(mie->device_mode != DEFAULT_MODE && !md_zeromq_writer_create_json_int(obj,
mwz->keys[MD_ZMQ_KEY_DEVICE_MODE], mie->device_mode)) ||
(mie->device_submode && !md_zeromq_writer_create_json_int(obj,
(mie->device_submode != DEFAULT_SUBMODE && !md_zeromq_writer_create_json_int(obj,
mwz->keys[MD_ZMQ_KEY_DEVICE_SUBMODE], mie->device_submode)) ||
(mie->lte_band && !md_zeromq_writer_create_json_int(obj,
(mie->lte_band != DEFAULT_LTE_BAND && !md_zeromq_writer_create_json_int(obj,
mwz->keys[MD_ZMQ_KEY_LTE_BAND], mie->lte_band)) ||
(mie->device_state && !md_zeromq_writer_create_json_int(obj,
(mie->device_state != DEFAULT_DEVICE_STATE && !md_zeromq_writer_create_json_int(obj,
mwz->keys[MD_ZMQ_KEY_DEVICE_STATE], mie->device_state)) ||
(mie->lte_pci != 0xFFFF &&
(mie->lte_pci != DEFAULT_LTE_PCI &&
!md_zeromq_writer_create_json_int(obj,
mwz->keys[MD_ZMQ_KEY_LTE_PCI], mie->lte_pci)) ||
(mie->enodeb_id >= 0 &&
(mie->enodeb_id != DEFAULT_ENODEBID &&
!md_zeromq_writer_create_json_int(obj,
mwz->keys[MD_ZMQ_KEY_ENODEB_ID], mie->enodeb_id))) {
json_object_put(obj);
Expand Down

0 comments on commit 1364458

Please sign in to comment.