enable uim message functions
[project/uqmi.git] / commands-wda.c
1 /*
2  * uqmi -- tiny QMI support implementation
3  *
4  * Copyright (C) 2014-2015 Felix Fietkau <nbd@openwrt.org>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301 USA.
20  */
21
22 #include <stdlib.h>
23
24 #include "qmi-message.h"
25
26 static const struct {
27         const char *name;
28         QmiWdaLinkLayerProtocol val;
29 } link_modes[] = {
30         { "802.3", QMI_WDA_LINK_LAYER_PROTOCOL_802_3 },
31         { "raw-ip", QMI_WDA_LINK_LAYER_PROTOCOL_RAW_IP },
32 };
33
34 #define cmd_wda_set_data_format_cb no_cb
35
36 static enum qmi_cmd_result
37 cmd_wda_set_data_format_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
38 {
39         struct qmi_wda_set_data_format_request data_req = {};
40         int i;
41
42         for (i = 0; i < ARRAY_SIZE(link_modes); i++) {
43                 if (strcasecmp(link_modes[i].name, arg) != 0)
44                         continue;
45
46                 qmi_set(&data_req, link_layer_protocol, link_modes[i].val);
47                 qmi_set_wda_set_data_format_request(msg, &data_req);
48                 return QMI_CMD_REQUEST;
49         }
50
51         uqmi_add_error("Invalid auth mode (valid: 802.3, raw-ip)");
52         return QMI_CMD_EXIT;
53 }
54
55 static void
56 cmd_wda_get_data_format_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
57 {
58         struct qmi_wda_get_data_format_response res;
59         const char *name = "unknown";
60         int i;
61
62         qmi_parse_wda_get_data_format_response(msg, &res);
63         for (i = 0; i < ARRAY_SIZE(link_modes); i++) {
64                 if (link_modes[i].val != res.data.link_layer_protocol)
65                         continue;
66
67                 name = link_modes[i].name;
68                 break;
69         }
70
71         blobmsg_add_string(&status, NULL, name);
72 }
73
74 static enum qmi_cmd_result
75 cmd_wda_get_data_format_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
76 {
77         qmi_set_wda_get_data_format_request(msg);
78         return QMI_CMD_REQUEST;
79 }