cfvidl.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (C) ST-Ericsson AB 2010
  3. * Author: Sjur Brendeland
  4. * License terms: GNU General Public License (GPL) version 2
  5. */
  6. #define pr_fmt(fmt) KBUILD_MODNAME ":%s(): " fmt, __func__
  7. #include <linux/kernel.h>
  8. #include <linux/types.h>
  9. #include <linux/slab.h>
  10. #include <linux/errno.h>
  11. #include <net/caif/caif_layer.h>
  12. #include <net/caif/cfsrvl.h>
  13. #include <net/caif/cfpkt.h>
  14. #define container_obj(layr) ((struct cfsrvl *) layr)
  15. static int cfvidl_receive(struct cflayer *layr, struct cfpkt *pkt);
  16. static int cfvidl_transmit(struct cflayer *layr, struct cfpkt *pkt);
  17. struct cflayer *cfvidl_create(u8 channel_id, struct dev_info *dev_info)
  18. {
  19. struct cfsrvl *vid = kzalloc(sizeof(struct cfsrvl), GFP_ATOMIC);
  20. if (!vid)
  21. return NULL;
  22. caif_assert(offsetof(struct cfsrvl, layer) == 0);
  23. cfsrvl_init(vid, channel_id, dev_info, false);
  24. vid->layer.receive = cfvidl_receive;
  25. vid->layer.transmit = cfvidl_transmit;
  26. snprintf(vid->layer.name, CAIF_LAYER_NAME_SZ - 1, "vid1");
  27. return &vid->layer;
  28. }
  29. static int cfvidl_receive(struct cflayer *layr, struct cfpkt *pkt)
  30. {
  31. u32 videoheader;
  32. if (cfpkt_extr_head(pkt, &videoheader, 4) < 0) {
  33. pr_err("Packet is erroneous!\n");
  34. cfpkt_destroy(pkt);
  35. return -EPROTO;
  36. }
  37. return layr->up->receive(layr->up, pkt);
  38. }
  39. static int cfvidl_transmit(struct cflayer *layr, struct cfpkt *pkt)
  40. {
  41. struct cfsrvl *service = container_obj(layr);
  42. struct caif_payload_info *info;
  43. u32 videoheader = 0;
  44. int ret;
  45. if (!cfsrvl_ready(service, &ret)) {
  46. cfpkt_destroy(pkt);
  47. return ret;
  48. }
  49. cfpkt_add_head(pkt, &videoheader, 4);
  50. /* Add info for MUX-layer to route the packet out */
  51. info = cfpkt_info(pkt);
  52. info->channel_id = service->layer.id;
  53. info->dev_info = &service->dev_info;
  54. return layr->dn->transmit(layr->dn, pkt);
  55. }