wds: make ipv6 address endian swap more portable
[project/uqmi.git] / commands-wms.c
index b85cd70..700d79f 100644 (file)
@@ -1,3 +1,24 @@
+/*
+ * uqmi -- tiny QMI support implementation
+ *
+ * Copyright (C) 2014-2015 Felix Fietkau <nbd@openwrt.org>
+ *
+ * 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 "qmi-message.h"
 
 #define MIN(a,b) (((a)<(b))?(a):(b))
@@ -512,7 +533,7 @@ pdu_encode_semioctet(unsigned char *dest, const char *str)
                str++;
        }
 
-       return len;
+       return lower ? len : (len + 1);
 }
 
 static int
@@ -560,7 +581,7 @@ pdu_encode_number(unsigned char *dest, const char *str, bool smsc)
        }
 
        for (i = 0; str[i]; i++) {
-               if (str[i] >= '0' || str[i] <= '9')
+               if (str[i] >= '0' && str[i] <= '9')
                        continue;
 
                ascii = true;
@@ -591,7 +612,7 @@ pdu_encode_data(unsigned char *dest, const char *str)
 
        dest[len++] = 0;
        len += pdu_encode_7bit_str(&dest[len], str);
-       dest[0] = len - 1;
+       dest[0] = strlen(str);
 
        return len;
 }
@@ -612,12 +633,12 @@ cmd_wms_send_message_prepare(struct qmi_dev *qmi, struct qmi_request *req, struc
        unsigned char protocol_id = 0x00;
        unsigned char dcs = 0x00;
 
-       if (!_send.smsc || !*_send.smsc || !_send.target || !*_send.target) {
+       if (!_send.target || !*_send.target) {
                uqmi_add_error("Missing argument");
                return QMI_CMD_EXIT;
        }
 
-       if (strlen(_send.smsc) > 16 || strlen(_send.target) > 16 || strlen(arg) > 160) {
+       if ((_send.smsc && strlen(_send.smsc) > 16) || strlen(_send.target) > 16 || strlen(arg) > 160) {
                uqmi_add_error("Argument too long");
                return QMI_CMD_EXIT;
        }
@@ -625,7 +646,11 @@ cmd_wms_send_message_prepare(struct qmi_dev *qmi, struct qmi_request *req, struc
        if (_send.flash)
                dcs |= 0x10;
 
-       cur += pdu_encode_number(cur, _send.smsc, true);
+       if (!_send.smsc || !*_send.smsc)
+               *(cur++) = 0;
+       else
+               cur += pdu_encode_number(cur, _send.smsc, true);
+
        *(cur++) = first_octet;
        *(cur++) = 0; /* reference */