Re: [PATCH v2] dnsproxy: Fix possible alignment issue when handling DNS packet.

2011-08-12 Thread Marcel Holtmann
Hi Jukka,

> this patch fixes possible memory alignment issue when dealing with
> DNS packet. This version uses alignment macros from Bluez.
> 
> Jukka
> 
>  include/types.h |   17 +++
>  src/dnsproxy.c  |  134 
> +--
>  2 files changed, 98 insertions(+), 53 deletions(-)
> 
> diff --git a/include/types.h b/include/types.h
> index 70aff9e..82f534a 100644
> --- a/include/types.h
> +++ b/include/types.h
> @@ -38,6 +38,23 @@ typedef intconnman_bool_t;
>  typedef unsigned charconnman_uint8_t;
>  typedef unsigned short   connman_uint16_t;
>  
> +/* unaligned access (code taken from Bluez lib/bluetooth.h) */

If you wanna mention BlueZ then it is with an upper-case Z ;)

However you do not need this. These a commonly known gcc magic macros
for unaligned access. BlueZ did not invent them either.

> +#define cm_get_unaligned(ptr)\
> +({   \
> + struct __attribute__((packed)) {\
> + typeof(*(ptr)) __v; \
> + } *__p = (void *) (ptr);\
> + __p->__v;   \
> +})
> +
> +#define cm_put_unaligned(val, ptr)   \
> +do { \
> + struct __attribute__((packed)) {\
> + typeof(*(ptr)) __v; \
> + } *__p = (void *) (ptr);\
> + __p->__v = (val);   \
> +} while(0)

please use connman_ as namespace. Don't introduce a new namespace. Even
if it would save you some characters.

> +
>  #ifdef __cplusplus
>  }
>  #endif
> diff --git a/src/dnsproxy.c b/src/dnsproxy.c
> index d9e291c..5fd6093 100644
> --- a/src/dnsproxy.c
> +++ b/src/dnsproxy.c
> @@ -37,23 +37,6 @@
>  
>  #include "connman.h"
>  
> -#if __BYTE_ORDER == __LITTLE_ENDIAN
> -struct domain_hdr {
> - uint16_t id;
> - uint8_t rd:1;
> - uint8_t tc:1;
> - uint8_t aa:1;
> - uint8_t opcode:4;
> - uint8_t qr:1;
> - uint8_t rcode:4;
> - uint8_t z:3;
> - uint8_t ra:1;
> - uint16_t qdcount;
> - uint16_t ancount;
> - uint16_t nscount;
> - uint16_t arcount;
> -} __attribute__ ((packed));
> -#elif __BYTE_ORDER == __BIG_ENDIAN
>  struct domain_hdr {
>   uint16_t id;
>   uint8_t qr:1;
> @@ -69,9 +52,6 @@ struct domain_hdr {
>   uint16_t nscount;
>   uint16_t arcount;
>  } __attribute__ ((packed));
> -#else
> -#error "Unknown byte order"
> -#endif

Why are you removing this one now. The bit handling is still correct.

Regards

Marcel


___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


Re: [PATCH_v6] ofono: manage CDMA device into plugin

2011-08-12 Thread Marcel Holtmann
Hi Guillaume,

> diff --git a/plugins/ofono.c b/plugins/ofono.c
> index 060cd8e..adb715d 100644
> --- a/plugins/ofono.c
> +++ b/plugins/ofono.c
> @@ -51,6 +51,11 @@
>  #define OFONO_SIM_INTERFACE  OFONO_SERVICE ".SimManager"
>  #define OFONO_REGISTRATION_INTERFACE OFONO_SERVICE ".NetworkRegistration"
>  
> +#define CDMA_SERVICE OFONO_SERVICE ".cdma"
> +

this is wrong. there is no CDMA service.

> +#define OFONO_CDMA_INTERFACE CDMA_SERVICE ".ConnectionManager"
> +#define OFONO_CDMA_NETREG_INTERFACE  CDMA_SERVICE ".NetworkRegistration"
> +

Keep the .cdma prefix here and don't try to make up new things.

>  #define PROPERTY_CHANGED "PropertyChanged"
>  #define GET_PROPERTIES   "GetProperties"
>  #define SET_PROPERTY "SetProperty"
> @@ -76,6 +81,8 @@ struct modem_data {
>   gboolean has_sim;
>   gboolean has_reg;
>   gboolean has_gprs;
> + gboolean has_cdma;
> + gboolean has_cdma_reg;
>   gboolean available;
>   gboolean pending_online;
>   dbus_bool_t requested_online;
> @@ -90,6 +97,7 @@ struct modem_data {
>   connman_bool_t roaming;
>   uint8_t strength, has_strength;
>   char *operator;
> + char *serial;
>  };

I do not see a point in storing the serial number. We do not store the
IMSI either.

All this CDMA special hacking around is kinda sad. The time might be
better spent to actually write a proper CDMA SIM atom and integrate it
properly into oFono core.

>  struct network_info {
> @@ -337,6 +345,7 @@ static struct connman_device_driver modem_driver = {
>  
>  static void remove_device_networks(struct connman_device *device)
>  {
> + struct modem_data *modem = connman_device_get_data(device);
>   GHashTableIter iter;
>   gpointer key, value;
>   GSList *info_list = NULL;
> @@ -362,6 +371,11 @@ static void remove_device_networks(struct connman_device 
> *device)
>   connman_device_remove_network(device, info->network);
>   }
>  
> + if (modem->has_cdma == TRUE) {
> + g_hash_table_remove(network_hash, modem->path);
> + modem->has_cdma = FALSE;
> + }
> +
>   g_slist_free(info_list);
>  }
>  
> @@ -388,6 +402,7 @@ static void remove_modem(gpointer data)
>  
>   g_free(modem->path);
>   g_free(modem->operator);
> + g_free(modem->serial);
>  
>   g_free(modem);
>  }
> @@ -541,25 +556,57 @@ done:
>  
>  static int set_network_active(struct connman_network *network)
>  {
> + struct connman_device *device;
> + struct modem_data *modem;
>   dbus_bool_t value = TRUE;
>   const char *path = connman_network_get_string(network, "Path");
>  
>   DBG("network %p, path %s", network, path);
>  
> - return set_property(path, OFONO_CONTEXT_INTERFACE,
> - "Active", DBUS_TYPE_BOOLEAN, &value,
> - set_active_reply, g_strdup(path), g_free);
> + device = connman_network_get_device(network);
> + if (device == NULL)
> + return -ENODEV;
> +
> + modem = connman_device_get_data(device);
> + if (modem == NULL)
> + return -ENODEV;
> +
> + if (modem->has_cdma == TRUE)
> + return set_property(path, OFONO_CDMA_INTERFACE,
> + "Powered", DBUS_TYPE_BOOLEAN, &value,
> + set_active_reply, g_strdup(path),
> + g_free);
> + else
> + return set_property(path, OFONO_CONTEXT_INTERFACE,
> + "Active", DBUS_TYPE_BOOLEAN, &value,
> + set_active_reply,
> + g_strdup(path), g_free);
>  }
>  
>  static int set_network_inactive(struct connman_network *network)
>  {
> + struct connman_device *device;
> + struct modem_data *modem;
>   int err;
>   dbus_bool_t value = FALSE;
>   const char *path = connman_network_get_string(network, "Path");
>  
>   DBG("network %p, path %s", network, path);
>  
> - err = set_property(path, OFONO_CONTEXT_INTERFACE,
> + device = connman_network_get_device(network);
> + if (device == NULL)
> + return -ENODEV;
> +
> + modem = connman_device_get_data(device);
> + if (modem == NULL)
> + return -ENODEV;
> +
> + if (modem->has_cdma == TRUE)
> + err = set_property(path, OFONO_CDMA_INTERFACE,
> + "Powered", DBUS_TYPE_BOOLEAN, &value,
> + NULL, NULL, NULL);
> + else
> + err = set_property(path, OFONO_CONTEXT_INTERFACE,
>   "Active", DBUS_TYPE_BOOLEAN, &value,
>   NULL, NULL, NULL);
>  
> @@ -587,7 +634,7 @@ static int network_connect(struct connman_network 
> *network)
>   if (modem->registered == FALSE)
>   return -ENOLINK;

[PATCH v2] dnsproxy: Fix possible alignment issue when handling DNS packet.

2011-08-12 Thread Jukka Rissanen
---
Hi,

this patch fixes possible memory alignment issue when dealing with
DNS packet. This version uses alignment macros from Bluez.

Jukka

 include/types.h |   17 +++
 src/dnsproxy.c  |  134 +--
 2 files changed, 98 insertions(+), 53 deletions(-)

diff --git a/include/types.h b/include/types.h
index 70aff9e..82f534a 100644
--- a/include/types.h
+++ b/include/types.h
@@ -38,6 +38,23 @@ typedef int  connman_bool_t;
 typedef unsigned char  connman_uint8_t;
 typedef unsigned short connman_uint16_t;
 
+/* unaligned access (code taken from Bluez lib/bluetooth.h) */
+#define cm_get_unaligned(ptr)  \
+({ \
+   struct __attribute__((packed)) {\
+   typeof(*(ptr)) __v; \
+   } *__p = (void *) (ptr);\
+   __p->__v;   \
+})
+
+#define cm_put_unaligned(val, ptr) \
+do {   \
+   struct __attribute__((packed)) {\
+   typeof(*(ptr)) __v; \
+   } *__p = (void *) (ptr);\
+   __p->__v = (val);   \
+} while(0)
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/dnsproxy.c b/src/dnsproxy.c
index d9e291c..5fd6093 100644
--- a/src/dnsproxy.c
+++ b/src/dnsproxy.c
@@ -37,23 +37,6 @@
 
 #include "connman.h"
 
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-struct domain_hdr {
-   uint16_t id;
-   uint8_t rd:1;
-   uint8_t tc:1;
-   uint8_t aa:1;
-   uint8_t opcode:4;
-   uint8_t qr:1;
-   uint8_t rcode:4;
-   uint8_t z:3;
-   uint8_t ra:1;
-   uint16_t qdcount;
-   uint16_t ancount;
-   uint16_t nscount;
-   uint16_t arcount;
-} __attribute__ ((packed));
-#elif __BYTE_ORDER == __BIG_ENDIAN
 struct domain_hdr {
uint16_t id;
uint8_t qr:1;
@@ -69,9 +52,6 @@ struct domain_hdr {
uint16_t nscount;
uint16_t arcount;
 } __attribute__ ((packed));
-#else
-#error "Unknown byte order"
-#endif
 
 struct partial_reply {
uint16_t len;
@@ -187,12 +167,56 @@ static struct server_data *find_server(const char 
*interface,
return NULL;
 }
 
+static struct domain_hdr *get_hdr(unsigned char *buf, struct domain_hdr *hdr)
+{
+   if (hdr == NULL)
+   return NULL;
+
+   hdr->id = ntohs(cm_get_unaligned((uint16_t *)buf));
+   hdr->qr = (buf[2] & 0x80) >> 7;
+   hdr->opcode = (buf[2] & 0x78) >> 3;
+   hdr->aa = (buf[2] & 0x04) >> 2;
+   hdr->tc = (buf[2] & 0x02) >> 1;
+   hdr->rd = buf[2] & 0x01;
+   hdr->ra = (buf[3] & 0x80) >> 7;
+   hdr->z = 0;
+   hdr->rcode = buf[3] & 0x0f;
+
+   hdr->qdcount = ntohs(cm_get_unaligned((uint16_t *)&buf[4]));
+   hdr->ancount = ntohs(cm_get_unaligned((uint16_t *)&buf[6]));
+   hdr->nscount = ntohs(cm_get_unaligned((uint16_t *)&buf[8]));
+   hdr->arcount = ntohs(cm_get_unaligned((uint16_t *)&buf[10]));
+
+   return hdr;
+}
+
+static void put_hdr(struct domain_hdr *hdr, unsigned char *buf)
+{
+   if (hdr == NULL)
+   return;
+
+   cm_put_unaligned(htons(hdr->id), (uint16_t *)buf);
+
+   buf[2] |= hdr->qr << 7;
+   buf[2] |= hdr->opcode << 3;
+   buf[2] |= hdr->aa << 2;
+   buf[2] |= hdr->tc << 1;
+   buf[2] |= hdr->rd << 0;
+   buf[3] |= hdr->ra << 7;
+   buf[3] &= ~0x70;
+   buf[3] |= hdr->rcode;
+
+   cm_put_unaligned(htons(hdr->qdcount), (uint16_t *)&buf[4]);
+   cm_put_unaligned(htons(hdr->ancount), (uint16_t *)&buf[6]);
+   cm_put_unaligned(htons(hdr->nscount), (uint16_t *)&buf[8]);
+   cm_put_unaligned(htons(hdr->arcount), (uint16_t *)&buf[10]);
+}
 
 static void send_response(int sk, unsigned char *buf, int len,
const struct sockaddr *to, socklen_t tolen,
int protocol)
 {
-   struct domain_hdr *hdr;
+   struct domain_hdr *hdr, header;
int err, offset = protocol_offset(protocol);
 
DBG("");
@@ -203,7 +227,7 @@ static void send_response(int sk, unsigned char *buf, int 
len,
if (len < 12)
return;
 
-   hdr = (void *) (buf + offset);
+   hdr = get_hdr(buf + offset, &header);
 
DBG("id 0x%04x qr %d opcode %d", hdr->id, hdr->qr, hdr->opcode);
 
@@ -214,6 +238,8 @@ static void send_response(int sk, unsigned char *buf, int 
len,
hdr->nscount = 0;
hdr->arcount = 0;
 
+   put_hdr(hdr, buf + offset);
+
err = sendto(sk, buf, len, 0, to, tolen);
if (err < 0) {
connman_error("Failed to send DNS response: %s",
@@ -247,19 +273,18 @@ static gboolean request_timeout(gpointer user_data)
if (err < 0)
return FALSE;
} else if (req->request && req->numserv == 0) {
-   struct domain_hdr *hdr;
 
if (req->protocol == IPPROTO_TCP

Re: Fun with DHCP

2011-08-12 Thread Daniel Wagner
forget it. some left overs in /var/lib/connman/default.config ...
___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


Fun with DHCP

2011-08-12 Thread Daniel Wagner
Hi,

I tried to get ConnMan working in a not so usual network. The DHCP lease I get
clearly has the DNS server named as 212.18.0.5 and 212.18.3.5. But somehow
we add the 85.25.255.10 address to our dnsproxy for the DNS server. I have a 
full
wireshark trace and the full log of connman, though there isn't even a 
85.25.255.10 
any where to find. Where does this come from?

connmand[2600]: src/dhcp.c:lease_available_cb() Lease available
connmand[2600]: src/service.c:__connman_service_lookup_from_network() network 
0xea16f0
connmand[2600]: src/dhcp.c:lease_available_cb() last address 10.180.92.161
connmand[2600]: src/dhcp.c:lease_available_cb() c_address (null)
connmand[2600]: src/ipconfig.c:__connman_ipconfig_set_gateway() 
connmand[2600]: src/service.c:__connman_service_nameserver_append() service 
0xe99000 nameserver 212.18.0.5
connmand[2600]: src/service.c:__connman_service_nameserver_append() service 
0xe99000 nameserver 212.18.3.5
connmand[2600]: src/utsname.c:__connman_utsname_set_domainname() domainname 
gwlan
connmand[2600]: src/utsname.c:__connman_utsname_set_domainname() driver 
0x68f000 name loopback
connmand[2600]: Setting domainname to gwlan
connmand[2600]: src/utsname.c:__connman_utsname_set_hostname() hostname 
freakazoid
connmand[2600]: src/utsname.c:__connman_utsname_set_hostname() driver 0x68f000 
name loopback
connmand[2600]: Setting hostname to freakazoid
connmand[2600]: src/network.c:dhcp_callback() success 1
connmand[2600]: src/service.c:__connman_service_lookup_from_network() network 
0xea16f0
connmand[2600]: src/network.c:connman_network_set_associating() network 
0xea16f0 associating 0
connmand[2600]: src/ipconfig.c:__connman_ipconfig_address_add() 
connmand[2600]: src/inet.c:connman_inet_set_address() index 3 address 
10.180.92.161 prefix_len 17
connmand[2600]: src/inet.c:__connman_inet_modify_address() cmd 0x14 flags 0x104 
index 3 family 2 address 10.180.92.161 peer (null) prefixlen 17 broadcast (null)
connmand[2600]: src/ipconfig.c:__connman_ipconfig_gateway_add() 
connmand[2600]: src/connection.c:__connman_connection_gateway_remove() service 
0xe99000 type 1
connmand[2600]: src/inet.c:connman_inet_del_network_route() ifname wlan0
connmand[2600]: Deleting host route failed (No such process)
connmand[2600]: src/ipconfig.c:__connman_ipconfig_gateway_add() type 1 gw 
10.180.0.1 peer (null)
connmand[2600]: src/connection.c:__connman_connection_gateway_add() service 
0xe99000 index 3 gateway 10.180.0.1 vpn ip (null) type 1
connmand[2600]: src/connection.c:find_active_gateway() 
connmand[2600]: src/inet.c:connman_inet_add_network_route() ifname wlan0
connmand[2600]: src/inet.c:connman_inet_compare_subnet() host 85.25.255.10
connmand[2600]: src/inet.c:connman_inet_add_network_route() ifname wlan0
connmand[2600]: src/service.c:__connman_service_ipconfig_indicate_state() 
service 0xe99000 (wifi_001e65e41672_56504e2d574c414e_managed_none) state 4 
(ready) type 1 (IPv4)
connmand[2600]: src/wpad.c:__connman_wpad_start() service 0xe99000
connmand[2600]: src/wpad.c:__connman_wpad_start() hostname wpad.gwlan
connmand[2600]: src/service.c:__connman_service_indicate_state() service 
0xe99000 old configuration - new ready/association => ready
connmand[2600]: src/session.c:service_state_changed() service 0xe99000 state 4
connmand[2600]: src/storage.c:__connman_storage_save_service() service 0xe99000
connmand[2600]: src/service.c:service_save() service 0xe99000
connmand[2600]: src/network.c:connman_network_get_blob() network 0xea16f0 key 
WiFi.SSID
connmand[2600]: src/ipconfig.c:__connman_ipconfig_save() ipconfig 0xef7b80 
identifier wifi_001e65e41672_56504e2d574c414e_managed_none
connmand[2600]: src/ipconfig.c:__connman_ipconfig_save() ipconfig 0xef7be0 
identifier wifi_001e65e41672_56504e2d574c414e_managed_none
connmand[2600]: src/resolver.c:connman_resolver_remove_all() interface wlan0
connmand[2600]: src/resolver.c:connman_resolver_append() interface wlan0 domain 
(null) server 85.25.255.10
connmand[2600]: src/resolver.c:append_resolver() interface wlan0 domain (null) 
server 85.25.255.10 lifetime 0 flags 0
connmand[2600]: src/dnsproxy.c:__connman_dnsproxy_append() interface wlan0 
server 85.25.255.10
connmand[2600]: src/dnsproxy.c:find_server() interface wlan0 server 85.25.255.10
connmand[2600]: src/dnsproxy.c:create_server() interface wlan0 server 
85.25.255.10
connmand[2600]: Adding DNS server 85.25.255.10


thanks,
daniel
___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


Re: [PATCH 1/4] connection: Fix can't connect to 3G service with ppp modem

2011-08-12 Thread Patrik Flykt
On Fri, 2011-08-12 at 02:42 -0400, Yu A Wang wrote:

Read through all of your four patches and they look ok to me.

Cheers,

Patrik


___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


[PATCH_v6] ofono: manage CDMA device into plugin

2011-08-12 Thread Guillaume Zajac
---
Change log from v4:
- manage CDMA network registration, netwok is retrieved like GSM case
- modem path is used as network hash_table key
- create CDMA_SERVICE macro to avoid over 80 characters lines

 plugins/ofono.c |  193 ---
 1 files changed, 184 insertions(+), 9 deletions(-)

diff --git a/plugins/ofono.c b/plugins/ofono.c
index 060cd8e..adb715d 100644
--- a/plugins/ofono.c
+++ b/plugins/ofono.c
@@ -51,6 +51,11 @@
 #define OFONO_SIM_INTERFACEOFONO_SERVICE ".SimManager"
 #define OFONO_REGISTRATION_INTERFACE   OFONO_SERVICE ".NetworkRegistration"
 
+#define CDMA_SERVICE   OFONO_SERVICE ".cdma"
+
+#define OFONO_CDMA_INTERFACE   CDMA_SERVICE ".ConnectionManager"
+#define OFONO_CDMA_NETREG_INTERFACECDMA_SERVICE ".NetworkRegistration"
+
 #define PROPERTY_CHANGED   "PropertyChanged"
 #define GET_PROPERTIES "GetProperties"
 #define SET_PROPERTY   "SetProperty"
@@ -76,6 +81,8 @@ struct modem_data {
gboolean has_sim;
gboolean has_reg;
gboolean has_gprs;
+   gboolean has_cdma;
+   gboolean has_cdma_reg;
gboolean available;
gboolean pending_online;
dbus_bool_t requested_online;
@@ -90,6 +97,7 @@ struct modem_data {
connman_bool_t roaming;
uint8_t strength, has_strength;
char *operator;
+   char *serial;
 };
 
 struct network_info {
@@ -337,6 +345,7 @@ static struct connman_device_driver modem_driver = {
 
 static void remove_device_networks(struct connman_device *device)
 {
+   struct modem_data *modem = connman_device_get_data(device);
GHashTableIter iter;
gpointer key, value;
GSList *info_list = NULL;
@@ -362,6 +371,11 @@ static void remove_device_networks(struct connman_device 
*device)
connman_device_remove_network(device, info->network);
}
 
+   if (modem->has_cdma == TRUE) {
+   g_hash_table_remove(network_hash, modem->path);
+   modem->has_cdma = FALSE;
+   }
+
g_slist_free(info_list);
 }
 
@@ -388,6 +402,7 @@ static void remove_modem(gpointer data)
 
g_free(modem->path);
g_free(modem->operator);
+   g_free(modem->serial);
 
g_free(modem);
 }
@@ -541,25 +556,57 @@ done:
 
 static int set_network_active(struct connman_network *network)
 {
+   struct connman_device *device;
+   struct modem_data *modem;
dbus_bool_t value = TRUE;
const char *path = connman_network_get_string(network, "Path");
 
DBG("network %p, path %s", network, path);
 
-   return set_property(path, OFONO_CONTEXT_INTERFACE,
-   "Active", DBUS_TYPE_BOOLEAN, &value,
-   set_active_reply, g_strdup(path), g_free);
+   device = connman_network_get_device(network);
+   if (device == NULL)
+   return -ENODEV;
+
+   modem = connman_device_get_data(device);
+   if (modem == NULL)
+   return -ENODEV;
+
+   if (modem->has_cdma == TRUE)
+   return set_property(path, OFONO_CDMA_INTERFACE,
+   "Powered", DBUS_TYPE_BOOLEAN, &value,
+   set_active_reply, g_strdup(path),
+   g_free);
+   else
+   return set_property(path, OFONO_CONTEXT_INTERFACE,
+   "Active", DBUS_TYPE_BOOLEAN, &value,
+   set_active_reply,
+   g_strdup(path), g_free);
 }
 
 static int set_network_inactive(struct connman_network *network)
 {
+   struct connman_device *device;
+   struct modem_data *modem;
int err;
dbus_bool_t value = FALSE;
const char *path = connman_network_get_string(network, "Path");
 
DBG("network %p, path %s", network, path);
 
-   err = set_property(path, OFONO_CONTEXT_INTERFACE,
+   device = connman_network_get_device(network);
+   if (device == NULL)
+   return -ENODEV;
+
+   modem = connman_device_get_data(device);
+   if (modem == NULL)
+   return -ENODEV;
+
+   if (modem->has_cdma == TRUE)
+   err = set_property(path, OFONO_CDMA_INTERFACE,
+   "Powered", DBUS_TYPE_BOOLEAN, &value,
+   NULL, NULL, NULL);
+   else
+   err = set_property(path, OFONO_CONTEXT_INTERFACE,
"Active", DBUS_TYPE_BOOLEAN, &value,
NULL, NULL, NULL);
 
@@ -587,7 +634,7 @@ static int network_connect(struct connman_network *network)
if (modem->registered == FALSE)
return -ENOLINK;
 
-   if (modem->powered == FALSE)
+   if (modem->powered == FALSE && modem->has_cdma == FALSE)