1 #include <libubox/uloop.h>
2 #include <libubox/utils.h>
13 static const char *device;
15 #define CMD_OPT(_arg) (-2 - _arg)
17 #define __uqmi_command(_name, _optname, _arg, _option) { #_optname, _arg##_argument, NULL, CMD_OPT(__UQMI_COMMAND_##_name) }
18 static const struct option uqmi_getopt[] = {
20 { "device", required_argument, NULL, 'd' },
21 { "keep-client-id", required_argument, NULL, 'K' },
26 static int usage(const char *progname)
28 fprintf(stderr, "Usage: %s <options|actions>\n"
30 " --device=NAME, -d NAME: Set device name to NAME (required)\n"
31 " --keep-client-id <name>: Keep Client ID for service <name>\n"
32 " (implies --keep-client-id)\n"
34 "Services: dms, nas, pds, wds, wms\n"
37 " --get-versions: Get service versions\n"
38 " --set-client-id <name>,<id>: Set Client ID for service <name> to <id>\n"
39 " --get-client-id <name>: Connect and get Client ID for service <name>\n"
40 " (implies --keep-client-id)\n"
48 static void keep_client_id(struct qmi_dev *qmi, const char *optarg)
50 QmiService svc = qmi_service_get_by_name(optarg);
52 fprintf(stderr, "Invalid service %s\n", optarg);
55 qmi_service_get_client_id(qmi, svc);
58 int main(int argc, char **argv)
60 static struct qmi_dev dev;
63 while ((ch = getopt_long(argc, argv, "d:k:", uqmi_getopt, NULL)) != -1) {
64 int cmd_opt = CMD_OPT(ch);
66 if (ch < 0 && cmd_opt >= 0 && cmd_opt < __UQMI_COMMAND_LAST) {
67 uqmi_add_command(optarg, cmd_opt);
73 keep_client_id(&dev, optarg);
79 return usage(argv[0]);
84 fprintf(stderr, "No device given\n");
85 return usage(argv[0]);
88 if (qmi_device_open(&dev, device)) {
89 fprintf(stderr, "Failed to open device\n");
93 uqmi_run_commands(&dev);
95 qmi_device_close(&dev);