caif_config_util.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright (C) ST-Ericsson AB 2010
  3. * Author: Sjur Brendeland sjur.brandeland@stericsson.com
  4. * License terms: GNU General Public License (GPL) version 2
  5. */
  6. #include <linux/module.h>
  7. #include <linux/spinlock.h>
  8. #include <net/caif/cfctrl.h>
  9. #include <net/caif/cfcnfg.h>
  10. #include <net/caif/caif_dev.h>
  11. int connect_req_to_link_param(struct cfcnfg *cnfg,
  12. struct caif_connect_request *s,
  13. struct cfctrl_link_param *l)
  14. {
  15. struct dev_info *dev_info;
  16. enum cfcnfg_phy_preference pref;
  17. int res;
  18. memset(l, 0, sizeof(*l));
  19. /* In caif protocol low value is high priority */
  20. l->priority = CAIF_PRIO_MAX - s->priority + 1;
  21. if (s->ifindex != 0){
  22. res = cfcnfg_get_id_from_ifi(cnfg, s->ifindex);
  23. if (res < 0)
  24. return res;
  25. l->phyid = res;
  26. }
  27. else {
  28. switch (s->link_selector) {
  29. case CAIF_LINK_HIGH_BANDW:
  30. pref = CFPHYPREF_HIGH_BW;
  31. break;
  32. case CAIF_LINK_LOW_LATENCY:
  33. pref = CFPHYPREF_LOW_LAT;
  34. break;
  35. default:
  36. return -EINVAL;
  37. }
  38. dev_info = cfcnfg_get_phyid(cnfg, pref);
  39. if (dev_info == NULL)
  40. return -ENODEV;
  41. l->phyid = dev_info->id;
  42. }
  43. switch (s->protocol) {
  44. case CAIFPROTO_AT:
  45. l->linktype = CFCTRL_SRV_VEI;
  46. if (s->sockaddr.u.at.type == CAIF_ATTYPE_PLAIN)
  47. l->chtype = 0x02;
  48. else
  49. l->chtype = s->sockaddr.u.at.type;
  50. l->endpoint = 0x00;
  51. break;
  52. case CAIFPROTO_DATAGRAM:
  53. l->linktype = CFCTRL_SRV_DATAGRAM;
  54. l->chtype = 0x00;
  55. l->u.datagram.connid = s->sockaddr.u.dgm.connection_id;
  56. break;
  57. case CAIFPROTO_DATAGRAM_LOOP:
  58. l->linktype = CFCTRL_SRV_DATAGRAM;
  59. l->chtype = 0x03;
  60. l->endpoint = 0x00;
  61. l->u.datagram.connid = s->sockaddr.u.dgm.connection_id;
  62. break;
  63. case CAIFPROTO_RFM:
  64. l->linktype = CFCTRL_SRV_RFM;
  65. l->u.datagram.connid = s->sockaddr.u.rfm.connection_id;
  66. strncpy(l->u.rfm.volume, s->sockaddr.u.rfm.volume,
  67. sizeof(l->u.rfm.volume)-1);
  68. l->u.rfm.volume[sizeof(l->u.rfm.volume)-1] = 0;
  69. break;
  70. case CAIFPROTO_UTIL:
  71. l->linktype = CFCTRL_SRV_UTIL;
  72. l->endpoint = 0x00;
  73. l->chtype = 0x00;
  74. strncpy(l->u.utility.name, s->sockaddr.u.util.service,
  75. sizeof(l->u.utility.name)-1);
  76. l->u.utility.name[sizeof(l->u.utility.name)-1] = 0;
  77. caif_assert(sizeof(l->u.utility.name) > 10);
  78. l->u.utility.paramlen = s->param.size;
  79. if (l->u.utility.paramlen > sizeof(l->u.utility.params))
  80. l->u.utility.paramlen = sizeof(l->u.utility.params);
  81. memcpy(l->u.utility.params, s->param.data,
  82. l->u.utility.paramlen);
  83. break;
  84. case CAIFPROTO_DEBUG:
  85. l->linktype = CFCTRL_SRV_DBG;
  86. l->endpoint = s->sockaddr.u.dbg.service;
  87. l->chtype = s->sockaddr.u.dbg.type;
  88. break;
  89. default:
  90. return -EINVAL;
  91. }
  92. return 0;
  93. }