2 * ---------------------------------------------------------------------------
6 * Routines related to IP address changes.
7 * Optional part of the porting exercise. It uses system network
8 * handlers to obtain the UniFi IP address and pass it to the SME
9 * using the unifi_sys_ip_configured_ind().
11 * Copyright (C) 2008-2009 Cambridge Silicon Radio Ltd.
13 * Refer to LICENSE.txt included with this source code for details on
16 * ---------------------------------------------------------------------------
18 #include <linux/inetdevice.h>
19 #include <linux/notifier.h>
21 #include "unifi_priv.h"
22 #include "csr_wifi_hip_conversions.h"
25 * The inet notifier is global and not per-netdev. To avoid having a
26 * notifier registered when there are no unifi devices present, it's
27 * registered after the first unifi network device is registered, and
28 * unregistered when the last unifi network device is unregistered.
31 static atomic_t inet_notif_refs
= ATOMIC_INIT(0);
33 static int uf_inetaddr_event(struct notifier_block
*notif
, unsigned long event
, void *ifa
)
35 struct net_device
*ndev
;
37 struct in_ifaddr
*if_addr
;
38 netInterface_priv_t
*InterfacePriv
= (netInterface_priv_t
*)NULL
;
40 if (!ifa
|| !((struct in_ifaddr
*)ifa
)->ifa_dev
) {
41 unifi_trace(NULL
, UDBG1
, "uf_inetaddr_event (%lu) ifa=%p\n", event
, ifa
);
45 ndev
= ((struct in_ifaddr
*)ifa
)->ifa_dev
->dev
;
46 InterfacePriv
= (netInterface_priv_t
*) netdev_priv(ndev
);
48 /* As the notifier is global, the call may be for a non-UniFi netdev.
49 * Therefore check the netdev_priv to make sure it's a known UniFi one.
51 if (uf_find_netdev_priv(InterfacePriv
) == -1) {
52 unifi_trace(NULL
, UDBG1
, "uf_inetaddr_event (%lu) ndev=%p, other netdev_priv=%p\n",
53 event
, ndev
, InterfacePriv
);
57 if (!InterfacePriv
->privPtr
) {
58 unifi_error(NULL
, "uf_inetaddr_event null priv (%lu) ndev=%p, InterfacePriv=%p\n",
59 event
, ndev
, InterfacePriv
);
63 priv
= InterfacePriv
->privPtr
;
64 if_addr
= (struct in_ifaddr
*)ifa
;
66 /* If this event is for a UniFi device, notify the SME that an IP
67 * address has been added or removed. */
68 if (uf_find_priv(priv
) != -1) {
71 unifi_info(priv
, "IP address assigned for %s\n", priv
->netdev
[InterfacePriv
->InterfaceTag
]->name
);
72 priv
->sta_ip_address
= if_addr
->ifa_address
;
73 #ifdef CSR_SUPPORT_WEXT
74 sme_mgt_packet_filter_set(priv
);
78 unifi_info(priv
, "IP address removed for %s\n", priv
->netdev
[InterfacePriv
->InterfaceTag
]->name
);
79 priv
->sta_ip_address
= 0xFFFFFFFF;
80 #ifdef CSR_SUPPORT_WEXT
81 sme_mgt_packet_filter_set(priv
);
90 static struct notifier_block uf_inetaddr_notifier
= {
91 .notifier_call
= uf_inetaddr_event
,
94 void uf_register_inet_notifier(void)
96 if (atomic_inc_return(&inet_notif_refs
) == 1) {
97 register_inetaddr_notifier(&uf_inetaddr_notifier
);
101 void uf_unregister_inet_notifier(void)
103 if (atomic_dec_return(&inet_notif_refs
) == 0) {
104 unregister_inetaddr_notifier(&uf_inetaddr_notifier
);