X-Git-Url: http://git.openwrt.org/?a=blobdiff_plain;f=main.c;h=e4617e295c92da4cad9e773d8dfffc9f22093267;hb=e69bf24b00d8bc15172644e52ead4aae8fdb7257;hp=5a4a8e818f4eb3f69717cb69e0a4beef2862d307;hpb=3762cd81f82e39fac74c1b213f526dc7261aa845;p=project%2Fuqmi.git diff --git a/main.c b/main.c index 5a4a8e8..e4617e2 100644 --- a/main.c +++ b/main.c @@ -1,3 +1,24 @@ +/* + * uqmi -- tiny QMI support implementation + * + * Copyright (C) 2014-2015 Felix Fietkau + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + */ + #include #include #include @@ -18,8 +39,11 @@ static const char *device; #define __uqmi_command(_name, _optname, _arg, _option) { #_optname, _arg##_argument, NULL, CMD_OPT(__UQMI_COMMAND_##_name) } static const struct option uqmi_getopt[] = { __uqmi_commands, + { "single", no_argument, NULL, 's' }, { "device", required_argument, NULL, 'd' }, - { "keep-client-id", required_argument, NULL, 'K' }, + { "keep-client-id", required_argument, NULL, 'k' }, + { "release-client-id", required_argument, NULL, 'r' }, + { "mbim", no_argument, NULL, 'm' }, { NULL, 0, NULL, 0 } }; #undef __uqmi_command @@ -28,21 +52,25 @@ static int usage(const char *progname) { fprintf(stderr, "Usage: %s \n" "Options:\n" + " --single, -s: Print output as a single line (for scripts)\n" " --device=NAME, -d NAME: Set device name to NAME (required)\n" " --keep-client-id : Keep Client ID for service \n" - " (implies --keep-client-id)\n" + " --release-client-id : Release Client ID after exiting\n" + " --mbim, -m NAME is an MBIM device with EXT_QMUX support\n" "\n" "Services: dms, nas, pds, wds, wms\n" "\n" "Actions:\n" " --get-versions: Get service versions\n" " --set-client-id ,: Set Client ID for service to \n" + " (implies --keep-client-id)\n" " --get-client-id : Connect and get Client ID for service \n" " (implies --keep-client-id)\n" wds_helptext dms_helptext nas_helptext wms_helptext + wda_helptext "\n", progname); return 1; } @@ -57,6 +85,16 @@ static void keep_client_id(struct qmi_dev *qmi, const char *optarg) qmi_service_get_client_id(qmi, svc); } +static void release_client_id(struct qmi_dev *qmi, const char *optarg) +{ + QmiService svc = qmi_service_get_by_name(optarg); + if (svc < 0) { + fprintf(stderr, "Invalid service %s\n", optarg); + exit(1); + } + qmi_service_release_client_id(qmi, svc); +} + static void handle_exit_signal(int signal) { cancel_all_requests = true; @@ -66,13 +104,13 @@ static void handle_exit_signal(int signal) int main(int argc, char **argv) { static struct qmi_dev dev; - int ch; + int ch, ret; uloop_init(); signal(SIGINT, handle_exit_signal); signal(SIGTERM, handle_exit_signal); - while ((ch = getopt_long(argc, argv, "d:k:", uqmi_getopt, NULL)) != -1) { + while ((ch = getopt_long(argc, argv, "d:k:sm", uqmi_getopt, NULL)) != -1) { int cmd_opt = CMD_OPT(ch); if (ch < 0 && cmd_opt >= 0 && cmd_opt < __UQMI_COMMAND_LAST) { @@ -81,12 +119,21 @@ int main(int argc, char **argv) } switch(ch) { + case 'r': + release_client_id(&dev, optarg); + break; case 'k': keep_client_id(&dev, optarg); break; case 'd': device = optarg; break; + case 's': + single_line = true; + break; + case 'm': + dev.is_mbim = true; + break; default: return usage(argv[0]); } @@ -102,9 +149,9 @@ int main(int argc, char **argv) return 2; } - uqmi_run_commands(&dev); + ret = uqmi_run_commands(&dev) ? 0 : -1; qmi_device_close(&dev); - return 0; + return ret; }