8 #define pr_fmt(fmt) KBUILD_MODNAME ":%s(): " fmt, __func__
13 #include <linux/module.h>
14 #include <linux/netdevice.h>
15 #include <linux/if_ether.h>
18 #include <linux/sched.h>
27 #define GPRS_PDP_MTU 1500
29 #define CONNECT_TIMEOUT (5 * HZ)
30 #define CAIF_NET_DEFAULT_QUEUE_LEN 500
31 #define UNDEF_CONNID 0xffffffff
59 static void robust_list_del(
struct list_head *delete_node)
65 if (list_node == delete_node) {
73 static int chnl_recv_cb(
struct cflayer *layr,
struct cfpkt *pkt)
96 ip_version = skb_header_pointer(skb, 0, 1, &buf);
102 switch (*ip_version >> 4) {
111 priv->
netdev->stats.rx_errors++;
127 priv->
netdev->stats.rx_packets++;
137 unregister_netdevice(dev->
netdev);
157 static void chnl_hold(
struct cflayer *lyr)
163 static void chnl_put(
struct cflayer *lyr)
173 pr_debug(
"NET flowctrl func called flow: %s\n",
180 "REMOTE_SHUTDOWN" :
"UKNOWN CTRL COMMAND");
187 netif_stop_queue(priv->
netdev);
198 netif_tx_disable(priv->
netdev);
203 netif_wake_queue(priv->
netdev);
209 netif_wake_queue(priv->
netdev);
224 priv = netdev_priv(dev);
227 pr_warn(
"Size of skb exceeded MTU\n");
229 dev->
stats.tx_errors++;
234 pr_debug(
"dropping packets flow off\n");
236 dev->
stats.tx_dropped++;
249 result = priv->
chnl.dn->transmit(priv->
chnl.dn, pkt);
251 dev->
stats.tx_dropped++;
256 dev->
stats.tx_packets++;
257 dev->
stats.tx_bytes += len;
262 static int chnl_net_open(
struct net_device *dev)
266 int llifindex, headroom, tailroom, mtu;
269 priv = netdev_priv(dev);
271 pr_debug(
"chnl_net_open: no priv\n");
278 &priv->
chnl, &llifindex,
279 &headroom, &tailroom);
282 "Unable to register and open device,"
307 mtu =
min_t(
int, dev->
mtu, lldev->
mtu - (headroom + tailroom));
313 pr_warn(
"CAIF Interface MTU too small (%d)\n", mtu);
328 pr_debug(
"wait_event_interruptible woken by a signal\n");
347 pr_debug(
"CAIF Netdevice connected\n");
358 static int chnl_net_stop(
struct net_device *dev)
363 priv = netdev_priv(dev);
369 static int chnl_net_init(
struct net_device *dev)
373 priv = netdev_priv(dev);
378 static void chnl_net_uninit(
struct net_device *dev)
382 priv = netdev_priv(dev);
387 .ndo_open = chnl_net_open,
388 .ndo_stop = chnl_net_stop,
389 .ndo_init = chnl_net_init,
390 .ndo_uninit = chnl_net_uninit,
391 .ndo_start_xmit = chnl_net_start_xmit,
394 static void chnl_net_destructor(
struct net_device *dev)
396 struct chnl_net *priv = netdev_priv(dev);
401 static void ipcaif_net_setup(
struct net_device *dev)
411 priv = netdev_priv(dev);
412 priv->
chnl.receive = chnl_recv_cb;
413 priv->
chnl.ctrlcmd = chnl_flowctrl_cb;
430 priv = netdev_priv(dev);
432 priv->
conn_req.sockaddr.u.dgm.connection_id) ||
434 priv->
conn_req.sockaddr.u.dgm.connection_id))
435 goto nla_put_failure;
438 goto nla_put_failure;
445 static void caif_netlink_parms(
struct nlattr *
data[],
449 pr_warn(
"no params data found\n");
453 conn_req->
sockaddr.u.dgm.connection_id =
454 nla_get_u32(data[IFLA_CAIF_IPV4_CONNID]);
456 conn_req->
sockaddr.u.dgm.connection_id =
457 nla_get_u32(data[IFLA_CAIF_IPV6_CONNID]);
459 if (nla_get_u8(data[IFLA_CAIF_LOOPBACK]))
466 static int ipcaif_newlink(
struct net *src_net,
struct net_device *dev,
472 caifdev = netdev_priv(dev);
473 caif_netlink_parms(data, &caifdev->
conn_req);
474 dev_net_set(caifdev->
netdev, src_net);
478 pr_warn(
"device rtml registration failed\n");
480 list_add(&caifdev->
list_field, &chnl_net_list);
495 caifdev = netdev_priv(dev);
496 caif_netlink_parms(data, &caifdev->
conn_req);
501 static size_t ipcaif_get_size(
const struct net_device *dev)
522 .priv_size =
sizeof(
struct chnl_net),
523 .
setup = ipcaif_net_setup,
525 .policy = ipcaif_policy,
526 .newlink = ipcaif_newlink,
527 .changelink = ipcaif_changelink,
528 .get_size = ipcaif_get_size,
529 .fill_info = ipcaif_fill_info,
533 static int __init chnl_init_module(
void)
538 static void __exit chnl_exit_module(
void)