coqos_mod.c.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. <?xml version='1.0' encoding='iso-8859-1'?>
  2. <!doctype html public '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
  3. <html xmlns='http://www.w3c.org/1999/xhtml' lang='en-us'>
  4. <head>
  5. <title>
  6. coqos_mod.c
  7. </title>
  8. <meta http-equiv='content-type' content='text/html;iso-8859-1'/>
  9. <meta name='generator' content='motley-tools 1.9.4 13:40:33 Feb 18 2015'/>
  10. <meta name='author' content='cmaier@cmassoc.net'/>
  11. <meta name='robots' content='noindex,nofollow'/>
  12. <link href='toolkit.css' rel='stylesheet' type='text/css'/>
  13. </head>
  14. <body>
  15. <div class='headerlink'>
  16. [<a href='coqos_man.c.html' title=' coqos_man.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='coqos_rel.c.html' title=' coqos_rel.c '>NEXT</a>]
  19. </div>
  20. <pre>
  21. /*====================================================================*
  22. *
  23. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  24. *
  25. * All rights reserved.
  26. *
  27. * Redistribution and use in source and binary forms, with or
  28. * without modification, are permitted (subject to the limitations
  29. * in the disclaimer below) provided that the following conditions
  30. * are met:
  31. *
  32. * * Redistributions of source code must retain the above copyright
  33. * notice, this list of conditions and the following disclaimer.
  34. *
  35. * * Redistributions in binary form must reproduce the above
  36. * copyright notice, this list of conditions and the following
  37. * disclaimer in the documentation and/or other materials
  38. * provided with the distribution.
  39. *
  40. * * Neither the name of Qualcomm Atheros nor the names of
  41. * its contributors may be used to endorse or promote products
  42. * derived from this software without specific prior written
  43. * permission.
  44. *
  45. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
  46. * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE
  47. * COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot; AND ANY EXPRESS OR
  48. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  49. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  50. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  51. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  52. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  53. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  54. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  55. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  56. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  57. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  58. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  59. *
  60. *--------------------------------------------------------------------*/
  61. /*====================================================================*
  62. *
  63. * coqos_mod.c - Modify MCMSA stream
  64. *
  65. *
  66. * Contributor(s):
  67. * Bill Wike &lt;bill.wike@qca.qualcomm.com&gt;
  68. * Nathaniel Houghton &lt;nhoughto@qca.qualcomm.com&gt;
  69. * Charles Maier &lt;cmaier@qca.qualcomm.com&gt;
  70. *
  71. *--------------------------------------------------------------------*/
  72. /*====================================================================*&quot;
  73. * system header files;
  74. *--------------------------------------------------------------------*/
  75. #include &lt;unistd.h&gt;
  76. #include &lt;stdlib.h&gt;
  77. #include &lt;stdint.h&gt;
  78. #include &lt;limits.h&gt;
  79. /*====================================================================*
  80. * custom header files;
  81. *--------------------------------------------------------------------*/
  82. #include &quot;../tools/getoptv.h&quot;
  83. #include &quot;../tools/putoptv.h&quot;
  84. #include &quot;../tools/memory.h&quot;
  85. #include &quot;../tools/number.h&quot;
  86. #include &quot;../tools/symbol.h&quot;
  87. #include &quot;../tools/types.h&quot;
  88. #include &quot;../tools/flags.h&quot;
  89. #include &quot;../tools/files.h&quot;
  90. #include &quot;../tools/error.h&quot;
  91. #include &quot;../plc/plc.h&quot;
  92. /*====================================================================*
  93. * custom source files;
  94. *--------------------------------------------------------------------*/
  95. #ifndef MAKEFILE
  96. #include &quot;../tools/getoptv.c&quot;
  97. #include &quot;../tools/putoptv.c&quot;
  98. #include &quot;../tools/version.c&quot;
  99. #include &quot;../tools/hexdump.c&quot;
  100. #include &quot;../tools/hexencode.c&quot;
  101. #include &quot;../tools/bytespec.c&quot;
  102. #include &quot;../tools/ipv4spec.c&quot;
  103. #include &quot;../tools/ipv6spec.c&quot;
  104. #include &quot;../tools/hexdecode.c&quot;
  105. #include &quot;../tools/todigit.c&quot;
  106. #include &quot;../tools/typename.c&quot;
  107. #include &quot;../tools/error.c&quot;
  108. #include &quot;../tools/synonym.c&quot;
  109. #include &quot;../tools/lookup.c&quot;
  110. #include &quot;../tools/assist.c&quot;
  111. #include &quot;../tools/codelist.c&quot;
  112. #endif
  113. #ifndef MAKEFILE
  114. #include &quot;../plc/Request.c&quot;
  115. #include &quot;../plc/Confirm.c&quot;
  116. #include &quot;../plc/Display.c&quot;
  117. #include &quot;../plc/Failure.c&quot;
  118. #include &quot;../plc/ReadMME.c&quot;
  119. #include &quot;../plc/SendMME.c&quot;
  120. #include &quot;../plc/Devices.c&quot;
  121. #include &quot;../mme/EthernetHeader.c&quot;
  122. #include &quot;../mme/QualcommHeader.c&quot;
  123. #include &quot;../mme/UnwantedMessage.c&quot;
  124. #endif
  125. #ifndef MAKEFILE
  126. #include &quot;../ether/channel.c&quot;
  127. #include &quot;../ether/openchannel.c&quot;
  128. #include &quot;../ether/closechannel.c&quot;
  129. #include &quot;../ether/readpacket.c&quot;
  130. #include &quot;../ether/sendpacket.c&quot;
  131. #endif
  132. #ifndef MAKEFILE
  133. #include &quot;../mme/MMECode.c&quot;
  134. #endif
  135. /*====================================================================*
  136. * constants;
  137. *--------------------------------------------------------------------*/
  138. #define ACTION &quot;action&quot;
  139. /*====================================================================*
  140. * program variables;
  141. *--------------------------------------------------------------------*/
  142. #define ACTION_SPND 0x00
  143. #define ACTION_RES 0x01
  144. static struct _code_ const actions [] =
  145. {
  146. {
  147. ACTION_SPND,
  148. &quot;suspend&quot;
  149. },
  150. {
  151. ACTION_RES,
  152. &quot;resume&quot;
  153. }
  154. };
  155. /*====================================================================*
  156. *
  157. * signed mod_conn (struct plc * plc, uint8_t TYPE, uint16_t CID);
  158. *
  159. *
  160. *
  161. * Contributor(s):
  162. * Bill Wike &lt;bill.wike@qca.qualcomm.com&gt;
  163. *
  164. *--------------------------------------------------------------------*/
  165. static signed mod_conn (struct plc * plc, uint8_t TYPE, uint16_t CID)
  166. {
  167. struct channel * channel = (struct channel *)(plc-&gt;channel);
  168. struct message * message = (struct message *)(plc-&gt;message);
  169. #ifndef __GNUC__
  170. #pragma pack (push,1)
  171. #endif
  172. struct __packed vs_mod_conn_req
  173. {
  174. struct ethernet_hdr ethernet;
  175. struct qualcomm_hdr qualcomm;
  176. uint32_t REQ_ID;
  177. uint32_t RSVD;
  178. uint16_t CID;
  179. uint8_t MOD_CTRL;
  180. }
  181. * request = (struct vs_mod_conn_req *)(message);
  182. struct __packed vs_mod_conn_cnf
  183. {
  184. struct ethernet_hdr ethernet;
  185. struct qualcomm_hdr qualcomm;
  186. uint32_t REQ_ID;
  187. uint8_t MSTATUS;
  188. uint16_t ERR_REC_CODE;
  189. uint32_t RSVD;
  190. uint16_t CID;
  191. }
  192. * confirm = (struct vs_mod_conn_cnf *)(message);
  193. #ifndef __GNUC__
  194. #pragma pack (pop)
  195. #endif
  196. Request (plc, &quot;COQOS modify connection&quot;);
  197. memset (message, 0, sizeof (* message));
  198. EthernetHeader (&amp;request-&gt;ethernet, channel-&gt;peer, channel-&gt;host, channel-&gt;type);
  199. QualcommHeader (&amp;request-&gt;qualcomm, 0, (VS_CONN_MOD | MMTYPE_REQ));
  200. plc-&gt;packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  201. request-&gt;MOD_CTRL = TYPE;
  202. request-&gt;CID = CID;
  203. if (SendMME (plc) &lt;= 0)
  204. {
  205. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  206. return (-1);
  207. }
  208. while (ReadMME (plc, 0, (VS_CONN_MOD | MMTYPE_CNF)) &gt; 0)
  209. {
  210. if (confirm-&gt;MSTATUS)
  211. {
  212. Failure (plc, PLC_WONTDOIT);
  213. return (-1);
  214. }
  215. Confirm (plc, &quot;%s connection %04X&quot;, (TYPE == ACTION_SPND)? &quot;Suspended&quot;: &quot;Resumed&quot;, CID);
  216. }
  217. return (0);
  218. }
  219. /*====================================================================*
  220. *
  221. * int main (int argc, char const * argv[]);
  222. *
  223. *
  224. *--------------------------------------------------------------------*/
  225. int main (int argc, char const * argv [])
  226. {
  227. extern struct channel channel;
  228. static char const * optv [] =
  229. {
  230. &quot;ei:qv&quot;,
  231. &quot;spnd,res cid&quot;,
  232. &quot;CoQos Stream Utility&quot;,
  233. &quot;e\tredirect stderr to stdout&quot;,
  234. #if defined (WINPCAP) || defined (LIBPCAP)
  235. &quot;i n\thost interface is (n) [&quot; LITERAL (CHANNEL_ETHNUMBER) &quot;]&quot;,
  236. #else
  237. &quot;i s\thost interface is (s) [&quot; LITERAL (CHANNEL_ETHDEVICE) &quot;]&quot;,
  238. #endif
  239. &quot;q\tquiet mode&quot;,
  240. &quot;v\tverbose mode&quot;,
  241. (char const *) (0)
  242. };
  243. #include &quot;../plc/plc.c&quot;
  244. uint16_t cid;
  245. uint8_t type;
  246. signed code;
  247. signed c;
  248. if (getenv (PLCDEVICE))
  249. {
  250. #if defined (WINPCAP) || defined (LIBPCAP)
  251. channel.ifindex = atoi (getenv (PLCDEVICE));
  252. #else
  253. channel.ifname = strdup (getenv (PLCDEVICE));
  254. #endif
  255. }
  256. optind = 1;
  257. while ((c = getoptv (argc, argv, optv)) != -1)
  258. {
  259. switch (c)
  260. {
  261. case 'e':
  262. dup2 (STDOUT_FILENO, STDERR_FILENO);
  263. break;
  264. case 'i':
  265. #if defined (WINPCAP) || defined (LIBPCAP)
  266. channel.ifindex = atoi (optarg);
  267. #else
  268. channel.ifname = optarg;
  269. #endif
  270. break;
  271. case 'q':
  272. _setbits (channel.flags, CHANNEL_SILENCE);
  273. _setbits (plc.flags, PLC_SILENCE);
  274. break;
  275. case 'v':
  276. _setbits (channel.flags, CHANNEL_VERBOSE);
  277. _setbits (plc.flags, PLC_VERBOSE);
  278. break;
  279. default:
  280. break;
  281. }
  282. }
  283. argc -= optind;
  284. argv += optind;
  285. if ((code = lookup (* argv++, actions, SIZEOF (actions))) == -1)
  286. {
  287. assist (*--argv, ACTION, actions, SIZEOF (actions));
  288. }
  289. type = (uint8_t)(code);
  290. argc--;
  291. if (argc == 0)
  292. {
  293. error (1, ECANCELED, &quot;Missing CID&quot;);
  294. }
  295. if (!hexencode ((uint8_t *)(&amp;cid), sizeof (cid), * argv++))
  296. {
  297. error (1, errno, &quot;Invalid CID&quot;);
  298. }
  299. cid = htons (cid);
  300. argc--;
  301. openchannel (&amp;channel);
  302. if (!(plc.message = malloc (sizeof (* plc.message))))
  303. {
  304. error (1, errno, PLC_NOMEMORY);
  305. }
  306. if (!argc)
  307. {
  308. mod_conn (&amp;plc, type, cid);
  309. }
  310. while ((argc) &amp;&amp; (* argv))
  311. {
  312. if (!hexencode (channel.peer, sizeof (channel.peer), synonym (* argv, devices, SIZEOF (devices))))
  313. {
  314. error (1, errno, PLC_BAD_MAC, * argv);
  315. }
  316. mod_conn (&amp;plc, type, cid);
  317. argc--;
  318. argv++;
  319. }
  320. free (plc.message);
  321. closechannel (&amp;channel);
  322. exit (0);
  323. }
  324. </pre>
  325. <div class='footerlink'>
  326. [<a href='coqos_man.c.html' title=' coqos_man.c '>PREV</a>]
  327. [<a href='toolkit.html' title=' Index '>HOME</a>]
  328. [<a href='coqos_rel.c.html' title=' coqos_rel.c '>NEXT</a>]
  329. </div>
  330. </body>
  331. </html>