aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2014-10-09 17:28:24 +0200
committerAleksander Morgado <aleksander@aleksander.es>2014-11-09 20:15:55 +0100
commitbdd4fa544528cfba3f7c37c5b4157890d1c9cd1f (patch)
tree7a752d76705a8b1d16a87fb248d8af524da1a674
parent4d7a31bbd319663994cc3f1290b69ae0fd83c45d (diff)
downloadexternal_libqmi-bdd4fa544528cfba3f7c37c5b4157890d1c9cd1f.zip
external_libqmi-bdd4fa544528cfba3f7c37c5b4157890d1c9cd1f.tar.gz
external_libqmi-bdd4fa544528cfba3f7c37c5b4157890d1c9cd1f.tar.bz2
libqmi-glib,message: use TLV builder to create response messages
-rw-r--r--src/libqmi-glib/qmi-message.c44
1 files changed, 8 insertions, 36 deletions
diff --git a/src/libqmi-glib/qmi-message.c b/src/libqmi-glib/qmi-message.c
index 1d773d6..3377d1d 100644
--- a/src/libqmi-glib/qmi-message.c
+++ b/src/libqmi-glib/qmi-message.c
@@ -549,14 +549,11 @@ qmi_message_new (QmiService service,
* Returns: (transfer full): a newly created #QmiMessage. The returned value should be freed with qmi_message_unref().
*/
QmiMessage *
-qmi_message_response_new (QmiMessage *request,
- QmiProtocolError error)
+qmi_message_response_new (QmiMessage *request,
+ QmiProtocolError error)
{
QmiMessage *response;
- guint8 result_tlv_buffer[4];
- guint16 result_tlv_buffer_len = 4;
- guint8 *result_tlv_buffer_aux = result_tlv_buffer;
- guint16 value;
+ gsize tlv_offset;
response = qmi_message_new (qmi_message_get_service (request),
qmi_message_get_client_id (request),
@@ -569,36 +566,11 @@ qmi_message_response_new (QmiMessage *request,
else
((struct full_message *)(((GByteArray *)response)->data))->qmi.service.header.flags |= QMI_SERVICE_FLAG_RESPONSE;
- /* Add result TLV */
- if (error != QMI_PROTOCOL_ERROR_NONE) {
- value = 0x01;
- qmi_utils_write_guint16_to_buffer (
- &result_tlv_buffer_aux,
- &result_tlv_buffer_len,
- QMI_ENDIAN_LITTLE,
- &value);
- value = error;
- qmi_utils_write_guint16_to_buffer (
- &result_tlv_buffer_aux,
- &result_tlv_buffer_len,
- QMI_ENDIAN_LITTLE,
- &value);
- } else {
- value = 0x00;
- qmi_utils_write_guint16_to_buffer (
- &result_tlv_buffer_aux,
- &result_tlv_buffer_len,
- QMI_ENDIAN_LITTLE,
- &value);
- value = QMI_PROTOCOL_ERROR_NONE;
- qmi_utils_write_guint16_to_buffer (
- &result_tlv_buffer_aux,
- &result_tlv_buffer_len,
- QMI_ENDIAN_LITTLE,
- &value);
- }
-
- g_assert (qmi_message_add_raw_tlv (response, 0x02, result_tlv_buffer, 4, NULL));
+ /* Add result TLV, should never fail */
+ g_assert ((tlv_offset = qmi_message_tlv_write_init (response, 0x02, NULL)) > 0);
+ g_assert (qmi_message_tlv_write_guint16 (response, QMI_ENDIAN_LITTLE, (error != QMI_PROTOCOL_ERROR_NONE), NULL));
+ g_assert (qmi_message_tlv_write_guint16 (response, QMI_ENDIAN_LITTLE, error, NULL));
+ g_assert (qmi_message_tlv_write_complete (response, tlv_offset, NULL));
/* We shouldn't create invalid response messages */
g_assert (message_check (response, NULL));