Lines Matching refs:app
239 static struct mrp_attr *mrp_attr_lookup(const struct mrp_applicant *app, in mrp_attr_lookup() argument
242 struct rb_node *parent = app->mad.rb_node; in mrp_attr_lookup()
259 static struct mrp_attr *mrp_attr_create(struct mrp_applicant *app, in mrp_attr_create() argument
262 struct rb_node *parent = NULL, **p = &app->mad.rb_node; in mrp_attr_create()
288 rb_insert_color(&attr->node, &app->mad); in mrp_attr_create()
292 static void mrp_attr_destroy(struct mrp_applicant *app, struct mrp_attr *attr) in mrp_attr_destroy() argument
294 rb_erase(&attr->node, &app->mad); in mrp_attr_destroy()
298 static int mrp_pdu_init(struct mrp_applicant *app) in mrp_pdu_init() argument
303 skb = alloc_skb(app->dev->mtu + LL_RESERVED_SPACE(app->dev), in mrp_pdu_init()
308 skb->dev = app->dev; in mrp_pdu_init()
309 skb->protocol = app->app->pkttype.type; in mrp_pdu_init()
310 skb_reserve(skb, LL_RESERVED_SPACE(app->dev)); in mrp_pdu_init()
315 ph->version = app->app->version; in mrp_pdu_init()
317 app->pdu = skb; in mrp_pdu_init()
321 static int mrp_pdu_append_end_mark(struct mrp_applicant *app) in mrp_pdu_append_end_mark() argument
325 if (skb_tailroom(app->pdu) < sizeof(*endmark)) in mrp_pdu_append_end_mark()
327 endmark = __skb_put(app->pdu, sizeof(*endmark)); in mrp_pdu_append_end_mark()
332 static void mrp_pdu_queue(struct mrp_applicant *app) in mrp_pdu_queue() argument
334 if (!app->pdu) in mrp_pdu_queue()
337 if (mrp_cb(app->pdu)->mh) in mrp_pdu_queue()
338 mrp_pdu_append_end_mark(app); in mrp_pdu_queue()
339 mrp_pdu_append_end_mark(app); in mrp_pdu_queue()
341 dev_hard_header(app->pdu, app->dev, ntohs(app->app->pkttype.type), in mrp_pdu_queue()
342 app->app->group_address, app->dev->dev_addr, in mrp_pdu_queue()
343 app->pdu->len); in mrp_pdu_queue()
345 skb_queue_tail(&app->queue, app->pdu); in mrp_pdu_queue()
346 app->pdu = NULL; in mrp_pdu_queue()
349 static void mrp_queue_xmit(struct mrp_applicant *app) in mrp_queue_xmit() argument
353 while ((skb = skb_dequeue(&app->queue))) in mrp_queue_xmit()
357 static int mrp_pdu_append_msg_hdr(struct mrp_applicant *app, in mrp_pdu_append_msg_hdr() argument
362 if (mrp_cb(app->pdu)->mh) { in mrp_pdu_append_msg_hdr()
363 if (mrp_pdu_append_end_mark(app) < 0) in mrp_pdu_append_msg_hdr()
365 mrp_cb(app->pdu)->mh = NULL; in mrp_pdu_append_msg_hdr()
366 mrp_cb(app->pdu)->vah = NULL; in mrp_pdu_append_msg_hdr()
369 if (skb_tailroom(app->pdu) < sizeof(*mh)) in mrp_pdu_append_msg_hdr()
371 mh = __skb_put(app->pdu, sizeof(*mh)); in mrp_pdu_append_msg_hdr()
374 mrp_cb(app->pdu)->mh = mh; in mrp_pdu_append_msg_hdr()
378 static int mrp_pdu_append_vecattr_hdr(struct mrp_applicant *app, in mrp_pdu_append_vecattr_hdr() argument
383 if (skb_tailroom(app->pdu) < sizeof(*vah) + attrlen) in mrp_pdu_append_vecattr_hdr()
385 vah = __skb_put(app->pdu, sizeof(*vah) + attrlen); in mrp_pdu_append_vecattr_hdr()
388 mrp_cb(app->pdu)->vah = vah; in mrp_pdu_append_vecattr_hdr()
389 memcpy(mrp_cb(app->pdu)->attrvalue, firstattrvalue, attrlen); in mrp_pdu_append_vecattr_hdr()
393 static int mrp_pdu_append_vecattr_event(struct mrp_applicant *app, in mrp_pdu_append_vecattr_event() argument
401 if (!app->pdu) { in mrp_pdu_append_vecattr_event()
402 err = mrp_pdu_init(app); in mrp_pdu_append_vecattr_event()
411 if (!mrp_cb(app->pdu)->mh || in mrp_pdu_append_vecattr_event()
412 mrp_cb(app->pdu)->mh->attrtype != attr->type || in mrp_pdu_append_vecattr_event()
413 mrp_cb(app->pdu)->mh->attrlen != attr->len) { in mrp_pdu_append_vecattr_event()
414 if (mrp_pdu_append_msg_hdr(app, attr->type, attr->len) < 0) in mrp_pdu_append_vecattr_event()
422 if (!mrp_cb(app->pdu)->vah || in mrp_pdu_append_vecattr_event()
423 memcmp(mrp_cb(app->pdu)->attrvalue, attr->value, attr->len)) { in mrp_pdu_append_vecattr_event()
424 if (mrp_pdu_append_vecattr_hdr(app, attr->value, attr->len) < 0) in mrp_pdu_append_vecattr_event()
428 len = be16_to_cpu(get_unaligned(&mrp_cb(app->pdu)->vah->lenflags)); in mrp_pdu_append_vecattr_event()
435 if (skb_tailroom(app->pdu) < sizeof(u8)) in mrp_pdu_append_vecattr_event()
437 vaevents = __skb_put(app->pdu, sizeof(u8)); in mrp_pdu_append_vecattr_event()
439 vaevents = (u8 *)(skb_tail_pointer(app->pdu) - sizeof(u8)); in mrp_pdu_append_vecattr_event()
460 put_unaligned(cpu_to_be16(++len), &mrp_cb(app->pdu)->vah->lenflags); in mrp_pdu_append_vecattr_event()
461 mrp_attrvalue_inc(mrp_cb(app->pdu)->attrvalue, attr->len); in mrp_pdu_append_vecattr_event()
466 mrp_pdu_queue(app); in mrp_pdu_append_vecattr_event()
470 static void mrp_attr_event(struct mrp_applicant *app, in mrp_attr_event() argument
493 app, attr, MRP_VECATTR_EVENT_NEW) < 0) in mrp_attr_event()
498 app, attr, MRP_VECATTR_EVENT_JOIN_IN) < 0) in mrp_attr_event()
503 app, attr, MRP_VECATTR_EVENT_LV) < 0) in mrp_attr_event()
509 mrp_attr_destroy(app, attr); in mrp_attr_event()
524 struct mrp_applicant *app = rtnl_dereference( in mrp_request_join() local
532 spin_lock_bh(&app->lock); in mrp_request_join()
533 attr = mrp_attr_create(app, value, len, type); in mrp_request_join()
535 spin_unlock_bh(&app->lock); in mrp_request_join()
538 mrp_attr_event(app, attr, MRP_EVENT_JOIN); in mrp_request_join()
539 spin_unlock_bh(&app->lock); in mrp_request_join()
549 struct mrp_applicant *app = rtnl_dereference( in mrp_request_leave() local
557 spin_lock_bh(&app->lock); in mrp_request_leave()
558 attr = mrp_attr_lookup(app, value, len, type); in mrp_request_leave()
560 spin_unlock_bh(&app->lock); in mrp_request_leave()
563 mrp_attr_event(app, attr, MRP_EVENT_LV); in mrp_request_leave()
564 spin_unlock_bh(&app->lock); in mrp_request_leave()
568 static void mrp_mad_event(struct mrp_applicant *app, enum mrp_event event) in mrp_mad_event() argument
573 for (node = rb_first(&app->mad); in mrp_mad_event()
577 mrp_attr_event(app, attr, event); in mrp_mad_event()
581 static void mrp_join_timer_arm(struct mrp_applicant *app) in mrp_join_timer_arm() argument
586 mod_timer(&app->join_timer, jiffies + delay); in mrp_join_timer_arm()
591 struct mrp_applicant *app = from_timer(app, t, join_timer); in mrp_join_timer() local
593 spin_lock(&app->lock); in mrp_join_timer()
594 mrp_mad_event(app, MRP_EVENT_TX); in mrp_join_timer()
595 mrp_pdu_queue(app); in mrp_join_timer()
596 spin_unlock(&app->lock); in mrp_join_timer()
598 mrp_queue_xmit(app); in mrp_join_timer()
599 mrp_join_timer_arm(app); in mrp_join_timer()
602 static void mrp_periodic_timer_arm(struct mrp_applicant *app) in mrp_periodic_timer_arm() argument
604 mod_timer(&app->periodic_timer, in mrp_periodic_timer_arm()
610 struct mrp_applicant *app = from_timer(app, t, periodic_timer); in mrp_periodic_timer() local
612 spin_lock(&app->lock); in mrp_periodic_timer()
613 mrp_mad_event(app, MRP_EVENT_PERIODIC); in mrp_periodic_timer()
614 mrp_pdu_queue(app); in mrp_periodic_timer()
615 spin_unlock(&app->lock); in mrp_periodic_timer()
617 mrp_periodic_timer_arm(app); in mrp_periodic_timer()
633 static void mrp_pdu_parse_vecattr_event(struct mrp_applicant *app, in mrp_pdu_parse_vecattr_event() argument
640 attr = mrp_attr_lookup(app, mrp_cb(skb)->attrvalue, in mrp_pdu_parse_vecattr_event()
669 mrp_attr_event(app, attr, event); in mrp_pdu_parse_vecattr_event()
672 static int mrp_pdu_parse_vecattr(struct mrp_applicant *app, in mrp_pdu_parse_vecattr() argument
687 mrp_mad_event(app, MRP_EVENT_R_LA); in mrp_pdu_parse_vecattr()
721 mrp_pdu_parse_vecattr_event(app, skb, vaevent); in mrp_pdu_parse_vecattr()
731 mrp_pdu_parse_vecattr_event(app, skb, vaevent); in mrp_pdu_parse_vecattr()
740 mrp_pdu_parse_vecattr_event(app, skb, vaevent); in mrp_pdu_parse_vecattr()
745 static int mrp_pdu_parse_msg(struct mrp_applicant *app, struct sk_buff *skb, in mrp_pdu_parse_msg() argument
756 mrp_cb(skb)->mh->attrtype > app->app->maxattr || in mrp_pdu_parse_msg()
763 if (mrp_pdu_parse_vecattr(app, skb, offset) < 0) in mrp_pdu_parse_msg()
775 struct mrp_applicant *app; in mrp_rcv() local
791 app = rcu_dereference(port->applicants[appl->type]); in mrp_rcv()
792 if (unlikely(!app)) in mrp_rcv()
800 if (ph->version != app->app->version) in mrp_rcv()
803 spin_lock(&app->lock); in mrp_rcv()
807 if (mrp_pdu_parse_msg(app, skb, &offset) < 0) in mrp_rcv()
810 spin_unlock(&app->lock); in mrp_rcv()
842 struct mrp_applicant *app; in mrp_init_applicant() local
854 app = kzalloc(sizeof(*app), GFP_KERNEL); in mrp_init_applicant()
855 if (!app) in mrp_init_applicant()
862 app->dev = dev; in mrp_init_applicant()
863 app->app = appl; in mrp_init_applicant()
864 app->mad = RB_ROOT; in mrp_init_applicant()
865 spin_lock_init(&app->lock); in mrp_init_applicant()
866 skb_queue_head_init(&app->queue); in mrp_init_applicant()
867 rcu_assign_pointer(dev->mrp_port->applicants[appl->type], app); in mrp_init_applicant()
868 timer_setup(&app->join_timer, mrp_join_timer, 0); in mrp_init_applicant()
869 mrp_join_timer_arm(app); in mrp_init_applicant()
870 timer_setup(&app->periodic_timer, mrp_periodic_timer, 0); in mrp_init_applicant()
871 mrp_periodic_timer_arm(app); in mrp_init_applicant()
875 kfree(app); in mrp_init_applicant()
886 struct mrp_applicant *app = rtnl_dereference( in mrp_uninit_applicant() local
896 del_timer_sync(&app->join_timer); in mrp_uninit_applicant()
897 del_timer_sync(&app->periodic_timer); in mrp_uninit_applicant()
899 spin_lock_bh(&app->lock); in mrp_uninit_applicant()
900 mrp_mad_event(app, MRP_EVENT_TX); in mrp_uninit_applicant()
901 mrp_pdu_queue(app); in mrp_uninit_applicant()
902 spin_unlock_bh(&app->lock); in mrp_uninit_applicant()
904 mrp_queue_xmit(app); in mrp_uninit_applicant()
907 kfree_rcu(app, rcu); in mrp_uninit_applicant()