add an option for releasing client ids
authorFelix Fietkau <nbd@openwrt.org>
Wed, 20 Feb 2013 01:09:03 +0000 (02:09 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Wed, 20 Feb 2013 01:09:03 +0000 (02:09 +0100)
dev.c
main.c
uqmi.h

diff --git a/dev.c b/dev.c
index 2e20274a742681be776de0b00afe1b2178cc77b8..76a8f30a0c08b304b4771ddd3c61702689c7806a 100644 (file)
--- a/dev.c
+++ b/dev.c
@@ -261,6 +261,13 @@ static void __qmi_service_disconnect(struct qmi_dev *qmi, int idx)
        qmi_request_wait(qmi, &req);
 }
 
+int qmi_service_release_client_id(struct qmi_dev *qmi, QmiService svc)
+{
+       int idx = qmi_get_service_idx(svc);
+       qmi->service_keep_cid &= ~(1 << idx);
+       return 0;
+}
+
 static void qmi_close_all_services(struct qmi_dev *qmi)
 {
        uint32_t connected = qmi->service_connected;
diff --git a/main.c b/main.c
index 5a4a8e818f4eb3f69717cb69e0a4beef2862d307..3a86c84712eb2c60e996e960680db89af150b6de 100644 (file)
--- a/main.c
+++ b/main.c
@@ -19,7 +19,8 @@ static const char *device;
 static const struct option uqmi_getopt[] = {
        __uqmi_commands,
        { "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' },
        { NULL, 0, NULL, 0 }
 };
 #undef __uqmi_command
@@ -31,6 +32,7 @@ static int usage(const char *progname)
                "  --device=NAME, -d NAME:           Set device name to NAME (required)\n"
                "  --keep-client-id <name>:          Keep Client ID for service <name>\n"
                "                                    (implies --keep-client-id)\n"
+               "  --release-client-id <name>:       Release Client ID after exiting\n"
                "\n"
                "Services:                           dms, nas, pds, wds, wms\n"
                "\n"
@@ -57,6 +59,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;
@@ -81,6 +93,9 @@ int main(int argc, char **argv)
                }
 
                switch(ch) {
+               case 'r':
+                       release_client_id(&dev, optarg);
+                       break;
                case 'k':
                        keep_client_id(&dev, optarg);
                        break;
diff --git a/uqmi.h b/uqmi.h
index 842fb9bee96b7f1c3dfce5d69a34c921b2632cb8..4c899b63af33eee42a804b2820da71171691e314 100644 (file)
--- a/uqmi.h
+++ b/uqmi.h
@@ -94,6 +94,7 @@ static inline bool qmi_request_pending(struct qmi_request *req)
 
 int qmi_service_connect(struct qmi_dev *qmi, QmiService svc, int client_id);
 int qmi_service_get_client_id(struct qmi_dev *qmi, QmiService svc);
+int qmi_service_release_client_id(struct qmi_dev *qmi, QmiService svc);
 QmiService qmi_service_get_by_name(const char *str);
 const char *qmi_get_error_str(int code);