AccessLevelPTS.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * signed AccessLevelPTS (struct plc * plc);
  11. *
  12. * plc.h
  13. *
  14. * Request PTS level access on a QCA6410, QCA7000 or QCA7420 device
  15. * using the VS_ACCESS_CONTROL_LEVEL Request Message;
  16. *
  17. * this function is a customized version of function AccessLevel;
  18. *
  19. * Contributor(s):
  20. * Nathaniel Houghton <nhoughto@qca.qualcomm.com>
  21. * Charles Maier <cmaier@qca.qualcomm.com>
  22. *
  23. *--------------------------------------------------------------------*/
  24. #ifndef ACCESSLEVELPTS_SOURCE
  25. #define ACCESSLEVELPTS_SOURCE
  26. #include <stdint.h>
  27. #include <memory.h>
  28. #include "../tools/error.h"
  29. #include "../nda/nda.h"
  30. #include "../plc/plc.h"
  31. #define ACCESS_CONTROL_MAX_KEY_LENGTH 1024
  32. signed AccessLevelPTS (struct plc * plc)
  33. {
  34. struct channel * channel = (struct channel *) (plc->channel);
  35. struct message * message = (struct message *) (plc->message);
  36. #ifndef __GNUC__
  37. #pragma pack (push,1)
  38. #endif
  39. struct __packed vs_access_level_request
  40. {
  41. struct ethernet_hdr ethernet;
  42. struct qualcomm_hdr qualcomm;
  43. uint32_t RSVD1;
  44. uint8_t ACCESS_LEVEL;
  45. uint16_t RSVD2;
  46. uint8_t ACCESS_TYPE;
  47. uint16_t RSVD3;
  48. uint16_t KEY_LENGTH;
  49. uint8_t KEY [1024];
  50. }
  51. * request = (struct vs_access_level_request *) (message);
  52. struct __packed vs_access_level_confirm
  53. {
  54. struct ethernet_hdr ethernet;
  55. struct qualcomm_hdr qualcomm;
  56. uint16_t RSVD1;
  57. uint16_t MRESPONSE;
  58. }
  59. * confirm = (struct vs_access_level_confirm *) (message);
  60. #ifndef __GNUC__
  61. #pragma pack (pop)
  62. #endif
  63. memset (message, 0, sizeof (* message));
  64. EthernetHeader (& request->ethernet, channel->peer, channel->host, channel->type);
  65. QualcommHeader (& request->qualcomm, 0, (VS_ACCESS_LEVEL_CONTROL | MMTYPE_REQ));
  66. plc->packetsize = sizeof (* request) - sizeof (request->KEY) + sizeof (plc->DAK);
  67. if (plc->packetsize < ETHER_MIN_LEN - ETHER_CRC_LEN)
  68. {
  69. plc->packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  70. }
  71. memcpy (request->KEY, plc->DAK, sizeof (plc->DAK));
  72. request->ACCESS_LEVEL = ACCESS_LEVEL_PTS;
  73. request->KEY_LENGTH = sizeof (plc->DAK);
  74. request->ACCESS_TYPE = ACCESS_KEY_TYPE_DAK;
  75. if (SendMME (plc) <= 0)
  76. {
  77. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  78. return (-1);
  79. }
  80. if (ReadMME (plc, 0, (VS_ACCESS_LEVEL_CONTROL | MMTYPE_CNF)) <= 0)
  81. {
  82. error (PLC_EXIT (plc), ECANCELED, CHANNEL_CANTREAD);
  83. return (-1);
  84. }
  85. if (confirm->MRESPONSE)
  86. {
  87. Failure (plc, PLC_WONTDOIT);
  88. return (-1);
  89. }
  90. return (0);
  91. }
  92. #endif