stemodem: Add RTNL functionality managing CAIF Network Interfaces.
PATCH v5 1/1 stemodem: Add RTNL functionality managing CAIF Network Interfaces.
From: Sjur Brændeland <[email protected]>
--- Makefile.am | 2 + drivers/stemodem/caif_rtnl.c | 340 ++++++++++++++++++++++++++++++++++++++++++ drivers/stemodem/caif_rtnl.h | 29 ++++ 3 files changed, 371 insertions(+), 0 deletions(-) create mode 100644 drivers/stemodem/caif_rtnl.c create mode 100644 drivers/stemodem/caif_rtnl.h
Makefile.am +2 -0
@@ -226,6 +226,8 @@ builtin_sources += drivers/atmodem/atutil.h \ drivers/stemodem/stemodem.c \ drivers/stemodem/voicecall.c \ drivers/stemodem/radio-settings.c \ + drivers/stemodem/caif_rtnl.c \ + drivers/stemodem/caif_rtnl.h \ drivers/stemodem/gprs-context.c \ drivers/stemodem/caif_socket.h \ drivers/stemodem/if_caif.h
drivers/stemodem/caif_rtnl.c new file +340 -0
340 lines not on this page · raw message
drivers/stemodem/caif_rtnl.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* +* oFono - Open Source Telephony +* +* Copyright (C) 2010 ST-Ericsson AB. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program 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 General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +* +*/ +typedef void (*caif_rtnl_create_cb_t ) (int ifindex,char *ifname, +void *user_data); + +extern int caif_rtnl_create_interface (int type,int connid,int loop, +caif_rtnl_create_cb_t cb,void *user_data); +extern int caif_rtnl_delete_interface (int ifid); + +extern int caif_rtnl_init (void ); +extern void caif_rtnl_exit (void );
Signature · 1 line
1.6.3.3
Hi Sjur,
Quoted 6 lines
Makefile.am | 2 + drivers/stemodem/caif_rtnl.c | 340 ++++++++++++++++++++++++++++++++++++++++++ drivers/stemodem/caif_rtnl.h | 29 ++++ 3 files changed, 371 insertions(+), 0 deletions(-) create mode 100644 drivers/stemodem/caif_rtnl.c create mode 100644 drivers/stemodem/caif_rtnl.h
I applied this patch now, but I had to fix this up a bit. You have to send a patch that updates this one.
drivers/stemodem/caif_rtnl.c line 50
Quoted 7 lines
drivers/stemodem/caif_rtnl.c new file +7
-0+#define RTNL_MSG_SIZE 4096 + +struct rtnl_msg { +struct nlmsghdr n; +struct ifinfomsg i; +char data[RTNL_MSG_SIZE ]; +};
Is this not a bit big?
drivers/stemodem/caif_rtnl.c line 53
Quoted 2 lines
drivers/stemodem/caif_rtnl.c new file +2
-0+struct iplink_req { +guint32 rtnlmsg_seqnr;
Use the proper nlmsg_seqnr type that you get from RTNL.
drivers/stemodem/caif_rtnl.c line 54
Quoted 1 line
drivers/stemodem/caif_rtnl.c new file +1
-0+gpointer user_data;
Use void * here since your callback does as well.
drivers/stemodem/caif_rtnl.c line 64
Quoted 10 lines
drivers/stemodem/caif_rtnl.c new file +10
-0+caif_rtnl_create_cb_t callback; +}; + +static GSList *pending_requests; +static guint32 rtnl_seqnr; +static guint rtnl_watch; +static GIOChannel *rtnl_channel; + +static struct iplink_req *find_request (guint32 seq) +{
seq should match RTNL given type.
Quoted 26 lines
drivers/stemodem/caif_rtnl.c new file +26
-0+GSList *list; + +for (list = pending_requests; list; list = list->next) { +struct iplink_req *req = list->data; + +if (req->rtnlmsg_seqnr == seq) +return req; + } + +return NULL ; +} + +static void parse_newlink_param (struct ifinfomsg *msg,int size, +int *ifindex,char *ifname) +{ +struct rtattr *attr; + +for (attr =IFLA_RTA (msg);RTA_OK (attr, size); + attr =RTA_NEXT (attr, size)) { + +if (attr->rta_type ==IFLA_IFNAME && + ifname !=NULL ) { + +strncpy (ifname,RTA_DATA (attr),IF_NAMESIZE ); + ifname[IF_NAMESIZE -1 ] ='\0' ; +break ;
drivers/stemodem/caif_rtnl.c line 100
Quoted 10 lines
drivers/stemodem/caif_rtnl.c new file +10
-0+ } + } + + *ifindex = msg->ifi_index; +} + +static void parse_rtnl_message (const void *buf,size_t len) +{ +struct ifinfomsg *msg; +struct iplink_req *req =NULL ;
This is bad. Please only do assignment if there is no other way around it. I fixed this for you.
Regards
Marcel