rmnet: Add skeleton
PATCH 1/8 rmnet: Add skeleton
Add skeleton of the RMNet interface management module. Implement the basic API structure and register the module with oFono core.
--- Makefile.am | 2 ++ src/rmnet.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/rmnet.h | 25 +++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 src/rmnet.c create mode 100644 src/rmnet.h
Makefile.am +2 -0
@@ -353,6 +353,8 @@ builtin_sources += plugins/u8500.c endif if QMIMODEM +builtin_sources += src/rmnet.h src/rmnet.c + qmi_sources = drivers/qmimodem/qmi.h drivers/qmimodem/qmi.c \ drivers/qmimodem/ctl.h \ drivers/qmimodem/dms.h \
src/rmnet.c new file +59 -0
59 lines not on this page · raw message
src/rmnet.h new file +25 -0
@@ -0,0 +1,25 @@ +/* +* oFono - Open Source Telephony +* Copyright (C) 2024 Cruise, LLC +* +* SPDX-License-Identifier: LGPL-2.1-or-later +*/ + +struct rmnet_ifinfo { +uint32_t ifindex; +uint16_t mux_id; +char ifname[IF_NAMESIZE ]; +}; + +typedef void (*rmnet_new_interfaces_func_t )(int error, +unsigned int n_interfaces, +const struct rmnet_ifinfo *interfaces, +void *user_data); +typedef void (*rmnet_destroy_func_t )(void *user_data); + +int rmnet_get_interfaces (uint32_t parent_ifindex,unsigned int n_interfaces, +rmnet_new_interfaces_func_t cb, +void *user_data,rmnet_destroy_func_t destroy); +int rmnet_del_interfaces (unsigned int n_interfaces, +const struct rmnet_ifinfo *interfaces); +int rmnet_cancel (int id);
Signature · 1 line
2.47.0
PATCH 2/8 rmnet: Add logic to dump out RMNet interfaces
This logic is triggered at startup to dump RMNet only links. This is accomplished by using RTM_GETLINK dump with a filter based on IFLA_LINKINFO attribute setup for IFLA_INFO_KIND being "rmnet".
For now, links are simply printed and not acted upon.
--- src/rmnet.c | 162 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+)
src/rmnet.c +162 -0
@@ -14,13 +14,19 @@#include <unistd.h> #include <linux/rtnetlink.h> #include <net/if.h> +#include <linux/if_link.h> +#include <linux/if_arp.h> #include <ell/ell.h> #include "ofono.h" #include "rmnet.h" +#define RMNET_TYPE "rmnet" +#define MAX_MUX_IDS 254U +static struct l_netlink *rtnl; +static uint32_t dump_id; int rmnet_get_interfaces(uint32_t parent_ifindex, unsigned int n_interfaces, rmnet_new_interfaces_func_t cb,
@@ -40,15 +46,171 @@ int rmnet_cancel(int id)return -ENOTSUP ; } +static int rmnet_parse_info_data (struct l_netlink_attr *linkinfo, +uint16_t *out_mux_id) +{ +struct l_netlink_attr info_data; +bool have_info_data = false; +uint16_t rta_type; +uint16_t rta_len; +const void *rta_data; +uint16_t mux_id; + +while (!l_netlink_attr_next (linkinfo, &rta_type, &rta_len, &rta_data)) { +switch (rta_type) { +case IFLA_INFO_KIND : +if (strncmp (rta_data,RMNET_TYPE , rta_len)) +return -EPROTOTYPE ; + +break ; +case IFLA_INFO_DATA : +if (l_netlink_attr_recurse (linkinfo, &info_data) <0 ) +return -EBADMSG ; + + have_info_data = true; +break ; + } + } + +if (!have_info_data) +return -ENOENT ; + +while (!l_netlink_attr_next (&info_data, + &rta_type, &rta_len, &rta_data)) { +if (rta_type !=IFLA_RMNET_MUX_ID ) +continue ; + +if (rta_len !=sizeof (uint16_t )) +return -EBADMSG ; + + mux_id =l_get_u16 (rta_data); +if (mux_id >MAX_MUX_IDS || !mux_id) +return -ERANGE ; + +if (out_mux_id) + *out_mux_id = mux_id; + +return 0 ; + } + +return -ENOENT ; +} + +static int rmnet_parse_link (const void *data,uint32_t len, +char *out_ifname, +uint32_t *out_ifindex, +uint16_t *out_mux_id) +{ +const struct ifaddrmsg *ifa = data; +struct l_netlink_attr attr; +struct l_netlink_attr linkinfo; +bool have_linkinfo = false; +const char *ifname =NULL ; +uint16_t ifnamelen =0 ; +uint16_t rta_type; +uint16_t rta_len; +const void *rta_data; +int r; + +if (l_netlink_attr_init (&attr,sizeof (struct ifinfomsg ), + data, len) <0 ) +return -EBADMSG ; + +while (!l_netlink_attr_next (&attr, &rta_type, &rta_len, &rta_data)) { +switch (rta_type) { +case IFLA_IFNAME : + ifname = rta_data; + ifnamelen = rta_len; +break ; +case IFLA_LINKINFO : +if (l_netlink_attr_recurse (&attr, &linkinfo) <0 ) +return -EBADMSG ; + + have_linkinfo = true; +break ; + } + } + +if (!have_linkinfo || !ifname || !ifnamelen) +return -ENOENT ; + + r =rmnet_parse_info_data (&linkinfo, out_mux_id); +if (r <0 ) +return r; + +if (out_ifname) +l_strlcpy (out_ifname, ifname,MIN (ifnamelen +1 ,IF_NAMESIZE )); + +if (out_ifindex) + *out_ifindex = ifa->ifa_index; + +return 0 ; +} + +static void rmnet_link_dump_destroy (void *user_data) +{ + dump_id =0 ; +} + +static void rmnet_link_dump_cb (int error, +uint16_t type,const void *data, +uint32_t len,void *user_data) +{ +struct rmnet_ifinfo info; + +/* Check conditions that can't happen on a dump */ +if (error || type !=RTM_NEWLINK ) +return ; + +if (rmnet_parse_link (data, len, + info.ifname, &info.ifindex, &info.mux_id) <0 ) +return ; + +DBG ("Existing rmnet link: %s(%u) mux_id: %u" , + info.ifname, info.ifindex, info.mux_id); +} + +static int rmnet_link_dump () +{ +struct ifinfomsg ifi; +struct l_netlink_message *nlm = +l_netlink_message_new_sized (RTM_GETLINK ,NLM_F_DUMP , +sizeof (ifi)); + +memset (&ifi,0 ,sizeof (ifi)); +l_netlink_message_add_header (nlm, &ifi,sizeof (ifi)); + +l_netlink_message_enter_nested (nlm,IFLA_LINKINFO ); +l_netlink_message_append_string (nlm,IFLA_INFO_KIND ,RMNET_TYPE ); +l_netlink_message_leave_nested (nlm); + + dump_id =l_netlink_send (rtnl, nlm, rmnet_link_dump_cb,NULL , + rmnet_link_dump_destroy); +if (dump_id >0 ) +return 0 ; + +l_netlink_message_unref (nlm); +return -EIO ; +} +static int rmnet_init (void ) { +int r; +DBG ("" ); rtnl =l_netlink_new (NETLINK_ROUTE );if (!rtnl)return -EIO ; + r =rmnet_link_dump (); +if (r <0 ) + goto dump_failed; +return 0 ; +dump_failed: +l_netlink_destroy (rtnl); +return r; }static void rmnet_exit (void )
Signature · 1 line
2.47.0
PATCH 3/8 rmnet: Track link notifications
In reply to Denis KenziorTrack link notifications that arrive via RTM_NEWLINK and RTM_DELLINK. This will be used in the future to try to de-conflict use of RMNet mux_ids that might have been (unlikely) created by other processes.
--- src/rmnet.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
src/rmnet.c +22 -0
@@ -27,6 +27,7 @@static struct l_netlink *rtnl;static uint32_t dump_id; +static uint32_t link_notify_id; int rmnet_get_interfaces(uint32_t parent_ifindex, unsigned int n_interfaces, rmnet_new_interfaces_func_t cb,
@@ -193,6 +194,23 @@ static int rmnet_link_dump()return -EIO ; } +static void rmnet_link_notification (uint16_t type,const void *data, +uint32_t len,void *user_data) +{ +char ifname[IF_NAMESIZE ]; +uint16_t mux_id; +uint32_t ifindex; + +if (type !=RTM_NEWLINK && type !=RTM_DELLINK ) +return ; + +if (rmnet_parse_link (data, len, ifname, &ifindex, &mux_id) <0 ) +return ; + +DBG ("link_notification: %s(%u) with mux_id: %u" , + ifname, ifindex, mux_id); +} +static int rmnet_init (void ) {int r;
@@ -207,6 +225,9 @@ static int rmnet_init(void)if (r <0 ) goto dump_failed; + link_notify_id =l_netlink_register (rtnl,RTNLGRP_LINK , + rmnet_link_notification,NULL ,NULL ); +return 0 ; dump_failed:l_netlink_destroy (rtnl);
@@ -215,6 +236,7 @@ dump_failed:static void rmnet_exit (void ) { +l_netlink_unregister (rtnl, link_notify_id);l_netlink_destroy (rtnl); }
Signature · 1 line
2.47.0
PATCH 4/8 rmnet: Track used mux ids
In reply to Denis KenziorTrack used mux identifiers. This uintset can later be used to allocate unused mux identifiers.
--- src/rmnet.c | 9 +++++++++ 1 file changed, 9 insertions(+)
src/rmnet.c +9 -0
@@ -28,6 +28,7 @@static struct l_netlink *rtnl;static uint32_t dump_id;static uint32_t link_notify_id; +static struct l_uintset *mux_ids; int rmnet_get_interfaces(uint32_t parent_ifindex, unsigned int n_interfaces, rmnet_new_interfaces_func_t cb,
@@ -169,6 +170,7 @@ static void rmnet_link_dump_cb(int error,DBG ("Existing rmnet link: %s(%u) mux_id: %u" , info.ifname, info.ifindex, info.mux_id); +l_uintset_put (mux_ids, info.mux_id); }static int rmnet_link_dump ()
@@ -207,6 +209,11 @@ static void rmnet_link_notification(uint16_t type, const void *data,if (rmnet_parse_link (data, len, ifname, &ifindex, &mux_id) <0 )return ; +if (type ==RTM_NEWLINK ) +l_uintset_put (mux_ids, mux_id); +else +l_uintset_take (mux_ids, mux_id); +DBG ("link_notification: %s(%u) with mux_id: %u" , ifname, ifindex, mux_id); }
@@ -227,6 +234,7 @@ static int rmnet_init(void) link_notify_id =l_netlink_register (rtnl,RTNLGRP_LINK , rmnet_link_notification,NULL ,NULL ); + mux_ids =l_uintset_new_from_range (1 ,MAX_MUX_IDS );return 0 ; dump_failed:
@@ -236,6 +244,7 @@ dump_failed:static void rmnet_exit (void ) { +l_uintset_free (mux_ids);l_netlink_unregister (rtnl, link_notify_id);l_netlink_destroy (rtnl); }
Signature · 1 line
2.47.0
PATCH 5/8 rmnet: Delete stale RMnet links at startup
In reply to Denis KenziorMost likely such links could be left over from ofono not exiting cleanly. There's unfortunately no easy way to mark links as belonging to a particular process, so remove all of them.
--- src/rmnet.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 118 insertions(+), 1 deletion(-)
src/rmnet.c +118 -1
@@ -25,10 +25,118 @@#define RMNET_TYPE "rmnet"#define MAX_MUX_IDS 254U +struct rmnet_request { +uint32_t parent_ifindex; +rmnet_new_interfaces_func_t new_cb; +void *user_data; +rmnet_destroy_func_t destroy; +int id; +uint32_t netlink_id; +uint16_t request_type; +uint8_t current; +uint8_t n_interfaces; +struct rmnet_ifinfo infos[]; +}; +static struct l_netlink *rtnl;static uint32_t dump_id;static uint32_t link_notify_id;static struct l_uintset *mux_ids; +struct l_queue *request_q; + +static void rmnet_request_free (struct rmnet_request *req) +{ +if (req->destroy) + req->destroy (req->user_data); + +l_free (req); +} + +static struct rmnet_request *__rmnet_del_request_new (unsigned int n_interfaces, +const struct rmnet_ifinfo *interfaces) +{ +struct rmnet_request *req; + + req =l_malloc (sizeof (struct rmnet_request ) + +sizeof (struct rmnet_ifinfo ) * n_interfaces); +memset (req,0 ,sizeof (struct rmnet_request )); + req->request_type =RTM_DELLINK ; + req->n_interfaces = n_interfaces; +memcpy (req->infos, interfaces, +sizeof (struct rmnet_ifinfo ) * n_interfaces); + +return req; +} + +static int rmnet_link_del (uint32_t ifindex,l_netlink_command_func_t cb, +void *userdata,l_netlink_destroy_func_t destroy, +uint32_t *out_command_id) +{ +struct l_netlink_message *nlm = +l_netlink_message_new (RTM_DELLINK ,0 ); +struct ifinfomsg ifi; +uint32_t id; + +memset (&ifi,0 ,sizeof (ifi)); + ifi.ifi_family =AF_UNSPEC ; + ifi.ifi_index = ifindex; + +l_netlink_message_add_header (nlm, &ifi,sizeof (ifi)); + + id =l_netlink_send (rtnl, nlm, cb, userdata, destroy); +if (!id) { +l_netlink_message_unref (nlm); +return -EIO ; + } + +if (out_command_id) + *out_command_id = id; + +return 0 ; +} + +static void rmnet_start_next_request (); + +static void rmnet_del_link_cb (int error,uint16_t type,const void *data, +uint32_t len,void *user_data) +{ +struct rmnet_request *req =l_queue_peek_head (request_q); + +DBG ("DELLINK %u (%u/%u) complete, error: %d" , + req->netlink_id, req->current, req->n_interfaces, error); + + req->netlink_id =0 ; + req->current +=1 ; + +if (req->current < req->n_interfaces) + goto next_request; + +l_queue_pop_head (request_q); +rmnet_request_free (req); + +next_request: +if (l_queue_length (request_q) >0 ) +rmnet_start_next_request (); +} + +static void rmnet_start_next_request () +{ +struct rmnet_request *req =l_queue_peek_head (request_q); + +if (!req) +return ; + +if (req->request_type ==RTM_DELLINK ) { +uint32_t ifindex = req->infos[req->current].ifindex; + +L_WARN_ON (rmnet_link_del (ifindex, rmnet_del_link_cb,NULL ,NULL , + &req->netlink_id) <0 ); +DBG ("Start DELLINK: ifindex: %u, interface: %u/%u, request: %u" , + ifindex, req->current, + req->n_interfaces, req->netlink_id); +return ; + } +} int rmnet_get_interfaces(uint32_t parent_ifindex, unsigned int n_interfaces, rmnet_new_interfaces_func_t cb,
@@ -152,6 +260,9 @@ static int rmnet_parse_link(const void *data, uint32_t len,static void rmnet_link_dump_destroy (void *user_data) { dump_id =0 ; + +if (l_queue_length (request_q) >0 ) +rmnet_start_next_request (); } static void rmnet_link_dump_cb(int error,
@@ -159,6 +270,7 @@ static void rmnet_link_dump_cb(int error, uint32_t len, void *user_data) { struct rmnet_ifinfo info; +struct rmnet_request *req;/* Check conditions that can't happen on a dump */ if (error || type !=RTM_NEWLINK )
@@ -168,9 +280,12 @@ static void rmnet_link_dump_cb(int error, info.ifname, &info.ifindex, &info.mux_id) < 0) return; -DBG ("Existing rmnet link: %s(%u) mux_id: %u" , +DBG ("Removing existing rmnet link: %s(%u) mux_id: %u" , info.ifname, info.ifindex, info.mux_id);l_uintset_put (mux_ids, info.mux_id); + + req =__rmnet_del_request_new (1 , &info); +l_queue_push_tail (request_q, req); }static int rmnet_link_dump ()
@@ -235,6 +350,7 @@ static int rmnet_init(void) link_notify_id =l_netlink_register (rtnl,RTNLGRP_LINK , rmnet_link_notification,NULL ,NULL ); mux_ids =l_uintset_new_from_range (1 ,MAX_MUX_IDS ); + request_q =l_queue_new ();return 0 ; dump_failed:
@@ -244,6 +360,7 @@ dump_failed:static void rmnet_exit (void ) { +l_queue_destroy (request_q, (l_queue_destroy_func_t ) rmnet_request_free);l_uintset_free (mux_ids);l_netlink_unregister (rtnl, link_notify_id);l_netlink_destroy (rtnl);
Signature · 1 line
2.47.0
PATCH 6/8 rmnet: Implement rmnet_del_interfaces
In reply to Denis KenziorAdd implementation for rmnet_del_interfaces. This method will remove the interfaces based on the passed in struct rmnet_ifinfo array.
--- src/rmnet.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
src/rmnet.c +12 -1
@@ -148,7 +148,18 @@ int rmnet_get_interfaces(uint32_t parent_ifindex, unsigned int n_interfaces,int rmnet_del_interfaces (unsigned int n_interfaces,const struct rmnet_ifinfo *interfaces) { -return -ENOTSUP ; +struct rmnet_request *req; + +if (!n_interfaces || n_interfaces >MAX_MUX_IDS ) +return -EINVAL ; + + req =__rmnet_del_request_new (n_interfaces, interfaces); +l_queue_push_tail (request_q, req); + +if (l_queue_length (request_q) ==1 && !dump_id) +rmnet_start_next_request (); + +return 0 ; }int rmnet_cancel (int id)
Signature · 1 line
2.47.0
PATCH 7/8 rmnet: Implement getting new interfaces
In reply to Denis KenziorAdd method to create N rmnet interfaces for use by the gobi driver. The rmnet interfaces are created in sequence, which should result in sequential mux ids and interface names to be created (assuming no other process creates rmnet interfaces in the background).
For now we hardcode the use of QMAPv5 as the aggregation protocol using EGRESS_MAP_CHKSUMV5 and INGRESS_MAP_CHKSUMV5. Support for QMAPv4 or QMAP is also possible in the future, but no devices are currently available for testing.
--- src/rmnet.c | 164 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 161 insertions(+), 3 deletions(-)
src/rmnet.c +161 -3
@@ -12,6 +12,7 @@#include <stddef.h> #include <errno.h> #include <unistd.h> +#include <stdio.h> #include <linux/rtnetlink.h> #include <net/if.h> #include <linux/if_link.h>
@@ -43,6 +44,7 @@ static uint32_t dump_id;static uint32_t link_notify_id;static struct l_uintset *mux_ids;struct l_queue *request_q; +static int next_request_id =1 ;static void rmnet_request_free (struct rmnet_request *req) {
@@ -95,6 +97,57 @@ static int rmnet_link_del(uint32_t ifindex, l_netlink_command_func_t cb,return 0 ; } +static int rmnet_link_new (uint32_t parent_ifindex,uint8_t mux_id, +const char ifname[static IF_NAMESIZE ], +l_netlink_command_func_t cb, +void *userdata, +l_netlink_destroy_func_t destroy, +uint32_t *out_command_id) +{ +struct ifinfomsg ifi; +struct l_netlink_message *nlm = +l_netlink_message_new (RTM_NEWLINK ,NLM_F_EXCL |NLM_F_CREATE ); +struct ifla_rmnet_flags flags; +uint32_t id; + +memset (&ifi,0 ,sizeof (ifi)); + ifi.ifi_family =AF_UNSPEC ; + ifi.ifi_type =ARPHRD_RAWIP ; + ifi.ifi_flags =0 ; + ifi.ifi_change =0xFFFFFFFF ; + +l_netlink_message_add_header (nlm, &ifi,sizeof (ifi)); +l_netlink_message_append_u32 (nlm,IFLA_LINK , parent_ifindex); +l_netlink_message_append_string (nlm,IFLA_IFNAME , ifname); + +l_netlink_message_enter_nested (nlm,IFLA_LINKINFO ); +l_netlink_message_append_string (nlm,IFLA_INFO_KIND ,RMNET_TYPE ); +l_netlink_message_enter_nested (nlm,IFLA_INFO_DATA ); +l_netlink_message_append_u16 (nlm,IFLA_RMNET_MUX_ID , mux_id); + flags.flags =RMNET_FLAGS_INGRESS_DEAGGREGATION | +RMNET_FLAGS_INGRESS_MAP_CKSUMV5 | +RMNET_FLAGS_EGRESS_MAP_CKSUMV5 ; + flags.mask =RMNET_FLAGS_EGRESS_MAP_CKSUMV4 | +RMNET_FLAGS_INGRESS_MAP_CKSUMV4 | +RMNET_FLAGS_EGRESS_MAP_CKSUMV5 | +RMNET_FLAGS_INGRESS_MAP_CKSUMV5 | +RMNET_FLAGS_INGRESS_DEAGGREGATION ; +l_netlink_message_append (nlm,IFLA_RMNET_FLAGS , &flags,sizeof (flags)); +l_netlink_message_leave_nested (nlm); +l_netlink_message_leave_nested (nlm); + + id =l_netlink_send (rtnl, nlm, cb, userdata, destroy); +if (!id) { +l_netlink_message_unref (nlm); +return -EIO ; + } + +if (out_command_id) + *out_command_id = id; + +return 0 ; +} +static void rmnet_start_next_request (); static void rmnet_del_link_cb(int error, uint16_t type, const void *data,
@@ -119,9 +172,54 @@ next_request:rmnet_start_next_request (); } +static void rmnet_new_link_cb (int error,uint16_t type,const void *data, +uint32_t len,void *user_data) +{ +struct rmnet_request *req =l_queue_peek_head (request_q); + +DBG ("NEWLINK %u (%u/%u) complete, error: %d" , + req->netlink_id, req->current +1 , req->n_interfaces, error); + + req->netlink_id =0 ; + +if (!error) + req->current +=1 ; + +if (error) { +if (req->current >0 ) { +struct rmnet_request *del_req = +__rmnet_del_request_new (req->current, + req->infos); + +l_queue_push_head (request_q, del_req); + } + + req->n_interfaces =0 ; + goto finish_request; + } + +if (req->current < req->n_interfaces) + goto next_request; + +finish_request: +l_queue_pop_head (request_q); + +if (req->new_cb) + req->new_cb (error, req->n_interfaces, + req->n_interfaces ? req->infos :NULL , + req->user_data); + +rmnet_request_free (req); +next_request: +if (l_queue_length (request_q) >0 ) +rmnet_start_next_request (); +} +static void rmnet_start_next_request () {struct rmnet_request *req =l_queue_peek_head (request_q); +uint32_t mux_id; +struct rmnet_ifinfo *info;if (!req)return ;
@@ -136,13 +234,55 @@ static void rmnet_start_next_request() req->n_interfaces, req->netlink_id);return ; } + + info = req->infos + req->current; + mux_id =l_uintset_find_unused_min (mux_ids); + info->mux_id = mux_id; +sprintf (info->ifname,RMNET_TYPE "%u" , mux_id -1 ); + +L_WARN_ON (rmnet_link_new (req->parent_ifindex, mux_id, info->ifname, + rmnet_new_link_cb,NULL ,NULL , + &req->netlink_id) <0 ); + +DBG ("Start NEWLINK: parent: %u, interface: %u/%u, request: %u" , + req->parent_ifindex, req->current +1 , + req->n_interfaces, req->netlink_id); }int rmnet_get_interfaces (uint32_t parent_ifindex,unsigned int n_interfaces,rmnet_new_interfaces_func_t cb,void *user_data,rmnet_destroy_func_t destroy) { -return -ENOTSUP ; +struct rmnet_request *req; + +if (!n_interfaces || n_interfaces >MAX_MUX_IDS ) +return -EINVAL ; + +if (l_uintset_size (mux_ids) >MAX_MUX_IDS - n_interfaces) +return -ENOSPC ; + + req =l_malloc (sizeof (struct rmnet_request ) + +sizeof (struct rmnet_ifinfo ) * n_interfaces); + req->parent_ifindex = parent_ifindex; + req->new_cb = cb; + req->user_data = user_data; + req->destroy = destroy; + req->id = next_request_id++; + req->request_type =RTM_NEWLINK ; + req->netlink_id =0 ; + req->current =0 ; + req->n_interfaces = n_interfaces; +memset (req->infos,0 ,sizeof (struct rmnet_ifinfo ) * n_interfaces); + +if (next_request_id <0 ) + next_request_id =1 ; + +l_queue_push_tail (request_q, req); + +if (l_queue_length (request_q) ==1 && !dump_id) +rmnet_start_next_request (); + +return req->id; } int rmnet_del_interfaces(unsigned int n_interfaces,
@@ -322,6 +462,23 @@ static int rmnet_link_dump()return -EIO ; } +/* For NEW_LINK requests, the ifindex comes in the multicast message */ +static void update_new_link_ifindex (uint16_t mux_id, +const char ifname[static IF_NAMESIZE ], +uint32_t ifindex) +{ +struct rmnet_request *req; +struct rmnet_ifinfo *info; + + req =l_queue_peek_head (request_q); +if (!req || req->request_type !=RTM_NEWLINK ) +return ; + + info = req->infos + req->current; +if (info->mux_id == mux_id && !strcmp (info->ifname, ifname)) + info->ifindex = ifindex; +} +static void rmnet_link_notification (uint16_t type,const void *data,uint32_t len,void *user_data) {
@@ -335,9 +492,10 @@ static void rmnet_link_notification(uint16_t type, const void *data,if (rmnet_parse_link (data, len, ifname, &ifindex, &mux_id) <0 )return ; -if (type ==RTM_NEWLINK ) +if (type ==RTM_NEWLINK ) {l_uintset_put (mux_ids, mux_id); -else +update_new_link_ifindex (mux_id, ifname, ifindex); + }else l_uintset_take (mux_ids, mux_id); DBG("link_notification: %s(%u) with mux_id: %u",
Signature · 1 line
2.47.0
PATCH 8/8 rmnet: Implement cancel
In reply to Denis KenziorImplement cancelation of an ongoing rmnet request. Any links that have already been created are deleted by putting another request to the head of the queue.
--- src/rmnet.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 2 deletions(-)
src/rmnet.c +67 -2
@@ -32,6 +32,7 @@ struct rmnet_request {void *user_data;rmnet_destroy_func_t destroy;int id; +bool canceled;uint32_t netlink_id;uint16_t request_type;uint8_t current;
@@ -54,6 +55,14 @@ static void rmnet_request_free(struct rmnet_request *req)l_free (req); } +static bool rmnet_request_id_matches (const void *a,const void *b) +{ +const struct rmnet_request *req = a; +int id =L_PTR_TO_INT (b); + +return req->id == id; +} +static struct rmnet_request *__rmnet_del_request_new (unsigned int n_interfaces,const struct rmnet_ifinfo *interfaces) {
@@ -185,7 +194,7 @@ static void rmnet_new_link_cb(int error, uint16_t type, const void *data,if (!error) req->current +=1 ; -if (error) { +if (error || req->canceled) {if (req->current >0 ) {struct rmnet_request *del_req = __rmnet_del_request_new(req->current,
@@ -268,6 +277,7 @@ int rmnet_get_interfaces(uint32_t parent_ifindex, unsigned int n_interfaces, req->user_data = user_data; req->destroy = destroy; req->id = next_request_id++; + req->canceled = false; req->request_type =RTM_NEWLINK ; req->netlink_id =0 ; req->current =0 ;
@@ -304,7 +314,62 @@ int rmnet_del_interfaces(unsigned int n_interfaces,int rmnet_cancel (int id) { -return -ENOTSUP ; +struct rmnet_request *req; + + req =l_queue_peek_head (request_q); +if (!req) +return -ENOENT ; + +/* Simple Case: Request not yet started (not queue head) */ +if (req->id != id) { + req =l_queue_remove_if (request_q, rmnet_request_id_matches, +L_INT_TO_PTR (id)); +if (!req) +return -ENOENT ; + +DBG ("Removing non-head of queue request %u" , id); +rmnet_request_free (req); +return 0 ; + } + +/* Harder Case: In progress, but the next request not in flight */ +if (!l_netlink_request_sent (rtnl, req->netlink_id)) { +DBG ("Removing in-progress request (not in flight) %u" , id); + req =l_queue_pop_head (request_q); +l_netlink_cancel (rtnl, req->netlink_id); + +if (req->current >0 ) { +struct rmnet_request *del_req = +__rmnet_del_request_new (req->current, + req->infos); + +l_queue_push_head (request_q, del_req); + } + +rmnet_request_free (req); + +if (l_queue_length (request_q)) +rmnet_start_next_request (); + +return 0 ; + } + +/* +* Hardest Case: In progress, next request in flight +* We have to wait until the next callback since the ifindex won't be +* known until then. +*/ +if (req->destroy) + req->destroy (req->user_data); + + req->new_cb =NULL ; + req->destroy =NULL ; + req->user_data =NULL ; + +DBG ("Setting canceled on in-progress request %u" , id); + req->canceled = true; + +return 0 ; } static int rmnet_parse_info_data(struct l_netlink_attr *linkinfo,
Signature · 1 line
2.47.0
Hi Denis,
Quoted 20 lines
Add skeleton of the RMNet interface management module. Implement the basic API structure and register the module with oFono core.
---Makefile.am | 2 ++ src/rmnet.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/rmnet.h | 25 +++++++++++++++++++++++ 3 files changed, 86 insertions(+)create mode 100644
src/rmnet.c
create mode 100644src/rmnet.hMakefile.am +0
-0@@ -353,6 +353,8 @@ builtin_sources += plugins/u8500.cendif
if QMIMODEM
Makefile.am +2
-0+builtin_sources += src/rmnet.h src/rmnet.c +
Quoted 3 lines
qmi_sources=drivers/qmimodem/qmi.hdrivers/qmimodem/qmi.c\drivers/qmimodem/ctl.h\drivers/qmimodem/dms.h\
does this make really sense? Putting this into drivers/qmimodem/rmnet.c is not possible?
We might actually need a generic abstraction for del_interface / add_interface and allow for drivers to register their implementation for it, but that is a different story.
Regards
Marcel
Hi Marcel,
Quoted 3 lines
does this make really sense? Putting this into
drivers/qmimodem/rmnet.cis not possible?
I switched most of the atom drivers to use the OFONO_ATOM_DRIVER_BUILTIN macro. The drivers that performed static initialization during 'plugin_init' using OFONO_PLUGIN_DEFINE went *poof*, including qmimodem. Only individual atom drivers remain. There is one straggler, namely drivers/stemodem/stemodem.c. That one does something somewhat similar in drivers/stemodem/caif_rtnl.c.
Similarly, for modem drivers, OFONO_MODEM_DRIVER_BUILTIN was introduced. This leaves only a few users of OFONO_PLUGIN_DEFINE. Longer term I'd like to get rid of the whole plugin concept. However, it still leaves the open question of what to do with code that requires plugin_init / plugin_exit style static initialization. Easiest way is to convert such users to core modules, like I do with rmnet here, but I'm open to suggestions.
Quoted 1 line
We might actually need a generic abstraction for
del_interface/add_interfaceand allow for drivers to register their implementation for it, but that is a different story.
Yes, true. This will surely come up with MBIM.
On another note, I was thinking of eventually moving transport implementations into src/ or transport/ to allow easier mixing, e.g. running QMI over MBIM, or AT commands over QMI, etc.
Regards,
-Denis