PPP Patches v3
cover PPP Patches v3
Changes since v2 - corrected whitespace.
PATCH 1/6 Basic PPP protocol support
This patch implements the basic PPP protocol. LCP, NCP etc. are handled in a different patch.
--- Makefile.am | 4 +- gatchat/gatppp.c | 133 ++++++++++++++++ gatchat/gatppp.h | 58 +++++++ gatchat/ppp.c | 454 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ gatchat/ppp.h | 130 ++++++++++++++++ 5 files changed, 778 insertions(+), 1 deletions(-) create mode 100644 gatchat/gatppp.c create mode 100644 gatchat/gatppp.h create mode 100644 gatchat/ppp.c create mode 100644 gatchat/ppp.h
Makefile.am +3 -1
@@ -55,7 +55,9 @@ gatchat_sources = gatchat/gatchat.h gatchat/gatchat.c \ gatchat/gattty.h gatchat/gattty.c \ gatchat/gatutil.h gatchat/gatutil.c \ gatchat/gat.h \ - gatchat/gatserver.h gatchat/gatserver.c + gatchat/gatserver.h gatchat/gatserver.c \ + gatchat/gatppp.c gatchat/gatppp.h \ + gatchat/ppp.c gatchat/ppp.h udev_files = plugins/ofono.rules
gatchat/gatppp.c new file +133 -0
133 lines not on this page · raw message
gatchat/gatppp.h new file +58 -0
58 lines not on this page · raw message
gatchat/ppp.c new file +454 -0
454 lines not on this page · raw message
gatchat/ppp.h new file +130 -0
130 lines not on this page · raw message
Signature · 1 line
1.6.6.1
PATCH 2/6 Generic PPP control protocol support
In reply to Kristen Carlson AccardiImplement a generic protocol that can be shared by both the LCP and the NCP implementation.
--- Makefile.am | 3 +- gatchat/ppp.h | 2 + gatchat/ppp_cp.c | 1503 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ gatchat/ppp_cp.h | 139 +++++ 4 files changed, 1646 insertions(+), 1 deletions(-) create mode 100644 gatchat/ppp_cp.c create mode 100644 gatchat/ppp_cp.h
Makefile.am +2 -1
@@ -57,7 +57,8 @@ gatchat_sources = gatchat/gatchat.h gatchat/gatchat.c \ gatchat/gat.h \ gatchat/gatserver.h gatchat/gatserver.c \ gatchat/gatppp.c gatchat/gatppp.h \ - gatchat/ppp.c gatchat/ppp.h + gatchat/ppp.c gatchat/ppp.h gatchat/ppp_cp.h \ + gatchat/ppp_cp.c udev_files = plugins/ofono.rules
gatchat/ppp.h +2 -0
@@ -18,6 +18,8 @@* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * */ +#include "ppp_cp.h" +#define DEFAULT_MRU 1500#define BUFFERSZ DEFAULT_MRU*2#define DEFAULT_ACCM 0x00000000
gatchat/ppp_cp.c new file +1503 -0
1,503 lines not on this page · raw message
gatchat/ppp_cp.h new file +139 -0
139 lines not on this page · raw message
Signature · 1 line
1.6.6.1
PATCH 3/6 PPP LCP support
In reply to Kristen Carlson AccardiImplement LCP support for the PPP protocol.
--- Makefile.am | 2 +- gatchat/gatppp.c | 6 +- gatchat/ppp.c | 47 ++++++++++ gatchat/ppp.h | 7 ++ gatchat/ppp_lcp.c | 246 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 306 insertions(+), 2 deletions(-) create mode 100644 gatchat/ppp_lcp.c
Makefile.am +1 -1
@@ -58,7 +58,7 @@ gatchat_sources = gatchat/gatchat.h gatchat/gatchat.c \ gatchat/gatserver.h gatchat/gatserver.c \ gatchat/gatppp.c gatchat/gatppp.h \ gatchat/ppp.c gatchat/ppp.h gatchat/ppp_cp.h \ - gatchat/ppp_cp.c + gatchat/ppp_cp.c gatchat/ppp_lcp.c udev_files = plugins/ofono.rules
gatchat/gatppp.c +5 -1
@@ -40,6 +40,7 @@void g_at_ppp_open (GAtPPP *ppp) {/* send an OPEN event to the lcp layer */ +lcp_open (ppp->lcp); } void g_at_ppp_set_connect_function(GAtPPP *ppp,
@@ -69,6 +70,9 @@ void g_at_ppp_shutdown(GAtPPP *ppp)/* cleanup modem channel */ g_source_remove (ppp->modem_watch);g_io_channel_unref (ppp->modem); + +/* remove lcp */ +lcp_free (ppp->lcp); }void g_at_ppp_ref (GAtPPP *ppp)
@@ -117,7 +121,7 @@ GAtPPP *g_at_ppp_new(GIOChannel *modem) ppp->index =0 ;/* initialize the lcp state */ - + ppp->lcp =lcp_new (ppp);/* initialize the autentication state */
gatchat/ppp.c +47 -0
66 lines not on this page · raw message
gatchat/ppp.h +7 -0
@@ -98,6 +98,7 @@ static inline guint16 __get_unaligned_short(const gpointer p)struct _GAtPPP {gint ref_count;enum ppp_phase phase; +struct pppcp_data *lcp;guint8 buffer[BUFFERSZ ];int index;gint mru;
@@ -130,3 +131,9 @@ void ppp_set_pfc(GAtPPP *ppp, gboolean pfc);gboolean ppp_get_pfc (GAtPPP *ppp);void ppp_set_acfc (GAtPPP *ppp,gboolean acfc);gboolean ppp_get_acfc (GAtPPP *ppp); +struct pppcp_data *lcp_new (GAtPPP *ppp); +void lcp_free (struct pppcp_data *lcp); +void lcp_open (struct pppcp_data *data); +void lcp_close (struct pppcp_data *data); +void lcp_establish (struct pppcp_data *data); +void lcp_terminate (struct pppcp_data *data);
gatchat/ppp_lcp.c new file +246 -0
246 lines not on this page · raw message
Signature · 1 line
1.6.6.1
PATCH 4/6 CHAP with MD5 authentication support
In reply to Kristen Carlson AccardiAuthentication support with CHAP and MD5
--- Makefile.am | 3 +- gatchat/gatppp.c | 11 +++- gatchat/gatppp.h | 2 + gatchat/ppp.c | 1 + gatchat/ppp.h | 15 ++++ gatchat/ppp_auth.c | 229 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 259 insertions(+), 2 deletions(-) create mode 100644 gatchat/ppp_auth.c
Makefile.am +2 -1
@@ -58,7 +58,8 @@ gatchat_sources = gatchat/gatchat.h gatchat/gatchat.c \ gatchat/gatserver.h gatchat/gatserver.c \ gatchat/gatppp.c gatchat/gatppp.h \ gatchat/ppp.c gatchat/ppp.h gatchat/ppp_cp.h \ - gatchat/ppp_cp.c gatchat/ppp_lcp.c + gatchat/ppp_cp.c gatchat/ppp_lcp.c \ + gatchat/ppp_auth.c udev_files = plugins/ofono.rules
gatchat/gatppp.c +10 -1
@@ -43,6 +43,12 @@ void g_at_ppp_open(GAtPPP *ppp)lcp_open (ppp->lcp); } +void g_at_ppp_set_credentials (GAtPPP *ppp,const char *username, +const char *passwd) +{ +auth_set_credentials (ppp->auth, username, passwd); +} +void g_at_ppp_set_connect_function (GAtPPP *ppp,GAtPPPConnectFunc callback,gpointer user_data) {
@@ -73,6 +79,9 @@ void g_at_ppp_shutdown(GAtPPP *ppp)/* remove lcp */ lcp_free (ppp->lcp); + +/* remove auth */ +auth_free (ppp->auth); }void g_at_ppp_ref (GAtPPP *ppp)
@@ -124,7 +133,7 @@ GAtPPP *g_at_ppp_new(GIOChannel *modem) ppp->lcp =lcp_new (ppp);/* initialize the autentication state */ - + ppp->auth =auth_new (ppp);/* intialize the network state */
gatchat/gatppp.h +2 -0
@@ -51,6 +51,8 @@ void g_at_ppp_set_disconnect_function(GAtPPP *ppp,void g_at_ppp_shutdown (GAtPPP *ppp);void g_at_ppp_ref (GAtPPP *ppp);void g_at_ppp_unref (GAtPPP *ppp); +void g_at_ppp_set_credentials (GAtPPP *ppp,const char *username, +const char *passwd); #ifdef __cplusplus }#endif
gatchat/ppp.c +1 -0
@@ -463,6 +463,7 @@ void ppp_set_auth(GAtPPP *ppp, guint8* auth_data)switch (proto) {case CHAP_PROTOCOL :/* get the algorithm */ +auth_set_proto (ppp->auth, proto, auth_data[2 ]);break ;default :g_printerr ("unknown authentication proto\n" );
gatchat/ppp.h +15 -0
@@ -95,10 +95,20 @@ static inline guint16 __get_unaligned_short(const gpointer p)#define ppp_proto (packet) \ (get_host_short(packet + 2)) +struct auth_data { +guint16 proto; +gpointer proto_data; +void (*process_packet)(struct auth_data *data,guint8 *packet); +char *username; +char *passwd; +GAtPPP *ppp; +}; +struct _GAtPPP {gint ref_count;enum ppp_phase phase;struct pppcp_data *lcp; +struct auth_data *auth;guint8 buffer[BUFFERSZ ];int index;gint mru;
@@ -137,3 +147,8 @@ void lcp_open(struct pppcp_data *data);void lcp_close (struct pppcp_data *data);void lcp_establish (struct pppcp_data *data);void lcp_terminate (struct pppcp_data *data); +void auth_set_credentials (struct auth_data *data,const char *username, +const char *passwd); +void auth_set_proto (struct auth_data *data,guint16 proto,guint8 method); +struct auth_data *auth_new (GAtPPP *ppp); +void auth_free (struct auth_data *auth);
gatchat/ppp_auth.c new file +229 -0
229 lines not on this page · raw message
Signature · 1 line
1.6.6.1
PATCH 5/6 IP support for PPP.
In reply to Kristen Carlson AccardiAdds IPCP support, and creates a TUN interface for sending/receiving IP packets.
--- Makefile.am | 2 +- gatchat/gatppp.c | 1 + gatchat/ppp.c | 1 + gatchat/ppp.h | 12 ++ gatchat/ppp_net.c | 356 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 371 insertions(+), 1 deletions(-) create mode 100644 gatchat/ppp_net.c
Makefile.am +1 -1
@@ -59,7 +59,7 @@ gatchat_sources = gatchat/gatchat.h gatchat/gatchat.c \ gatchat/gatppp.c gatchat/gatppp.h \ gatchat/ppp.c gatchat/ppp.h gatchat/ppp_cp.h \ gatchat/ppp_cp.c gatchat/ppp_lcp.c \ - gatchat/ppp_auth.c + gatchat/ppp_auth.c gatchat/ppp_net.c udev_files = plugins/ofono.rules
gatchat/gatppp.c +1 -0
@@ -136,6 +136,7 @@ GAtPPP *g_at_ppp_new(GIOChannel *modem) ppp->auth =auth_new (ppp);/* intialize the network state */ + ppp->net =ppp_net_new (ppp);/* start listening for packets from the modem */ ppp->modem_watch = g_io_add_watch(modem,
gatchat/ppp.c +1 -0
@@ -381,6 +381,7 @@ static void ppp_dead(GAtPPP *ppp)static void ppp_network (GAtPPP *ppp) {/* bring network phase up */ +ppp_net_open (ppp->net); }static void ppp_transition_phase (GAtPPP *ppp,enum ppp_phase phase)
gatchat/ppp.h +12 -0
@@ -104,11 +104,19 @@ struct auth_data {GAtPPP *ppp; }; +struct ppp_net_data { +GAtPPP *ppp; +char *if_name; +GIOChannel *channel; +struct pppcp_data *ipcp; +}; +struct _GAtPPP {gint ref_count;enum ppp_phase phase;struct pppcp_data *lcp;struct auth_data *auth; +struct ppp_net_data *net;guint8 buffer[BUFFERSZ ];int index;gint mru;
@@ -152,3 +160,7 @@ void auth_set_credentials(struct auth_data *data, const char *username,void auth_set_proto (struct auth_data *data,guint16 proto,guint8 method);struct auth_data *auth_new (GAtPPP *ppp);void auth_free (struct auth_data *auth); +struct ppp_net_data *ppp_net_new (GAtPPP *ppp); +void ppp_net_open (struct ppp_net_data *data); +void ppp_net_free (struct ppp_net_data *data); +void ppp_net_close (struct ppp_net_data *data);
gatchat/ppp_net.c new file +356 -0
356 lines not on this page · raw message
Signature · 1 line
1.6.6.1
PATCH 6/6 Add PPP option to gsmdial
In reply to Kristen Carlson AccardiImplement new options for gsmdial to use PPP and set the user name and password for authentication if needed.
--- gatchat/gsmdial.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 84 insertions(+), 3 deletions(-)
gatchat/gsmdial.c +84 -3
@@ -36,6 +36,7 @@#include <glib.h> #include <gatchat.h> #include <gattty.h> +#include <gatppp.h> static const char *none_prefix[] = {NULL };static const char *cgreg_prefix[] = {"+CGREG:" ,NULL };
@@ -48,7 +49,11 @@ static gint option_cid = 0;static gchar *option_apn =NULL ;static gint option_offmode =0 ;static gboolean option_legacy = FALSE; +static gboolean option_ppp = FALSE; +static gchar *option_username =NULL ; +static gchar *option_password =NULL ; +static GAtPPP *ppp;static GAtChat *control;static GAtChat *modem;static GMainLoop *event_loop;
@@ -223,6 +228,76 @@ static void at_cgact_up_cb(gboolean ok, GAtResult *result, gpointer user_data)g_at_chat_send (modem, buf, none_prefix,NULL ,NULL ,NULL ); } +static void print_ip_address (const char *label,guint32 ip_addr) +{ +struct in_addr addr; +char buf[INET_ADDRSTRLEN ]; + + addr.s_addr = ip_addr; + +if (inet_ntop (AF_INET , &addr, buf,INET_ADDRSTRLEN )) +g_print ("%s: %s\n" , label, buf); +} + +static void ppp_connect (GAtPPP *ppp,GAtPPPConnectStatus success, +guint32 ip_addr,guint32 dns1,guint32 dns2, +gpointer user_data) +{ +if (success !=G_AT_PPP_CONNECT_SUCCESS ) { +g_print ("Failed to create PPP interface!\n" ); +return ; + } + +/* print out the negotiated address and dns server */ +print_ip_address ("IP Address" , ip_addr); +print_ip_address ("Primary DNS Server" , dns1); +print_ip_address ("Secondary DNS Server" , dns2); +} + +static void ppp_disconnect (GAtPPP *ppp,gpointer user_data) +{ +g_print ("PPP Link down\n" ); +} + +static void connect_cb (gboolean ok,GAtResult *result,gpointer user_data) +{ +GIOChannel *channel; + +if (!ok) { +g_print ("Unable to define context\n" ); +exit (1 ); + } + +if (option_ppp == FALSE) +return ; + +/* get the data IO channel */ + channel =g_at_chat_get_channel (modem); + +/* +* shutdown gatchat or else it tries to take all the input +* from the modem and does not let PPP get it. +*/ +g_at_chat_shutdown (control); +g_at_chat_shutdown (modem); + +/* open ppp */ + ppp =g_at_ppp_new (channel); +if (!ppp) { +g_print ("Unable to create PPP object\n" ); +return ; + } +g_at_ppp_set_credentials (ppp, option_username, + option_password); + +/* set connect and disconnect callbacks */ +g_at_ppp_set_connect_function (ppp, ppp_connect,NULL ); +g_at_ppp_set_disconnect_function (ppp, ppp_disconnect,NULL ); + +/* open the ppp connection */ +g_at_ppp_open (ppp); +} +static void at_cgdcont_cb (gboolean ok,GAtResult *result,gpointer user_data) {char buf[64 ];
@@ -233,9 +308,9 @@ static void at_cgdcont_cb(gboolean ok, GAtResult *result, gpointer user_data) }if (option_legacy == TRUE) { -sprintf (buf,"ATD*99***%u#" , option_cid); -g_at_chat_send (modem, buf, none_prefix, -NULL ,NULL ,NULL ); +sprintf (buf,"ATD*99***%u#" , option_cid); +g_at_chat_send (modem, buf, none_prefix, + connect_cb,NULL ,NULL ); }else {sprintf (buf,"AT+CGACT=1,%u" , option_cid); g_at_chat_send(control, buf, none_prefix,
@@ -452,6 +527,12 @@ static GOptionEntry options[] = { "Specify CFUN offmode" }, {"legacy" ,'l' ,0 ,G_OPTION_ARG_NONE , &option_legacy, "Use ATD*99***<cid>#" }, + { "ppp", 'P', 0, G_OPTION_ARG_NONE, &option_ppp, + "Connect using PPP" }, + { "username", 'u', 0, G_OPTION_ARG_STRING, &option_username, + "Specify PPP username" }, + { "password", 'w', 0, G_OPTION_ARG_STRING, &option_password, + "Specifiy PPP password" }, { NULL }, };
Signature · 1 line
1.6.6.1
Re: [PATCH 6/6] Add PPP option to gsmdial
Quoted 62 lines · Kristen Carlson Accardi
Implement new options for gsmdial to use PPP and set the user name and password for authentication if needed.
--- gatchat/gsmdial.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 84 insertions(+), 3 deletions(-)gatchat/gsmdial.c +33
-0@@ -36,6 +36,7 @@#include <glib.h> #include <gatchat.h> #include <gattty.h> +#include <gatppp.h> static const char *none_prefix[] = {NULL };static const char *cgreg_prefix[] = {"+CGREG:" ,NULL };@@ -48,7 +49,11 @@ static gint option_cid = 0;static gchar *option_apn =NULL ;static gint option_offmode =0 ;static gboolean option_legacy = FALSE; +static gboolean option_ppp = FALSE; +static gchar *option_username =NULL ; +static gchar *option_password =NULL ; +static GAtPPP *ppp;static GAtChat *control;static GAtChat *modem;static GMainLoop *event_loop;@@ -223,6 +228,76 @@ static void at_cgact_up_cb(gboolean ok, GAtResult *result, gpointer user_data)g_at_chat_send (modem, buf, none_prefix,NULL ,NULL ,NULL ); } +static void print_ip_address (const char *label,guint32 ip_addr) +{ +struct in_addr addr; +char buf[INET_ADDRSTRLEN ]; + + addr.s_addr = ip_addr; + +if (inet_ntop (AF_INET , &addr, buf,INET_ADDRSTRLEN )) +g_print ("%s: %s\n" , label, buf); +} + +static void ppp_connect (GAtPPP *ppp,GAtPPPConnectStatus success, +guint32 ip_addr,guint32 dns1,guint32 dns2, +gpointer user_data) +{ +if (success !=G_AT_PPP_CONNECT_SUCCESS ) { +g_print ("Failed to create PPP interface!\n" ); +return ; + } + +/* print out the negotiated address and dns server */ +print_ip_address ("IP Address" , ip_addr); +print_ip_address ("Primary DNS Server" , dns1); +print_ip_address ("Secondary DNS Server" , dns2); +} + +static void ppp_disconnect (GAtPPP *ppp,gpointer user_data) +{
gatchat/gsmdial.c static void at_cgact_up_cb(gboolean ok, GAtResult *result, gpointer user_data) · line 268
Quoted 10 lines
gatchat/gsmdial.c +10
-0+g_print ("PPP Link down\n" ); +} + +static void connect_cb (gboolean ok,GAtResult *result,gpointer user_data) +{ +GIOChannel *channel; + +if (!ok) { +g_print ("Unable to define context\n" ); +exit (1 );
I guess we should not call exit here. Just return.
Quoted 68 lines
gatchat/gsmdial.c +41
-3+ } + +if (option_ppp == FALSE) +return ; + +/* get the data IO channel */ + channel =g_at_chat_get_channel (modem); + +/* +* shutdown gatchat or else it tries to take all the input +* from the modem and does not let PPP get it. +*/ +g_at_chat_shutdown (control); +g_at_chat_shutdown (modem); + +/* open ppp */ + ppp =g_at_ppp_new (channel); +if (!ppp) { +g_print ("Unable to create PPP object\n" ); +return ; + } +g_at_ppp_set_credentials (ppp, option_username, + option_password); + +/* set connect and disconnect callbacks */ +g_at_ppp_set_connect_function (ppp, ppp_connect,NULL ); +g_at_ppp_set_disconnect_function (ppp, ppp_disconnect,NULL ); + +/* open the ppp connection */ +g_at_ppp_open (ppp); +} +static void at_cgdcont_cb (gboolean ok,GAtResult *result,gpointer user_data) {char buf[64 ];@@ -233,9 +308,9 @@ static void at_cgdcont_cb(gboolean ok, GAtResult *result, gpointer user_data) }if (option_legacy == TRUE) { -sprintf (buf,"ATD*99***%u#" , option_cid); -g_at_chat_send (modem, buf, none_prefix, -NULL ,NULL ,NULL ); +sprintf (buf,"ATD*99***%u#" , option_cid); +g_at_chat_send (modem, buf, none_prefix, + connect_cb,NULL ,NULL ); }else {sprintf (buf,"AT+CGACT=1,%u" , option_cid); g_at_chat_send(control, buf, none_prefix,@@ -452,6 +527,12 @@ static GOptionEntry options[] = { "Specify CFUN offmode" }, {"legacy" ,'l' ,0 ,G_OPTION_ARG_NONE , &option_legacy, "Use ATD*99***<cid>#" }, + { "ppp", 'P', 0, G_OPTION_ARG_NONE, &option_ppp, + "Connect using PPP" }, + { "username", 'u', 0, G_OPTION_ARG_STRING, &option_username, + "Specify PPP username" }, + { "password", 'w', 0, G_OPTION_ARG_STRING, &option_password, + "Specifiy PPP password" }, { NULL }, };Signature · 6 lines
1.6.6.1 _______________________________________________ ofono mailing list ofono(a)ofono.org http://lists.ofono.org/listinfo/ofono
Signature · 2 lines
Gustavo F. Padovan ProFUSION embedded systems - http://profusion.mobi
Re: [PATCH 6/6] Add PPP option to gsmdial
Hi Gustavo,
Quoted 9 lines
gatchat/gsmdial.c static void at_cgact_up_cb(gboolean ok, GAtResult *result, gpointer user_data) · line 268
Quoted 7 lines
gatchat/gsmdial.c +7
-0+static void connect_cb (gboolean ok,GAtResult *result,gpointer user_data) +{ +GIOChannel *channel; + +if (!ok) { +g_print ("Unable to define context\n" ); +exit (1 );I guess we should not call exit here. Just return.
it is a test program. So it doesn't really matter. We will never install this program. It is just for the developers ;)
Regards
Marcel
Hi Kristen,
Quoted 1 line
Changes since v2 - corrected whitespace.
all the patches have been applied.
So form now on please send smaller patches as soon as you have them ready and tested. If you need comments or have questions, you can use the mailing list as well.
Regards
Marcel
Hi Kristen,
Quoted 7 lines
Quoted 1 line
Changes since v2 - corrected whitespace.
all the patches have been applied.
So form now on please send smaller patches as soon as you have them ready and tested. If you need comments or have questions, you can use the mailing list as well.
some additional comments from my side.
If you have variables that are only valid inside the scope of a statement, then I prefer if you only declare them there. This makes the code a bit simpler to read. Check the patch I just pushed to give you an example.
Also please find access to a 32-bit system if you are running 64-bit or vice versa. Our build system is strict and will turn turn all casting mistakes in an error.
Please be present on #ofono IRC as much as possible so people can report such things. Remember that your code is now part of the tree and it can break the build.
Regards
Marcel
Quoted 21 lines · On Mon, 22 Mar 2010 19:22:00 -0700 Marcel Holtmann <[email protected]> wrote:
Hi Kristen,
Quoted 7 lines
Quoted 1 line
Changes since v2 - corrected whitespace.
all the patches have been applied.
So form now on please send smaller patches as soon as you have them ready and tested. If you need comments or have questions, you can use the mailing list as well.
some additional comments from my side.
If you have variables that are only valid inside the scope of a statement, then I prefer if you only declare them there. This makes the code a bit simpler to read. Check the patch I just pushed to give you an example.
Also please find access to a 32-bit system if you are running 64-bit or vice versa. Our build system is strict and will turn turn all casting mistakes in an error.
Quoted 9 lines
Please be present on #ofono IRC as much as possible so people can report such things. Remember that your code is now part of the tree and it can break the build.
Regards
Marcel
Marcel - I just started reviewing the changes you made and the first patch I hit I discovered that you broke something. Would you like to revert the patches and let me review them first, or should I just send a patch to the mailing list to fix what you broke?
Hi Kristen,
Quoted 19 lines
Quoted 19 lines
Quoted 7 lines
Quoted 1 line
Changes since v2 - corrected whitespace.
all the patches have been applied.
So form now on please send smaller patches as soon as you have them ready and tested. If you need comments or have questions, you can use the mailing list as well.
some additional comments from my side.
If you have variables that are only valid inside the scope of a statement, then I prefer if you only declare them there. This makes the code a bit simpler to read. Check the patch I just pushed to give you an example.
Also please find access to a 32-bit system if you are running 64-bit or vice versa. Our build system is strict and will turn turn all casting mistakes in an error.
Quoted 8 lines
Quoted 3 lines
Please be present on #ofono IRC as much as possible so people can report such things. Remember that your code is now part of the tree and it can break the build.
I just started reviewing the changes you made and the first patch I hit I discovered that you broke something. Would you like to revert the patches and let me review them first, or should I just send a patch to the mailing list to fix what you broke?
send patches to the mailing list to fix them. The PPP code is in development so it is just fine. I prefer to keep reverts for code that is suppose to be stable.
If I did break something, then I am worried that the code gets too complex. Such little changes should not have broken anything. Except I made a stupid typo or thinking mistake (which happens of course). If it fundamentally changes the code flow, then we do have a bigger problem.
Regards
Marcel
Quoted 34 lines · On Mon, 22 Mar 2010 20:47:16 -0700 Marcel Holtmann <[email protected]> wrote:
Hi Kristen,
Quoted 19 lines
Quoted 19 lines
Quoted 7 lines
Quoted 1 line
Changes since v2 - corrected whitespace.
all the patches have been applied.
So form now on please send smaller patches as soon as you have them ready and tested. If you need comments or have questions, you can use the mailing list as well.
some additional comments from my side.
If you have variables that are only valid inside the scope of a statement, then I prefer if you only declare them there. This makes the code a bit simpler to read. Check the patch I just pushed to give you an example.
Also please find access to a 32-bit system if you are running 64-bit or vice versa. Our build system is strict and will turn turn all casting mistakes in an error.
Quoted 8 lines
Quoted 3 lines
Please be present on #ofono IRC as much as possible so people can report such things. Remember that your code is now part of the tree and it can break the build.
I just started reviewing the changes you made and the first patch I hit I discovered that you broke something. Would you like to revert the patches and let me review them first, or should I just send a patch to the mailing list to fix what you broke?
send patches to the mailing list to fix them. The PPP code is in development so it is just fine. I prefer to keep reverts for code that is suppose to be stable.
Quoted 10 lines
If I did break something, then I am worried that the code gets too complex. Such little changes should not have broken anything. Except I made a stupid typo or thinking mistake (which happens of course). If it fundamentally changes the code flow, then we do have a bigger problem.
Regards
Marcel
I wanted this code to at least be able to send a packet over the wire, and with your changes we can't do that anymore. The problem is that your little cosmetic change really did change the flow, simply because you didn't think through what you were doing. Of course it is up to you if you want to have this code be completely non-functional rather than simply doing the revert. I'll be glad to submit a patch later which fixes your fix and adds some comments so you know what is actually happening.
Hi Kristen,
Quoted 37 lines
Quoted 28 lines
Quoted 19 lines
Quoted 19 lines
Quoted 7 lines
Quoted 1 line
Changes since v2 - corrected whitespace.
all the patches have been applied.
So form now on please send smaller patches as soon as you have them ready and tested. If you need comments or have questions, you can use the mailing list as well.
some additional comments from my side.
If you have variables that are only valid inside the scope of a statement, then I prefer if you only declare them there. This makes the code a bit simpler to read. Check the patch I just pushed to give you an example.
Also please find access to a 32-bit system if you are running 64-bit or vice versa. Our build system is strict and will turn turn all casting mistakes in an error.
Quoted 8 lines
Quoted 3 lines
Please be present on #ofono IRC as much as possible so people can report such things. Remember that your code is now part of the tree and it can break the build.
I just started reviewing the changes you made and the first patch I hit I discovered that you broke something. Would you like to revert the patches and let me review them first, or should I just send a patch to the mailing list to fix what you broke?
Quoted 8 lines
send patches to the mailing list to fix them. The PPP code is in development so it is just fine. I prefer to keep reverts for code that is suppose to be stable.
If I did break something, then I am worried that the code gets too complex. Such little changes should not have broken anything. Except I made a stupid typo or thinking mistake (which happens of course). If it fundamentally changes the code flow, then we do have a bigger problem.
Quoted 8 lines
I wanted this code to at least be able to send a packet over the wire, and with your changes we can't do that anymore. The problem is that your little cosmetic change really did change the flow, simply because you didn't think through what you were doing. Of course it is up to you if you want to have this code be completely non-functional rather than simply doing the revert. I'll be glad to submit a patch later which fixes your fix and adds some comments so you know what is actually happening.
I am not doing the revert since I do wanna figure out what broke it. And actually I wanna have that recorded in the tree.
So Denis and I looked through my changes and he figured out what might have broken it. So your attempt at doing code flow optimization with g_list_length() throw me on the wrong error path. Please don't do this since all the GLib functions will do proper empty list checking.
I fixed this now in the tree and it should restore it to a working code base. I prefer if you don't do things like GList *list = NULL. These initialization of variables lead to some complex code flow. And if you do something wrong, the compiler will never warn.
Also in general it is preferred to do list == NULL checking instead of using g_list_legnth() functions.
Regards
Marcel
Quoted 4 lines · On Mon, 22 Mar 2010 21:51:38 -0700 Marcel Holtmann <[email protected]> wrote:
So Denis and I looked through my changes and he figured out what might have broken it. So your attempt at doing code flow optimization with
g_list_length()throw me on the wrong error path. Please don't do this since all the GLib functions will do proper empty list checking.
I reviewed your patch and it seems that you didn't break it this time :). If you ever have questions about the code, feel free to ask me.
Hi Kristen,
Quoted 7 lines
Quoted 4 lines
So Denis and I looked through my changes and he figured out what might have broken it. So your attempt at doing code flow optimization with
g_list_length()throw me on the wrong error path. Please don't do this since all the GLib functions will do proper empty list checking.I reviewed your patch and it seems that you didn't break it this time :). If you ever have questions about the code, feel free to ask me.
please try to keep the code flow inside the functions as simple as possible. Otherwise things like this happen.
Also in this context I would prefer if you create a helper function like find_option() instead of manually calling g_list_find_custom() all the time. From a pure code understanding point of view it is way simpler to see what the code is meant do be doing. The find_custom + is_option is not intuitiv.
With a proper helper we didn't need to workaround the casting issue from guint16/guint8 to guint at every spot. The compiler will inline the helper anyway if useful. So no real drawback here from a runtime code point of view. And there was another problem with one variable being guint16, but the is_option casts it back to guint8. We can't really have that. Once you start casting on that scale the compiler will not warn you about type mismatches or if the value of argument is too big for its type.
Regards
Marcel
Quoted 2 lines · On Mon, 22 Mar 2010 23:45:14 -0700 Marcel Holtmann <[email protected]> wrote:
please try to keep the code flow inside the functions as simple as possible. Otherwise things like this happen.
One suggestion I have for the future is to actually send your patches to the mailing list for review, even if you've already committed them. I can understand just committing things without public review for expediency, but having many eyes looking at things can help as well.
Quoted 5 lines · On Mon, 22 Mar 2010 23:45:14 -0700 Marcel Holtmann <[email protected]> wrote:
And there was another problem with one variable being guint16, but the
is_optioncasts it back to guint8. We can't really have that. Once you start casting on that scale the compiler will not warn you about type mismatches or if the value of argument is too big for its type.
Can you please let me know which git commit this fix you made was? I want to review it because all of the option types should only be a byte anyway, so I am trying to figure out if there was a mistake somewhere where we were using is_option to examine a 16 bit value. I searched through the git log and can't figure out where this change was. I can see where you changed the option type we are comparing to a regular guint to avoid compiler problems, but not the other issue you mentioned.
Hi Kristen,
Quoted 6 lines
Quoted 5 lines
And there was another problem with one variable being guint16, but the
is_optioncasts it back to guint8. We can't really have that. Once you start casting on that scale the compiler will not warn you about type mismatches or if the value of argument is too big for its type.
Quoted 7 lines
Can you please let me know which git commit this fix you made was? I want to review it because all of the option types should only be a byte anyway, so I am trying to figure out if there was a mistake somewhere where we were using
is_optionto examine a 16 bit value. I searched through the git log and can't figure out where this change was. I can see where you changed the option type we are comparing to a regular guint to avoid compiler problems, but not the other issue you mentioned.
I had a second look at these. It is the is_proto_handler actually and not the is_option. However that thing applies here. A helper function to find that handle would be better then manually coding g_list_find_custom in the functions.
Regards
Marcel
Quoted 16 lines · On Tue, 23 Mar 2010 10:56:00 -0700 Marcel Holtmann <[email protected]> wrote:
Hi Kristen,
Quoted 6 lines
Quoted 5 lines
And there was another problem with one variable being guint16, but the
is_optioncasts it back to guint8. We can't really have that. Once you start casting on that scale the compiler will not warn you about type mismatches or if the value of argument is too big for its type.Quoted 7 lines
Can you please let me know which git commit this fix you made was? I want to review it because all of the option types should only be a byte anyway, so I am trying to figure out if there was a mistake somewhere where we were using
is_optionto examine a 16 bit value. I searched through the git log and can't figure out where this change was. I can see where you changed the option type we are comparing to a regular guint to avoid compiler problems, but not the other issue you mentioned.
Quoted 10 lines
I had a second look at these. It is the
is_proto_handleractually and not theis_option. However that thing applies here. A helper function to find that handle would be better then manually codingg_list_find_customin the functions.Regards
Marcel
so is_proto_handler was casting a 16 bit value to an 8 bit value? Or are you just complaining about having g_list_find_custom in the routines. It would really be easier on me to understand what you are trying to tell me if you you posted your patches to the list next time.
Hi Kristen,
Quoted 25 lines
On Tue, 23 Mar 2010 10:56:00 -0700
Quoted 22 lines · Marcel Holtmann
Hi Kristen,
Quoted 6 lines
Quoted 5 lines
And there was another problem with one variable being guint16, but the
is_optioncasts it back to guint8. We can't really have that. Once you start casting on that scale the compiler will not warn you about type mismatches or if the value of argument is too big for its type.Quoted 8 lines
Can you please let me know which git commit this fix you made was? I want to review it because all of the option types should only be a byte anyway, so I am trying to figure out if there was a mistake somewhere where we were using
is_optionto examine a 16 bit value. I searched through the git log and can't figure out where this change was. I can see where you changed the option type we are comparing to a regular guint to avoid compiler problems, but not the other issue you mentioned.I had a second look at these. It is the
is_proto_handleractually and not theis_option. However that thing applies here. A helper function to find that handle would be better then manually codingg_list_find_customin the functions.
Quoted 8 lines
Quoted 3 lines
Regards
Marcel
so
is_proto_handlerwas casting a 16 bit value to an 8 bit value? Or are
you just complaining about havingg_list_find_customin the routines. It would really be easier on me to understand what you are trying to tell me if you you posted your patches to the list next time.
If you have questions or concerns then the best place to discuss this is on IRC. I don't expect maintainers to post re-factoring patches on the mailing list.
Regards,
-Denis
Hi Kristen,
Quoted 19 lines
Quoted 14 lines
Quoted 6 lines
Quoted 5 lines
And there was another problem with one variable being guint16, but the
is_optioncasts it back to guint8. We can't really have that. Once you start casting on that scale the compiler will not warn you about type mismatches or if the value of argument is too big for its type.Quoted 7 lines
Can you please let me know which git commit this fix you made was? I want to review it because all of the option types should only be a byte anyway, so I am trying to figure out if there was a mistake somewhere where we were using
is_optionto examine a 16 bit value. I searched through the git log and can't figure out where this change was. I can see where you changed the option type we are comparing to a regular guint to avoid compiler problems, but not the other issue you mentioned.Quoted 4 lines
I had a second look at these. It is the
is_proto_handleractually and not theis_option. However that thing applies here. A helper function to find that handle would be better then manually codingg_list_find_customin the functions.
Quoted 4 lines
so
is_proto_handlerwas casting a 16 bit value to an 8 bit value? Or are you just complaining about havingg_list_find_customin the routines. It would really be easier on me to understand what you are trying to tell me if you you posted your patches to the list next time.
I expect you to ensure that your patches compile on 32-bit systems. And also that they work on 32-bit and 64-bit systems. In addition I expect that little endian and big endian works smoothly.
In general I don't wanna have casting in the source since it is a potential trap for errors. Without casting the compiler will warn us if we make mistakes, without we run into troubles. Especially with the different pointer sizes it is important to not cast.
So in this specific cases, I think the usage of g_list_find_custom is not a good idea. Manually walking this in a helper function and ensuring that the variable and parameters types are enforced.
In short summary:
1) No casting if not really really needed. Think twice before adding a casting to the source code.
2) Think about your optimization and understand what you are trying to optimize. Simple code flow is preferred. Only in hot path we should attempt to optimize manually and then it needs to be documented in the source code itself. Otherwise lets GCC do it for us. Walking the GLib list manually is sometimes a lot simpler to read than trying to use foreach type functions.
3) No variable initialization on declaration. There are a few exceptions when it makes sense. However the general rule is not to do it. We want the compiler to warn us about variables that we might use uninitialized. In most cases this indicates a mistake in the code flow and that the code is too complex.
Regards
Marcel
Quoted 30 lines · On Mon, 22 Mar 2010 20:22:02 -0700 Kristen Carlson Accardi…
Quoted 27 lines · On Mon, 22 Mar 2010 19:22:00 -0700 Marcel Holtmann <[email protected]> wrote:
Hi Kristen,
Quoted 7 lines
Quoted 1 line
Changes since v2 - corrected whitespace.
all the patches have been applied.
So form now on please send smaller patches as soon as you have them ready and tested. If you need comments or have questions, you can use the mailing list as well.
some additional comments from my side.
If you have variables that are only valid inside the scope of a statement, then I prefer if you only declare them there. This makes the code a bit simpler to read. Check the patch I just pushed to give you an example.
Also please find access to a 32-bit system if you are running 64-bit or vice versa. Our build system is strict and will turn turn all casting mistakes in an error.
Please be present on #ofono IRC as much as possible so people can report such things. Remember that your code is now part of the tree and it can break the build.
Regards
Quoted 8 lines
Quoted 3 lines
Marcel
Marcel - I just started reviewing the changes you made and the first patch I hit I discovered that you broke something. Would you like to revert the patches and let me review them first, or should I just send a patch to the mailing list to fix what you broke?
Here's the commits to revert:
a09d38643b8da50c8703fd843be26553f294f0bbe396b7d5afcce6d90d5836d57f7b800a1b6b7b52
I'd be glad to clean them up for you later if you like.
Quoted 4 lines · you
If you have variables that are only valid inside the scope of a statement, then I prefer if you only declare them there. This makes the code a bit simpler to read. Check the patch I just pushed to give you an example.
If you're serious about that, you should turn on C99 support. Only then you can use C++-style for-loops.
Signature · 1 line
Rémi Denis-Courmont
Hi Remi,
Quoted 7 lines
Quoted 4 lines
If you have variables that are only valid inside the scope of a statement, then I prefer if you only declare them there. This makes the code a bit simpler to read. Check the patch I just pushed to give you an example.
If you're serious about that, you should turn on C99 support. Only then you can use C++-style for-loops.
I wasn't talking about the iterator variable.
Regards
Marcel