On Tue, Dec 07, 2021 at 09:43:47AM -0600, Denis Kenzior wrote:
> Hi Sean,
> 
> > Good plan :)
> > I have been looking at it. [0]
> 
> Yep, that looks like a good start.
> 
> > 
> > Should I catch the callback directly in atmodem/devinfo.c instead?
> 
> You could try to intercept this in attr_cb itself.  But you'd need access to
> vendor selector somehow.  Perhaps a custom data structure instead of
> cb_data. Alternatively store the prefix in struct dev_data and set
> cb_data->user to struct dev_data.
> 
> Something like:
> 
> static void attr_cb()
> {
>       ...
> 
>       if (at_util_parse_attr(...)) {
>               ...
>       }
> 
>       if (dev->vendor == QUECTEL &&
>                       (!strcmp(dev->prefix, ...) ||
>                       !strcmp(dev->prefix, ...))) {
>               // Strip Revision:
>       }
> 
>       ...
> }
> 

[ ... ]

Hi Denis,

What do you think about this: [0]

In attr_cb() the +10 to attr pointer I need to do better.
While looking at the code, in attr_cb() do we leak the attr string? I
can't find where it's free'd :)

/Sean

[0]:

diff --git a/drivers/atmodem/devinfo.c b/drivers/atmodem/devinfo.c
index ff7386cd..263facd2 100644
--- a/drivers/atmodem/devinfo.c
+++ b/drivers/atmodem/devinfo.c
@@ -29,6 +29,7 @@
 #include <ofono/log.h>
 #include <ofono/modem.h>
 #include <ofono/devinfo.h>
+#include "vendor.h"
 
 #include "gatchat.h"
 #include "gatresult.h"
@@ -37,9 +38,20 @@
 
 static const char *gcap_prefix[] = { "+GCAP:", NULL };
 
+struct dev_data {
+       GAtChat *chat;
+       unsigned int vendor;
+};
+
+struct custom_cb_data {
+       struct cb_data *cbd;
+       unsigned int vendor;
+};
+
 static void attr_cb(gboolean ok, GAtResult *result, gpointer user_data)
 {
-       struct cb_data *cbd = user_data;
+       struct custom_cb_data *ccd = user_data;
+       struct cb_data *cbd = ccd->cbd;
        ofono_devinfo_query_cb_t cb = cbd->cb;
        const char *prefix = cbd->user;
        struct ofono_error error;
@@ -57,21 +69,33 @@ static void attr_cb(gboolean ok, GAtResult *result, 
gpointer user_data)
                return;
        }
 
+       if (ccd->vendor == OFONO_VENDOR_QUECTEL_SERIAL &&
+                       (!strcmp(prefix, "+CGMI:") ||
+                        !strcmp(prefix, "+CGMR:"))) {
+               if (!strncmp("Revision: ", attr, 10)) {
+                       cb(&error, attr+10, cbd->data);
+                       return;
+               }
+       }
+
        cb(&error, attr, cbd->data);
 }
 
 static void at_query_manufacturer(struct ofono_devinfo *info,
                                ofono_devinfo_query_cb_t cb, void *data)
 {
-       struct cb_data *cbd = cb_data_new(cb, data);
-       GAtChat *chat = ofono_devinfo_get_data(info);
+       struct custom_cb_data *ccd = g_new0(struct custom_cb_data, 1);
+       struct dev_data *dev = ofono_devinfo_get_data(info);
+       ccd->cbd = cb_data_new(cb, data);
+       ccd->vendor = dev->vendor;
 
-       cbd->user = "+CGMI:";
+       ccd->cbd->user = "+CGMI:";
 
-       if (g_at_chat_send(chat, "AT+CGMI", NULL, attr_cb, cbd, g_free) > 0)
+       if (g_at_chat_send(dev->chat, "AT+CGMI", NULL, attr_cb, ccd, g_free) > 
0)
                return;
 
-       g_free(cbd);
+       g_free(ccd->cbd);
+       g_free(ccd);
 
        CALLBACK_WITH_FAILURE(cb, NULL, data);
 }
@@ -79,15 +103,18 @@ static void at_query_manufacturer(struct ofono_devinfo 
*info,
 static void at_query_model(struct ofono_devinfo *info,
                                ofono_devinfo_query_cb_t cb, void *data)
 {
-       struct cb_data *cbd = cb_data_new(cb, data);
-       GAtChat *chat = ofono_devinfo_get_data(info);
+       struct custom_cb_data *ccd = g_new0(struct custom_cb_data, 1);
+       struct dev_data *dev = ofono_devinfo_get_data(info);
+       ccd->cbd = cb_data_new(cb, data);
+       ccd->vendor = dev->vendor;
 
-       cbd->user = "+CGMM:";
+       ccd->cbd->user = "+CGMM:";
 
-       if (g_at_chat_send(chat, "AT+CGMM", NULL, attr_cb, cbd, g_free) > 0)
+       if (g_at_chat_send(dev->chat, "AT+CGMM", NULL, attr_cb, ccd, g_free) > 
0)
                return;
 
-       g_free(cbd);
+       g_free(ccd->cbd);
+       g_free(ccd);
 
        CALLBACK_WITH_FAILURE(cb, NULL, data);
 }
@@ -95,15 +122,18 @@ static void at_query_model(struct ofono_devinfo *info,
 static void at_query_revision(struct ofono_devinfo *info,
                                ofono_devinfo_query_cb_t cb, void *data)
 {
-       struct cb_data *cbd = cb_data_new(cb, data);
-       GAtChat *chat = ofono_devinfo_get_data(info);
+       struct custom_cb_data *ccd = g_new0(struct custom_cb_data, 1);
+       struct dev_data *dev = ofono_devinfo_get_data(info);
+       ccd->cbd = cb_data_new(cb, data);
+       ccd->vendor = dev->vendor;
 
-       cbd->user = "+CGMR:";
+       ccd->cbd->user = "+CGMR:";
 
-       if (g_at_chat_send(chat, "AT+CGMR", NULL, attr_cb, cbd, g_free) > 0)
+       if (g_at_chat_send(dev->chat, "AT+CGMR", NULL, attr_cb, ccd, g_free) > 
0)
                return;
 
-       g_free(cbd);
+       g_free(ccd->cbd);
+       g_free(ccd);
 
        CALLBACK_WITH_FAILURE(cb, NULL, data);
 }
@@ -111,15 +141,18 @@ static void at_query_revision(struct ofono_devinfo *info,
 static void at_query_serial(struct ofono_devinfo *info,
                                ofono_devinfo_query_cb_t cb, void *data)
 {
-       struct cb_data *cbd = cb_data_new(cb, data);
-       GAtChat *chat = ofono_devinfo_get_data(info);
+       struct custom_cb_data *ccd = g_new0(struct custom_cb_data, 1);
+       struct dev_data *dev = ofono_devinfo_get_data(info);
+       ccd->cbd = cb_data_new(cb, data);
+       ccd->vendor = dev->vendor;
 
-       cbd->user = "+CGSN:";
+       ccd->cbd->user = "+CGSN:";
 
-       if (g_at_chat_send(chat, "AT+CGSN", NULL, attr_cb, cbd, g_free) > 0)
+       if (g_at_chat_send(dev->chat, "AT+CGSN", NULL, attr_cb, ccd, g_free) > 
0)
                return;
 
-       g_free(cbd);
+       g_free(ccd->cbd);
+       g_free(ccd);
 
        CALLBACK_WITH_FAILURE(cb, NULL, data);
 }
@@ -134,11 +167,16 @@ static void capability_cb(gboolean ok, GAtResult *result, 
gpointer user_data)
 static int at_devinfo_probe(struct ofono_devinfo *info, unsigned int vendor,
                                void *data)
 {
-       GAtChat *chat = g_at_chat_clone(data);
+       GAtChat *chat = data;
+       struct dev_data *dev;
+
+       dev = g_new0(struct dev_data, 1);
+       dev->chat = g_at_chat_clone(chat);
+       dev->vendor = vendor;
 
-       ofono_devinfo_set_data(info, chat);
+       ofono_devinfo_set_data(info, dev);
 
-       g_at_chat_send(chat, "AT+GCAP", gcap_prefix,
+       g_at_chat_send(dev->chat, "AT+GCAP", gcap_prefix,
                                capability_cb, info, NULL);
 
        return 0;
@@ -146,11 +184,11 @@ static int at_devinfo_probe(struct ofono_devinfo *info, 
unsigned int vendor,
 
 static void at_devinfo_remove(struct ofono_devinfo *info)
 {
-       GAtChat *chat = ofono_devinfo_get_data(info);
+       struct dev_data *dev = ofono_devinfo_get_data(info);
 
-       ofono_devinfo_set_data(info, NULL);
+       g_at_chat_unref(dev->chat);
 
-       g_at_chat_unref(chat);
+       ofono_devinfo_set_data(info, NULL);
 }
 
 static const struct ofono_devinfo_driver driver = {
_______________________________________________
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org

Reply via email to