The sync command resets the QMI interface state. It will flushs all
previous assigned sessions and transactions.
---
drivers/qmimodem/qmi.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++
drivers/qmimodem/qmi.h | 6 ++++-
2 files changed, 64 insertions(+), 1 deletion(-)
diff --git a/drivers/qmimodem/qmi.c b/drivers/qmimodem/qmi.c
index 0269f7729be0..8bb71b0513ed 100644
--- a/drivers/qmimodem/qmi.c
+++ b/drivers/qmimodem/qmi.c
@@ -1342,6 +1342,65 @@ bool qmi_device_shutdown(struct qmi_device *device,
qmi_shutdown_func_t func,
return true;
}
+struct sync_data {
+ qmi_sync_func_t func;
+ void *user_data;
+};
+
+static void qmi_device_sync_callback(uint16_t message, uint16_t length,
+ const void *buffer, void *user_data)
+{
+ struct sync_data *data = user_data;
+
+ if (data->func)
+ data->func(data->user_data);
+
+ g_free(data);
+}
+
+/* sync will release all previous clients */
+bool qmi_device_sync(struct qmi_device *device,
+ qmi_sync_func_t func, void *user_data)
+{
+ struct qmi_request *req;
+ struct qmi_control_hdr *hdr;
+ struct sync_data *func_data;
+
+ if (!device)
+ return false;
+
+ __debug_device(device, "Sending sync to reset QMI");
+
+ func_data = g_new0(struct sync_data, 1);
+ func_data->func = func;
+ func_data->user_data = user_data;
+
+ req = __request_alloc(QMI_SERVICE_CONTROL, 0x00,
+ QMI_CTL_SYNC, QMI_CONTROL_HDR_SIZE,
+ NULL, 0,
+ qmi_device_sync_callback, func_data, (void **) &hdr);
+
+ if (device->next_control_tid < 1)
+ device->next_control_tid = 1;
+
+ hdr->type = 0x00;
+ hdr->transaction = device->next_control_tid++;
+
+ __request_submit(device, req, hdr->transaction);
+
+ return true;
+}
+
+/* if the device support the QMI call SYNC over the CTL interface */
+bool qmi_device_is_sync_supported(struct qmi_device *device)
+{
+ if (device == NULL)
+ return false;
+
+ return (device->control_major > 1 ||
+ (device->control_major == 1 && device->control_minor >= 5));
+}
+
static bool get_device_file_name(struct qmi_device *device,
char *file_name, int size)
{
diff --git a/drivers/qmimodem/qmi.h b/drivers/qmimodem/qmi.h
index b4955b40b1fb..40d398229af8 100644
--- a/drivers/qmimodem/qmi.h
+++ b/drivers/qmimodem/qmi.h
@@ -76,7 +76,7 @@ typedef void (*qmi_destroy_func_t)(void *user_data);
struct qmi_device;
typedef void (*qmi_debug_func_t)(const char *str, void *user_data);
-
+typedef void (*qmi_sync_func_t)(void *user_data);
typedef void (*qmi_shutdown_func_t)(void *user_data);
typedef void (*qmi_discover_func_t)(uint8_t count,
const struct qmi_version *list, void *user_data);
@@ -96,6 +96,10 @@ bool qmi_device_discover(struct qmi_device *device, qmi_discover_func_t
func,
bool qmi_device_shutdown(struct qmi_device *device, qmi_shutdown_func_t func,
void *user_data, qmi_destroy_func_t destroy);
+bool qmi_device_sync(struct qmi_device *device,
+ qmi_sync_func_t func, void *user_data);
+bool qmi_device_is_sync_supported(struct qmi_device *device);
+
enum qmi_device_expected_data_format qmi_device_get_expected_data_format(
struct qmi_device *device);
bool qmi_device_set_expected_data_format(struct qmi_device *device,
--
2.15.1