coqos_mod.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * coqos_mod.c - Modify MCMSA stream
  11. *
  12. * Contributor(s):
  13. * Bill Wike <bill.wike@qca.qualcomm.com>
  14. * Nathaniel Houghton <nhoughto@qca.qualcomm.com>
  15. * Charles Maier <cmaier@qca.qualcomm.com>
  16. *
  17. *--------------------------------------------------------------------*/
  18. /*====================================================================*
  19. * system header files;
  20. *--------------------------------------------------------------------*/
  21. #include <unistd.h>
  22. #include <stdlib.h>
  23. #include <stdint.h>
  24. #include <limits.h>
  25. /*====================================================================*
  26. * custom header files;
  27. *--------------------------------------------------------------------*/
  28. #include "../tools/getoptv.h"
  29. #include "../tools/putoptv.h"
  30. #include "../tools/memory.h"
  31. #include "../tools/number.h"
  32. #include "../tools/symbol.h"
  33. #include "../tools/types.h"
  34. #include "../tools/flags.h"
  35. #include "../tools/files.h"
  36. #include "../tools/error.h"
  37. #include "../plc/plc.h"
  38. /*====================================================================*
  39. * custom source files;
  40. *--------------------------------------------------------------------*/
  41. #ifndef MAKEFILE
  42. #include "../tools/getoptv.c"
  43. #include "../tools/putoptv.c"
  44. #include "../tools/version.c"
  45. #include "../tools/hexdump.c"
  46. #include "../tools/hexencode.c"
  47. #include "../tools/bytespec.c"
  48. #include "../tools/ipv4spec.c"
  49. #include "../tools/ipv6spec.c"
  50. #include "../tools/hexdecode.c"
  51. #include "../tools/todigit.c"
  52. #include "../tools/typename.c"
  53. #include "../tools/error.c"
  54. #include "../tools/synonym.c"
  55. #include "../tools/lookup.c"
  56. #include "../tools/assist.c"
  57. #include "../tools/codelist.c"
  58. #endif
  59. #ifndef MAKEFILE
  60. #include "../plc/Request.c"
  61. #include "../plc/Confirm.c"
  62. #include "../plc/Display.c"
  63. #include "../plc/Failure.c"
  64. #include "../plc/ReadMME.c"
  65. #include "../plc/SendMME.c"
  66. #include "../plc/Devices.c"
  67. #include "../mme/EthernetHeader.c"
  68. #include "../mme/QualcommHeader.c"
  69. #include "../mme/UnwantedMessage.c"
  70. #endif
  71. #ifndef MAKEFILE
  72. #include "../ether/channel.c"
  73. #include "../ether/openchannel.c"
  74. #include "../ether/closechannel.c"
  75. #include "../ether/readpacket.c"
  76. #include "../ether/sendpacket.c"
  77. #endif
  78. #ifndef MAKEFILE
  79. #include "../mme/MMECode.c"
  80. #endif
  81. /*====================================================================*
  82. * constants;
  83. *--------------------------------------------------------------------*/
  84. #define ACTION "action"
  85. /*====================================================================*
  86. * program variables;
  87. *--------------------------------------------------------------------*/
  88. #define ACTION_SPND 0x00
  89. #define ACTION_RES 0x01
  90. static struct _code_ const actions [] =
  91. {
  92. {
  93. ACTION_SPND,
  94. "suspend"
  95. },
  96. {
  97. ACTION_RES,
  98. "resume"
  99. }
  100. };
  101. /*====================================================================*
  102. *
  103. * signed mod_conn (struct plc * plc, uint8_t TYPE, uint16_t CID);
  104. *
  105. * Contributor(s):
  106. * Bill Wike <bill.wike@qca.qualcomm.com>
  107. *
  108. *--------------------------------------------------------------------*/
  109. static signed mod_conn (struct plc * plc, uint8_t TYPE, uint16_t CID)
  110. {
  111. struct channel * channel = (struct channel *) (plc->channel);
  112. struct message * message = (struct message *) (plc->message);
  113. #ifndef __GNUC__
  114. #pragma pack (push,1)
  115. #endif
  116. struct __packed vs_mod_conn_req
  117. {
  118. struct ethernet_hdr ethernet;
  119. struct qualcomm_hdr qualcomm;
  120. uint32_t REQ_ID;
  121. uint32_t RSVD;
  122. uint16_t CID;
  123. uint8_t MOD_CTRL;
  124. }
  125. * request = (struct vs_mod_conn_req *) (message);
  126. struct __packed vs_mod_conn_cnf
  127. {
  128. struct ethernet_hdr ethernet;
  129. struct qualcomm_hdr qualcomm;
  130. uint32_t REQ_ID;
  131. uint8_t MSTATUS;
  132. uint16_t ERR_REC_CODE;
  133. uint32_t RSVD;
  134. uint16_t CID;
  135. }
  136. * confirm = (struct vs_mod_conn_cnf *) (message);
  137. #ifndef __GNUC__
  138. #pragma pack (pop)
  139. #endif
  140. Request (plc, "COQOS modify connection");
  141. memset (message, 0, sizeof (* message));
  142. EthernetHeader (& request->ethernet, channel->peer, channel->host, channel->type);
  143. QualcommHeader (& request->qualcomm, 0, (VS_CONN_MOD | MMTYPE_REQ));
  144. plc->packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  145. request->MOD_CTRL = TYPE;
  146. request->CID = CID;
  147. if (SendMME (plc) <= 0)
  148. {
  149. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  150. return (-1);
  151. }
  152. while (ReadMME (plc, 0, (VS_CONN_MOD | MMTYPE_CNF)) > 0)
  153. {
  154. if (confirm->MSTATUS)
  155. {
  156. Failure (plc, PLC_WONTDOIT);
  157. return (-1);
  158. }
  159. Confirm (plc, "%s connection %04X", (TYPE == ACTION_SPND)? "Suspended": "Resumed", CID);
  160. }
  161. return (0);
  162. }
  163. /*====================================================================*
  164. *
  165. * int main (int argc, char const * argv[]);
  166. *
  167. *--------------------------------------------------------------------*/
  168. int main (int argc, char const * argv [])
  169. {
  170. extern struct channel channel;
  171. static char const * optv [] =
  172. {
  173. "ei:qv",
  174. "spnd,res cid",
  175. "CoQos Stream Utility",
  176. "e\tredirect stderr to stdout",
  177. #if defined (WINPCAP) || defined (LIBPCAP)
  178. "i n\thost interface is (n) [" LITERAL (CHANNEL_ETHNUMBER) "]",
  179. #else
  180. "i s\thost interface is (s) [" LITERAL (CHANNEL_ETHDEVICE) "]",
  181. #endif
  182. "q\tquiet mode",
  183. "v\tverbose mode",
  184. (char const *) (0)
  185. };
  186. #include "../plc/plc.c"
  187. uint16_t cid;
  188. uint8_t type;
  189. signed code;
  190. signed c;
  191. if (getenv (PLCDEVICE))
  192. {
  193. #if defined (WINPCAP) || defined (LIBPCAP)
  194. channel.ifindex = atoi (getenv (PLCDEVICE));
  195. #else
  196. channel.ifname = strdup (getenv (PLCDEVICE));
  197. #endif
  198. }
  199. optind = 1;
  200. while (~ (c = getoptv (argc, argv, optv)))
  201. {
  202. switch (c)
  203. {
  204. case 'e':
  205. dup2 (STDOUT_FILENO, STDERR_FILENO);
  206. break;
  207. case 'i':
  208. #if defined (WINPCAP) || defined (LIBPCAP)
  209. channel.ifindex = atoi (optarg);
  210. #else
  211. channel.ifname = optarg;
  212. #endif
  213. break;
  214. case 'q':
  215. _setbits (channel.flags, CHANNEL_SILENCE);
  216. _setbits (plc.flags, PLC_SILENCE);
  217. break;
  218. case 'v':
  219. _setbits (channel.flags, CHANNEL_VERBOSE);
  220. _setbits (plc.flags, PLC_VERBOSE);
  221. break;
  222. default:
  223. break;
  224. }
  225. }
  226. argc -= optind;
  227. argv += optind;
  228. if ((code = lookup (* argv++, actions, SIZEOF (actions))) == -1)
  229. {
  230. assist (* -- argv, ACTION, actions, SIZEOF (actions));
  231. }
  232. type = (uint8_t) (code);
  233. argc--;
  234. if (argc == 0)
  235. {
  236. error (1, ECANCELED, "Missing CID");
  237. }
  238. if (! hexencode ((uint8_t *) (& cid), sizeof (cid), * argv++))
  239. {
  240. error (1, errno, "Invalid CID");
  241. }
  242. cid = htons (cid);
  243. argc--;
  244. openchannel (& channel);
  245. if (! (plc.message = malloc (sizeof (* plc.message))))
  246. {
  247. error (1, errno, PLC_NOMEMORY);
  248. }
  249. if (! argc)
  250. {
  251. mod_conn (& plc, type, cid);
  252. }
  253. while ((argc) && (* argv))
  254. {
  255. if (! hexencode (channel.peer, sizeof (channel.peer), synonym (* argv, devices, SIZEOF (devices))))
  256. {
  257. error (1, errno, PLC_BAD_MAC, * argv);
  258. }
  259. mod_conn (& plc, type, cid);
  260. argc--;
  261. argv++;
  262. }
  263. free (plc.message);
  264. closechannel (& channel);
  265. exit (0);
  266. }