1 /* -----------------------------------------------------------------------------
2 * Copyright (c) 2011 Ozmo Inc
3 * Released under the GNU General Public License Version 2 (GPLv2).
4 * -----------------------------------------------------------------------------
6 #include <linux/init.h>
7 #include <linux/module.h>
8 #include <linux/timer.h>
9 #include <linux/sched.h>
10 #include <linux/netdevice.h>
11 #include <linux/errno.h>
12 #include <linux/ieee80211.h>
15 #include "ozprotocol.h"
22 #include <asm/unaligned.h>
23 #include <linux/uaccess.h>
24 #include <net/psnap.h>
25 /*------------------------------------------------------------------------------
27 #define OZ_CF_CONN_SUCCESS 1
28 #define OZ_CF_CONN_FAILURE 2
33 /* States of the timer.
35 #define OZ_TIMER_IDLE 0
36 #define OZ_TIMER_SET 1
37 #define OZ_TIMER_IN_HANDLER 2
39 #define OZ_MAX_TIMER_POOL_SIZE 16
41 /*------------------------------------------------------------------------------
44 struct packet_type ptype;
45 char name[OZ_MAX_BINDING_LEN];
46 struct oz_binding *next;
50 struct list_head link;
52 unsigned long due_time;
55 /*------------------------------------------------------------------------------
56 * Static external variables.
58 static DEFINE_SPINLOCK(g_polling_lock);
59 static LIST_HEAD(g_pd_list);
60 static struct oz_binding *g_binding ;
61 static DEFINE_SPINLOCK(g_binding_lock);
62 static struct sk_buff_head g_rx_queue;
63 static u8 g_session_id;
64 static u16 g_apps = 0x1;
65 static int g_processing_rx;
66 static struct timer_list g_timer;
67 static struct oz_timer *g_cur_timer;
68 static struct list_head *g_timer_pool;
69 static int g_timer_pool_count;
70 static int g_timer_state = OZ_TIMER_IDLE;
71 static LIST_HEAD(g_timer_list);
72 /*------------------------------------------------------------------------------
74 static void oz_protocol_timer_start(void);
75 /*------------------------------------------------------------------------------
76 * Context: softirq-serialized
78 static u8 oz_get_new_session_id(u8 exclude)
80 if (++g_session_id == 0)
82 if (g_session_id == exclude) {
83 if (++g_session_id == 0)
88 /*------------------------------------------------------------------------------
89 * Context: softirq-serialized
91 static void oz_send_conn_rsp(struct oz_pd *pd, u8 status)
94 struct net_device *dev = pd->net_dev;
95 struct oz_hdr *oz_hdr;
97 struct oz_elt_connect_rsp *body;
98 int sz = sizeof(struct oz_hdr) + sizeof(struct oz_elt) +
99 sizeof(struct oz_elt_connect_rsp);
100 skb = alloc_skb(sz + OZ_ALLOCATED_SPACE(dev), GFP_ATOMIC);
103 skb_reserve(skb, LL_RESERVED_SPACE(dev));
104 skb_reset_network_header(skb);
105 oz_hdr = (struct oz_hdr *)skb_put(skb, sz);
106 elt = (struct oz_elt *)(oz_hdr+1);
107 body = (struct oz_elt_connect_rsp *)(elt+1);
109 skb->protocol = htons(OZ_ETHERTYPE);
110 /* Fill in device header */
111 if (dev_hard_header(skb, dev, OZ_ETHERTYPE, pd->mac_addr,
112 dev->dev_addr, skb->len) < 0) {
116 oz_hdr->control = (OZ_PROTOCOL_VERSION<<OZ_VERSION_SHIFT);
117 oz_hdr->last_pkt_num = 0;
118 put_unaligned(0, &oz_hdr->pkt_num);
119 elt->type = OZ_ELT_CONNECT_RSP;
120 elt->length = sizeof(struct oz_elt_connect_rsp);
121 memset(body, 0, sizeof(struct oz_elt_connect_rsp));
122 body->status = status;
124 body->mode = pd->mode;
125 body->session_id = pd->session_id;
126 put_unaligned(cpu_to_le16(pd->total_apps), &body->apps);
128 oz_dbg(ON, "TX: OZ_ELT_CONNECT_RSP %d", status);
132 /*------------------------------------------------------------------------------
133 * Context: softirq-serialized
135 static void pd_set_keepalive(struct oz_pd *pd, u8 kalive)
137 unsigned long keep_alive = kalive & OZ_KALIVE_VALUE_MASK;
139 switch (kalive & OZ_KALIVE_TYPE_MASK) {
140 case OZ_KALIVE_SPECIAL:
142 oz_ms_to_jiffies(keep_alive * 1000*60*60*24*20);
145 pd->keep_alive_j = oz_ms_to_jiffies(keep_alive*1000);
148 pd->keep_alive_j = oz_ms_to_jiffies(keep_alive*1000*60);
150 case OZ_KALIVE_HOURS:
151 pd->keep_alive_j = oz_ms_to_jiffies(keep_alive*1000*60*60);
154 pd->keep_alive_j = 0;
156 oz_dbg(ON, "Keepalive = %lu jiffies\n", pd->keep_alive_j);
158 /*------------------------------------------------------------------------------
159 * Context: softirq-serialized
161 static void pd_set_presleep(struct oz_pd *pd, u8 presleep)
164 pd->presleep_j = oz_ms_to_jiffies(presleep*100);
166 pd->presleep_j = OZ_PRESLEEP_TOUT_J;
167 oz_dbg(ON, "Presleep time = %lu jiffies\n", pd->presleep_j);
169 /*------------------------------------------------------------------------------
170 * Context: softirq-serialized
172 static struct oz_pd *oz_connect_req(struct oz_pd *cur_pd, struct oz_elt *elt,
173 const u8 *pd_addr, struct net_device *net_dev)
176 struct oz_elt_connect_req *body =
177 (struct oz_elt_connect_req *)(elt+1);
178 u8 rsp_status = OZ_STATUS_SUCCESS;
180 u16 new_apps = g_apps;
181 struct net_device *old_net_dev = NULL;
182 struct oz_pd *free_pd = NULL;
185 spin_lock_bh(&g_polling_lock);
187 struct oz_pd *pd2 = NULL;
189 pd = oz_pd_alloc(pd_addr);
192 pd->last_rx_time_j = jiffies;
193 spin_lock_bh(&g_polling_lock);
194 list_for_each(e, &g_pd_list) {
195 pd2 = container_of(e, struct oz_pd, link);
196 if (memcmp(pd2->mac_addr, pd_addr, ETH_ALEN) == 0) {
203 list_add_tail(&pd->link, &g_pd_list);
206 spin_unlock_bh(&g_polling_lock);
209 if (pd->net_dev != net_dev) {
210 old_net_dev = pd->net_dev;
212 pd->net_dev = net_dev;
214 oz_dbg(ON, "Host vendor: %d\n", body->host_vendor);
215 pd->max_tx_size = OZ_MAX_TX_SIZE;
216 pd->mode = body->mode;
217 pd->pd_info = body->pd_info;
218 if (pd->mode & OZ_F_ISOC_NO_ELTS) {
219 pd->ms_per_isoc = body->ms_per_isoc;
220 if (!pd->ms_per_isoc)
223 switch (body->ms_isoc_latency & OZ_LATENCY_MASK) {
224 case OZ_ONE_MS_LATENCY:
225 pd->isoc_latency = (body->ms_isoc_latency &
226 ~OZ_LATENCY_MASK) / pd->ms_per_isoc;
228 case OZ_TEN_MS_LATENCY:
229 pd->isoc_latency = ((body->ms_isoc_latency &
230 ~OZ_LATENCY_MASK) * 10) / pd->ms_per_isoc;
233 pd->isoc_latency = OZ_MAX_TX_QUEUE_ISOC;
236 if (body->max_len_div16)
237 pd->max_tx_size = ((u16)body->max_len_div16)<<4;
238 oz_dbg(ON, "Max frame:%u Ms per isoc:%u\n",
239 pd->max_tx_size, pd->ms_per_isoc);
240 pd->max_stream_buffering = 3*1024;
241 pd->timeout_time_j = jiffies + OZ_CONNECTION_TOUT_J;
242 pd->pulse_period_j = OZ_QUANTUM_J;
243 pd_set_presleep(pd, body->presleep);
244 pd_set_keepalive(pd, body->keep_alive);
246 new_apps &= le16_to_cpu(get_unaligned(&body->apps));
247 if ((new_apps & 0x1) && (body->session_id)) {
248 if (pd->session_id) {
249 if (pd->session_id != body->session_id) {
250 rsp_status = OZ_STATUS_SESSION_MISMATCH;
254 new_apps &= ~0x1; /* Resume not permitted */
256 oz_get_new_session_id(body->session_id);
259 if (pd->session_id && !body->session_id) {
260 rsp_status = OZ_STATUS_SESSION_TEARDOWN;
263 new_apps &= ~0x1; /* Resume not permitted */
265 oz_get_new_session_id(body->session_id);
269 if (rsp_status == OZ_STATUS_SUCCESS) {
270 u16 start_apps = new_apps & ~pd->total_apps & ~0x1;
271 u16 stop_apps = pd->total_apps & ~new_apps & ~0x1;
272 u16 resume_apps = new_apps & pd->paused_apps & ~0x1;
273 spin_unlock_bh(&g_polling_lock);
274 oz_pd_set_state(pd, OZ_PD_S_CONNECTED);
275 oz_timer_delete(pd, OZ_TIMER_STOP);
276 oz_dbg(ON, "new_apps=0x%x total_apps=0x%x paused_apps=0x%x\n",
277 new_apps, pd->total_apps, pd->paused_apps);
279 if (oz_services_start(pd, start_apps, 0))
280 rsp_status = OZ_STATUS_TOO_MANY_PDS;
283 if (oz_services_start(pd, resume_apps, 1))
284 rsp_status = OZ_STATUS_TOO_MANY_PDS;
286 oz_services_stop(pd, stop_apps, 0);
287 oz_pd_request_heartbeat(pd);
289 spin_unlock_bh(&g_polling_lock);
291 oz_send_conn_rsp(pd, rsp_status);
292 if (rsp_status != OZ_STATUS_SUCCESS) {
299 dev_put(old_net_dev);
301 oz_pd_destroy(free_pd);
304 /*------------------------------------------------------------------------------
305 * Context: softirq-serialized
307 static void oz_add_farewell(struct oz_pd *pd, u8 ep_num, u8 index,
308 const u8 *report, u8 len)
310 struct oz_farewell *f;
311 struct oz_farewell *f2;
313 f = kmalloc(sizeof(struct oz_farewell) + len - 1, GFP_ATOMIC);
318 memcpy(f->report, report, len);
319 oz_dbg(ON, "RX: Adding farewell report\n");
320 spin_lock(&g_polling_lock);
321 list_for_each_entry(f2, &pd->farewell_list, link) {
322 if ((f2->ep_num == ep_num) && (f2->index == index)) {
328 list_add_tail(&f->link, &pd->farewell_list);
329 spin_unlock(&g_polling_lock);
333 /*------------------------------------------------------------------------------
334 * Context: softirq-serialized
336 static void oz_rx_frame(struct sk_buff *skb)
342 struct oz_pd *pd = NULL;
343 struct oz_hdr *oz_hdr = (struct oz_hdr *)skb_network_header(skb);
347 oz_dbg(RX_FRAMES, "RX frame PN=0x%x LPN=0x%x control=0x%x\n",
348 oz_hdr->pkt_num, oz_hdr->last_pkt_num, oz_hdr->control);
349 mac_hdr = skb_mac_header(skb);
350 src_addr = &mac_hdr[ETH_ALEN] ;
353 /* Check the version field */
354 if (oz_get_prot_ver(oz_hdr->control) != OZ_PROTOCOL_VERSION) {
355 oz_dbg(ON, "Incorrect protocol version: %d\n",
356 oz_get_prot_ver(oz_hdr->control));
360 pkt_num = le32_to_cpu(get_unaligned(&oz_hdr->pkt_num));
362 pd = oz_pd_find(src_addr);
364 pd->last_rx_time_j = jiffies;
365 oz_timer_add(pd, OZ_TIMER_TOUT,
366 pd->last_rx_time_j + pd->presleep_j, 1);
367 if (pkt_num != pd->last_rx_pkt_num) {
368 pd->last_rx_pkt_num = pkt_num;
371 oz_dbg(ON, "Duplicate frame\n");
375 if (pd && !dup && ((pd->mode & OZ_MODE_MASK) == OZ_MODE_TRIGGERED)) {
376 oz_dbg(RX_FRAMES, "Received TRIGGER Frame\n");
377 pd->last_sent_frame = &pd->tx_queue;
378 if (oz_hdr->control & OZ_F_ACK) {
379 /* Retire completed frames */
380 oz_retire_tx_frames(pd, oz_hdr->last_pkt_num);
382 if ((oz_hdr->control & OZ_F_ACK_REQUESTED) &&
383 (pd->state == OZ_PD_S_CONNECTED)) {
384 int backlog = pd->nb_queued_frames;
385 pd->trigger_pkt_num = pkt_num;
386 /* Send queued frames */
387 oz_send_queued_frames(pd, backlog);
391 length -= sizeof(struct oz_hdr);
392 elt = (struct oz_elt *)((u8 *)oz_hdr + sizeof(struct oz_hdr));
394 while (length >= sizeof(struct oz_elt)) {
395 length -= sizeof(struct oz_elt) + elt->length;
399 case OZ_ELT_CONNECT_REQ:
400 oz_dbg(ON, "RX: OZ_ELT_CONNECT_REQ\n");
401 pd = oz_connect_req(pd, elt, src_addr, skb->dev);
403 case OZ_ELT_DISCONNECT:
404 oz_dbg(ON, "RX: OZ_ELT_DISCONNECT\n");
408 case OZ_ELT_UPDATE_PARAM_REQ: {
409 struct oz_elt_update_param *body =
410 (struct oz_elt_update_param *)(elt + 1);
411 oz_dbg(ON, "RX: OZ_ELT_UPDATE_PARAM_REQ\n");
412 if (pd && (pd->state & OZ_PD_S_CONNECTED)) {
413 spin_lock(&g_polling_lock);
414 pd_set_keepalive(pd, body->keepalive);
415 pd_set_presleep(pd, body->presleep);
416 spin_unlock(&g_polling_lock);
420 case OZ_ELT_FAREWELL_REQ: {
421 struct oz_elt_farewell *body =
422 (struct oz_elt_farewell *)(elt + 1);
423 oz_dbg(ON, "RX: OZ_ELT_FAREWELL_REQ\n");
424 oz_add_farewell(pd, body->ep_num,
425 body->index, body->report,
426 elt->length + 1 - sizeof(*body));
429 case OZ_ELT_APP_DATA:
430 if (pd && (pd->state & OZ_PD_S_CONNECTED)) {
431 struct oz_app_hdr *app_hdr =
432 (struct oz_app_hdr *)(elt+1);
435 oz_handle_app_elt(pd, app_hdr->app_id, elt);
439 oz_dbg(ON, "RX: Unknown elt %02x\n", elt->type);
441 elt = oz_next_elt(elt);
448 /*------------------------------------------------------------------------------
451 void oz_protocol_term(void)
453 struct list_head *chain;
454 del_timer_sync(&g_timer);
455 /* Walk the list of bindings and remove each one.
457 spin_lock_bh(&g_binding_lock);
459 struct oz_binding *b = g_binding;
461 spin_unlock_bh(&g_binding_lock);
462 dev_remove_pack(&b->ptype);
464 dev_put(b->ptype.dev);
466 spin_lock_bh(&g_binding_lock);
468 spin_unlock_bh(&g_binding_lock);
469 /* Walk the list of PDs and stop each one. This causes the PD to be
470 * removed from the list so we can just pull each one from the head
473 spin_lock_bh(&g_polling_lock);
474 while (!list_empty(&g_pd_list)) {
476 list_first_entry(&g_pd_list, struct oz_pd, link);
478 spin_unlock_bh(&g_polling_lock);
481 spin_lock_bh(&g_polling_lock);
483 chain = g_timer_pool;
485 spin_unlock_bh(&g_polling_lock);
487 struct oz_timer *t = container_of(chain, struct oz_timer, link);
491 oz_dbg(ON, "Protocol stopped\n");
493 /*------------------------------------------------------------------------------
496 static void oz_pd_handle_timer(struct oz_pd *pd, int type)
505 case OZ_TIMER_HEARTBEAT: {
507 spin_lock_bh(&g_polling_lock);
508 pd->heartbeat_requested = 0;
509 if (pd->state & OZ_PD_S_CONNECTED)
510 apps = pd->total_apps;
511 spin_unlock_bh(&g_polling_lock);
513 oz_pd_heartbeat(pd, apps);
518 /*------------------------------------------------------------------------------
521 static void oz_protocol_timer(unsigned long arg)
526 spin_lock_bh(&g_polling_lock);
528 /* This happens if we remove the current timer but can't stop
529 * the timer from firing. In this case just get out.
531 spin_unlock_bh(&g_polling_lock);
534 g_timer_state = OZ_TIMER_IN_HANDLER;
538 spin_unlock_bh(&g_polling_lock);
541 oz_pd_handle_timer(pd, t->type);
542 spin_lock_bh(&g_polling_lock);
543 if (g_timer_pool_count < OZ_MAX_TIMER_POOL_SIZE) {
544 t->link.next = g_timer_pool;
545 g_timer_pool = &t->link;
546 g_timer_pool_count++;
549 if (!list_empty(&g_timer_list)) {
550 t2 = container_of(g_timer_list.next,
551 struct oz_timer, link);
552 if (time_before_eq(t2->due_time, jiffies))
559 spin_unlock_bh(&g_polling_lock);
564 g_timer_state = OZ_TIMER_IDLE;
565 oz_protocol_timer_start();
567 /*------------------------------------------------------------------------------
570 static void oz_protocol_timer_start(void)
572 spin_lock_bh(&g_polling_lock);
573 if (!list_empty(&g_timer_list)) {
575 container_of(g_timer_list.next, struct oz_timer, link);
576 if (g_timer_state == OZ_TIMER_SET) {
577 mod_timer(&g_timer, g_cur_timer->due_time);
579 g_timer.expires = g_cur_timer->due_time;
580 g_timer.function = oz_protocol_timer;
584 g_timer_state = OZ_TIMER_SET;
586 oz_dbg(ON, "No queued timers\n");
588 spin_unlock_bh(&g_polling_lock);
590 /*------------------------------------------------------------------------------
591 * Context: softirq or process
593 void oz_timer_add(struct oz_pd *pd, int type, unsigned long due_time,
597 struct oz_timer *t = NULL;
598 int restart_needed = 0;
599 spin_lock(&g_polling_lock);
601 list_for_each(e, &g_timer_list) {
602 t = container_of(e, struct oz_timer, link);
603 if ((t->pd == pd) && (t->type == type)) {
604 if (g_cur_timer == t) {
616 t = container_of(g_timer_pool, struct oz_timer, link);
617 g_timer_pool = g_timer_pool->next;
618 g_timer_pool_count--;
620 t = kmalloc(sizeof(struct oz_timer), GFP_ATOMIC);
630 t->due_time = due_time;
631 list_for_each(e, &g_timer_list) {
632 t2 = container_of(e, struct oz_timer, link);
633 if (time_before(due_time, t2->due_time)) {
634 if (t2 == g_cur_timer) {
641 list_add_tail(&t->link, e);
643 if (g_timer_state == OZ_TIMER_IDLE)
645 else if (g_timer_state == OZ_TIMER_IN_HANDLER)
647 spin_unlock(&g_polling_lock);
649 oz_protocol_timer_start();
651 /*------------------------------------------------------------------------------
652 * Context: softirq or process
654 void oz_timer_delete(struct oz_pd *pd, int type)
656 struct list_head *chain = NULL;
659 int restart_needed = 0;
661 spin_lock(&g_polling_lock);
662 list_for_each_entry_safe(t, n, &g_timer_list, link) {
663 if ((t->pd == pd) && ((type == 0) || (t->type == type))) {
664 if (g_cur_timer == t) {
671 if (g_timer_pool_count < OZ_MAX_TIMER_POOL_SIZE) {
672 t->link.next = g_timer_pool;
673 g_timer_pool = &t->link;
674 g_timer_pool_count++;
676 t->link.next = chain;
683 if (g_timer_state == OZ_TIMER_IN_HANDLER)
685 else if (restart_needed)
686 g_timer_state = OZ_TIMER_IDLE;
687 spin_unlock(&g_polling_lock);
689 oz_protocol_timer_start();
693 t = container_of(chain, struct oz_timer, link);
698 /*------------------------------------------------------------------------------
699 * Context: softirq or process
701 void oz_pd_request_heartbeat(struct oz_pd *pd)
703 unsigned long now = jiffies;
705 spin_lock(&g_polling_lock);
706 if (pd->heartbeat_requested) {
707 spin_unlock(&g_polling_lock);
710 if (pd->pulse_period_j)
711 t = ((now / pd->pulse_period_j) + 1) * pd->pulse_period_j;
714 pd->heartbeat_requested = 1;
715 spin_unlock(&g_polling_lock);
716 oz_timer_add(pd, OZ_TIMER_HEARTBEAT, t, 0);
718 /*------------------------------------------------------------------------------
719 * Context: softirq or process
721 struct oz_pd *oz_pd_find(const u8 *mac_addr)
725 spin_lock_bh(&g_polling_lock);
726 list_for_each(e, &g_pd_list) {
727 pd = container_of(e, struct oz_pd, link);
728 if (memcmp(pd->mac_addr, mac_addr, ETH_ALEN) == 0) {
729 atomic_inc(&pd->ref_count);
730 spin_unlock_bh(&g_polling_lock);
734 spin_unlock_bh(&g_polling_lock);
737 /*------------------------------------------------------------------------------
740 void oz_app_enable(int app_id, int enable)
742 if (app_id <= OZ_APPID_MAX) {
743 spin_lock_bh(&g_polling_lock);
745 g_apps |= (1<<app_id);
747 g_apps &= ~(1<<app_id);
748 spin_unlock_bh(&g_polling_lock);
751 /*------------------------------------------------------------------------------
754 static int oz_pkt_recv(struct sk_buff *skb, struct net_device *dev,
755 struct packet_type *pt, struct net_device *orig_dev)
757 skb = skb_share_check(skb, GFP_ATOMIC);
760 spin_lock_bh(&g_rx_queue.lock);
761 if (g_processing_rx) {
762 /* We already hold the lock so use __ variant.
764 __skb_queue_head(&g_rx_queue, skb);
765 spin_unlock_bh(&g_rx_queue.lock);
770 spin_unlock_bh(&g_rx_queue.lock);
772 spin_lock_bh(&g_rx_queue.lock);
773 if (skb_queue_empty(&g_rx_queue)) {
775 spin_unlock_bh(&g_rx_queue.lock);
778 /* We already hold the lock so use __ variant.
780 skb = __skb_dequeue(&g_rx_queue);
785 /*------------------------------------------------------------------------------
788 void oz_binding_add(char *net_dev)
790 struct oz_binding *binding;
792 binding = kmalloc(sizeof(struct oz_binding), GFP_KERNEL);
794 binding->ptype.type = __constant_htons(OZ_ETHERTYPE);
795 binding->ptype.func = oz_pkt_recv;
796 memcpy(binding->name, net_dev, OZ_MAX_BINDING_LEN);
797 if (net_dev && *net_dev) {
798 oz_dbg(ON, "Adding binding: %s\n", net_dev);
800 dev_get_by_name(&init_net, net_dev);
801 if (binding->ptype.dev == NULL) {
802 oz_dbg(ON, "Netdev %s not found\n", net_dev);
807 oz_dbg(ON, "Binding to all netcards\n");
808 binding->ptype.dev = NULL;
811 dev_add_pack(&binding->ptype);
812 spin_lock_bh(&g_binding_lock);
813 binding->next = g_binding;
815 spin_unlock_bh(&g_binding_lock);
819 /*------------------------------------------------------------------------------
822 static int compare_binding_name(char *s1, char *s2)
825 for (i = 0; i < OZ_MAX_BINDING_LEN; i++) {
834 /*------------------------------------------------------------------------------
837 static void pd_stop_all_for_device(struct net_device *net_dev)
843 spin_lock_bh(&g_polling_lock);
844 list_for_each_entry_safe(pd, n, &g_pd_list, link) {
845 if (pd->net_dev == net_dev) {
846 list_move(&pd->link, &h);
850 spin_unlock_bh(&g_polling_lock);
851 while (!list_empty(&h)) {
852 pd = list_first_entry(&h, struct oz_pd, link);
857 /*------------------------------------------------------------------------------
860 void oz_binding_remove(char *net_dev)
862 struct oz_binding *binding;
863 struct oz_binding **link;
864 oz_dbg(ON, "Removing binding: %s\n", net_dev);
865 spin_lock_bh(&g_binding_lock);
869 if (compare_binding_name(binding->name, net_dev)) {
870 oz_dbg(ON, "Binding '%s' found\n", net_dev);
871 *link = binding->next;
875 binding = binding->next;
878 spin_unlock_bh(&g_binding_lock);
880 dev_remove_pack(&binding->ptype);
881 if (binding->ptype.dev) {
882 dev_put(binding->ptype.dev);
883 pd_stop_all_for_device(binding->ptype.dev);
888 /*------------------------------------------------------------------------------
891 static char *oz_get_next_device_name(char *s, char *dname, int max_size)
895 while (*s && (*s != ',') && max_size > 1) {
902 /*------------------------------------------------------------------------------
905 int oz_protocol_init(char *devs)
907 skb_queue_head_init(&g_rx_queue);
908 if (devs && (devs[0] == '*')) {
909 oz_binding_add(NULL);
913 devs = oz_get_next_device_name(devs, d, sizeof(d));
918 init_timer(&g_timer);
921 /*------------------------------------------------------------------------------
924 int oz_get_pd_list(struct oz_mac_addr *addr, int max_count)
929 spin_lock_bh(&g_polling_lock);
930 list_for_each(e, &g_pd_list) {
931 if (count >= max_count)
933 pd = container_of(e, struct oz_pd, link);
934 memcpy(&addr[count++], pd->mac_addr, ETH_ALEN);
936 spin_unlock_bh(&g_polling_lock);
939 /*------------------------------------------------------------------------------
941 void oz_polling_lock_bh(void)
943 spin_lock_bh(&g_polling_lock);
945 /*------------------------------------------------------------------------------
947 void oz_polling_unlock_bh(void)
949 spin_unlock_bh(&g_polling_lock);