add command for getting signal strength info
[project/uqmi.git] / commands-nas.c
1 #include "qmi-message.h"
2
3 static struct qmi_nas_set_system_selection_preference_request sel_req;
4
5 #define cmd_nas_set_network_modes_cb no_cb
6 static enum qmi_cmd_result
7 cmd_nas_set_network_modes_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
8 {
9         static const struct {
10                 const char *name;
11                 QmiNasRatModePreference val;
12         } modes[] = {
13                 { "cdma", QMI_NAS_RAT_MODE_PREFERENCE_CDMA_1X | QMI_NAS_RAT_MODE_PREFERENCE_CDMA_1XEVDO },
14                 { "td-scdma", QMI_NAS_RAT_MODE_PREFERENCE_TD_SCDMA },
15                 { "gsm", QMI_NAS_RAT_MODE_PREFERENCE_GSM },
16                 { "umts", QMI_NAS_RAT_MODE_PREFERENCE_UMTS },
17                 { "lte", QMI_NAS_RAT_MODE_PREFERENCE_LTE },
18         };
19         QmiNasRatModePreference val = 0;
20         char *word;
21         int i;
22
23         for (word = strtok(arg, ",");
24              word;
25              word = strtok(NULL, ",")) {
26                 bool found = false;
27
28                 for (i = 0; i < ARRAY_SIZE(modes); i++) {
29                         if (strcmp(word, modes[i].name) != 0 &&
30                                 strcmp(word, "all") != 0)
31                                 continue;
32
33                         val |= modes[i].val;
34                         found = true;
35                 }
36
37                 if (!found) {
38                         fprintf(stderr, "Invalid network mode '%s'\n", word);
39                         return QMI_CMD_EXIT;
40                 }
41         }
42
43         qmi_set(&sel_req, mode_preference, val);
44         qmi_set_nas_set_system_selection_preference_request(msg, &sel_req);
45         return QMI_CMD_REQUEST;
46 }
47
48 static void
49 cmd_nas_get_signal_info_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
50 {
51         struct qmi_nas_get_signal_info_response res;
52
53         qmi_parse_nas_get_signal_info_response(msg, &res);
54
55         if (res.set.cdma_signal_strength)
56                 printf("cdma_rssi=%d\ncdma_ecio=%d\n",
57                         res.data.cdma_signal_strength.rssi,
58                         res.data.cdma_signal_strength.ecio);
59
60         if (res.set.hdr_signal_strength)
61                 printf("hdr_rssi=%d\nhdr_ecio=%d\nhdr_io=%d\n",
62                         res.data.hdr_signal_strength.rssi,
63                         res.data.hdr_signal_strength.ecio,
64                         res.data.hdr_signal_strength.io);
65
66         if (res.set.gsm_signal_strength)
67                 printf("gsm_rssi=%d\n", res.data.gsm_signal_strength);
68
69         if (res.set.wcdma_signal_strength)
70                 printf("wcdma_rssi=%d\nwcdma_ecio=%d\n",
71                         res.data.wcdma_signal_strength.rssi,
72                         res.data.wcdma_signal_strength.ecio);
73
74         if (res.set.lte_signal_strength)
75                 printf("lte_rssi=%d\nlte_rsrq=%d\nlte_rsrp=%d\nlte_snr=%d\n",
76                         res.data.lte_signal_strength.rssi,
77                         res.data.lte_signal_strength.rsrq,
78                         res.data.lte_signal_strength.rsrp,
79                         res.data.lte_signal_strength.snr);
80
81 }
82
83 static enum qmi_cmd_result
84 cmd_nas_get_signal_info_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
85 {
86         qmi_set_nas_get_signal_info_request(msg);
87         return QMI_CMD_REQUEST;
88 }