uqmi: cancel all requests on SYNC indication reception
[project/uqmi.git] / dev.c
diff --git a/dev.c b/dev.c
index 2d1597c07cd2424140d2063fafbf2aa9dbe63493..031b0c0dfa672950f67455550ff94b93af4cc29f 100644 (file)
--- a/dev.c
+++ b/dev.c
@@ -76,6 +76,20 @@ static bool qmi_message_is_response(struct qmi_msg *msg)
        return false;
 }
 
+static bool qmi_message_is_indication(struct qmi_msg *msg)
+{
+       if (msg->qmux.service == QMI_SERVICE_CTL) {
+               if (msg->flags & QMI_CTL_FLAG_INDICATION)
+                       return true;
+       }
+       else {
+               if (msg->flags & QMI_SERVICE_FLAG_INDICATION)
+                       return true;
+       }
+
+       return false;
+}
+
 static void __qmi_request_complete(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
 {
        void *tlv_buf;
@@ -110,6 +124,24 @@ static void qmi_process_msg(struct qmi_dev *qmi, struct qmi_msg *msg)
        struct qmi_request *req;
        uint16_t tid;
 
+       if (qmi_message_is_indication(msg)) {
+               if (msg->qmux.service == QMI_SERVICE_CTL) {
+                       struct qmi_msg sync_msg = {0};
+                       qmi_set_ctl_sync_request(&sync_msg);
+                       /* A SYNC indication might be sent on boot in order to indicate
+                        * that all Client IDs have been deallocated by the modem:
+                        * cancel all requests, as they will not be answered. */
+                       if (msg->ctl.message == sync_msg.ctl.message) {
+                               while (!list_empty(&qmi->req)) {
+                                       req = list_first_entry(&qmi->req, struct qmi_request, list);
+                                       qmi_request_cancel(qmi, req);
+                               }
+                       }
+               }
+
+               return;
+       }
+
        if (!qmi_message_is_response(msg))
                return;