1 #include <libubox/uloop.h>
2 #include <libubox/utils.h>
14 static const char *device
;
16 #define CMD_OPT(_arg) (-2 - _arg)
18 #define __uqmi_command(_name, _optname, _arg, _option) { #_optname, _arg##_argument, NULL, CMD_OPT(__UQMI_COMMAND_##_name) }
19 static const struct option uqmi_getopt
[] = {
21 { "device", required_argument
, NULL
, 'd' },
22 { "keep-client-id", required_argument
, NULL
, 'k' },
23 { "release-client-id", required_argument
, NULL
, 'r' },
28 static int usage(const char *progname
)
30 fprintf(stderr
, "Usage: %s <options|actions>\n"
32 " --device=NAME, -d NAME: Set device name to NAME (required)\n"
33 " --keep-client-id <name>: Keep Client ID for service <name>\n"
34 " (implies --keep-client-id)\n"
35 " --release-client-id <name>: Release Client ID after exiting\n"
37 "Services: dms, nas, pds, wds, wms\n"
40 " --get-versions: Get service versions\n"
41 " --set-client-id <name>,<id>: Set Client ID for service <name> to <id>\n"
42 " --get-client-id <name>: Connect and get Client ID for service <name>\n"
43 " (implies --keep-client-id)\n"
52 static void keep_client_id(struct qmi_dev
*qmi
, const char *optarg
)
54 QmiService svc
= qmi_service_get_by_name(optarg
);
56 fprintf(stderr
, "Invalid service %s\n", optarg
);
59 qmi_service_get_client_id(qmi
, svc
);
62 static void release_client_id(struct qmi_dev
*qmi
, const char *optarg
)
64 QmiService svc
= qmi_service_get_by_name(optarg
);
66 fprintf(stderr
, "Invalid service %s\n", optarg
);
69 qmi_service_release_client_id(qmi
, svc
);
72 static void handle_exit_signal(int signal
)
74 cancel_all_requests
= true;
78 int main(int argc
, char **argv
)
80 static struct qmi_dev dev
;
84 signal(SIGINT
, handle_exit_signal
);
85 signal(SIGTERM
, handle_exit_signal
);
87 while ((ch
= getopt_long(argc
, argv
, "d:k:", uqmi_getopt
, NULL
)) != -1) {
88 int cmd_opt
= CMD_OPT(ch
);
90 if (ch
< 0 && cmd_opt
>= 0 && cmd_opt
< __UQMI_COMMAND_LAST
) {
91 uqmi_add_command(optarg
, cmd_opt
);
97 release_client_id(&dev
, optarg
);
100 keep_client_id(&dev
, optarg
);
106 return usage(argv
[0]);
111 fprintf(stderr
, "No device given\n");
112 return usage(argv
[0]);
115 if (qmi_device_open(&dev
, device
)) {
116 fprintf(stderr
, "Failed to open device\n");
120 uqmi_run_commands(&dev
);
122 qmi_device_close(&dev
);