coqos_man.c.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  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_man.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_info.c.html' title=' coqos_info.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='coqos_mod.c.html' title=' coqos_mod.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_man.c - Manage MCSMA streams
  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. #include &quot;../plc/coqos.h&quot;
  93. /*====================================================================*
  94. * custom source files;
  95. *--------------------------------------------------------------------*/
  96. #ifndef MAKEFILE
  97. #include &quot;../tools/getoptv.c&quot;
  98. #include &quot;../tools/putoptv.c&quot;
  99. #include &quot;../tools/version.c&quot;
  100. #include &quot;../tools/uintspec.c&quot;
  101. #include &quot;../tools/hexdump.c&quot;
  102. #include &quot;../tools/hexencode.c&quot;
  103. #include &quot;../tools/hexdecode.c&quot;
  104. #include &quot;../tools/todigit.c&quot;
  105. #include &quot;../tools/typename.c&quot;
  106. #include &quot;../tools/error.c&quot;
  107. #include &quot;../tools/synonym.c&quot;
  108. #endif
  109. #ifndef MAKEFILE
  110. #include &quot;../plc/Request.c&quot;
  111. #include &quot;../plc/Confirm.c&quot;
  112. #include &quot;../plc/Failure.c&quot;
  113. #include &quot;../plc/Display.c&quot;
  114. #include &quot;../plc/ReadMME.c&quot;
  115. #include &quot;../plc/SendMME.c&quot;
  116. #include &quot;../plc/Devices.c&quot;
  117. #endif
  118. #ifndef MAKEFILE
  119. #include &quot;../ether/openchannel.c&quot;
  120. #include &quot;../ether/closechannel.c&quot;
  121. #include &quot;../ether/readpacket.c&quot;
  122. #include &quot;../ether/sendpacket.c&quot;
  123. #include &quot;../ether/channel.c&quot;
  124. #endif
  125. #ifndef MAKEFILE
  126. #include &quot;../mme/MMECode.c&quot;
  127. #include &quot;../mme/EthernetHeader.c&quot;
  128. #include &quot;../mme/QualcommHeader.c&quot;
  129. #include &quot;../mme/UnwantedMessage.c&quot;
  130. #endif
  131. /*====================================================================*
  132. *
  133. * signed con_man (struct plc * plc, uint16_t TOT_BW_USED);
  134. *
  135. *
  136. *
  137. * Contributor(s):
  138. * Bill Wike &lt;bill.wike@qca.qualcomm.com&gt;
  139. *
  140. *--------------------------------------------------------------------*/
  141. signed con_man (struct plc * plc, uint16_t TOT_BW_USED)
  142. {
  143. struct channel * channel = (struct channel *)(plc-&gt;channel);
  144. struct message * message = (struct message *)(plc-&gt;message);
  145. #ifndef __GNUC__
  146. #pragma pack (push,1)
  147. #endif
  148. struct __packed vs_con_info_req
  149. {
  150. struct ethernet_hdr ethernet;
  151. struct qualcomm_hdr qualcomm;
  152. uint8_t REQ_TYPE;
  153. uint32_t RSVD;
  154. uint16_t CSPEC_VER;
  155. uint16_t CID;
  156. uint16_t TOT_BW_USED;
  157. }
  158. * request = (struct vs_con_info_req *)(message);
  159. struct __packed vs_con_info_cnf
  160. {
  161. struct ethernet_hdr ethernet;
  162. struct qualcomm_hdr qualcomm;
  163. uint8_t REQ_TYPE;
  164. uint8_t MSTATUS;
  165. uint16_t ERR_REC_CODE;
  166. uint32_t RSVD;
  167. uint8_t NUM_CONN;
  168. struct conn_info CONN_INFO [64];
  169. }
  170. * confirm = (struct vs_con_info_cnf *)(message);
  171. struct conn_info * conn_info =(struct conn_info*)(confirm-&gt;CONN_INFO);
  172. struct vs_con_info_cnf *indicate = (struct vs_con_info_cnf *)(message);
  173. struct __packed vs_mod_conn_req
  174. {
  175. struct ethernet_hdr ethernet;
  176. struct qualcomm_hdr qualcomm;
  177. uint32_t REQ_ID;
  178. uint32_t RSVD;
  179. uint16_t CID;
  180. uint8_t MOD_CTRL;
  181. }
  182. * mc_request = (struct vs_mod_conn_req *)(message);
  183. struct __packed vs_mod_conn_cnf
  184. {
  185. struct ethernet_hdr ethernet;
  186. struct qualcomm_hdr qualcomm;
  187. uint32_t REQ_ID;
  188. uint8_t MSTATUS;
  189. uint16_t ERR_REC_CODE;
  190. uint32_t RSVD;
  191. }
  192. * mc_confirm = (struct vs_mod_conn_cnf *)(message);
  193. #ifndef __GNUC__
  194. #pragma pack (pop)
  195. #endif
  196. int i;
  197. int bwused;
  198. int lowest;
  199. uint16_t lowcid;
  200. while (1)
  201. {
  202. Request (plc, &quot;COQOS connection information (requesting bandwidth notification)&quot;);
  203. memset (message, 0, sizeof (* message));
  204. EthernetHeader (&amp;request-&gt;ethernet, channel-&gt;peer, channel-&gt;host, channel-&gt;type);
  205. QualcommHeader (&amp;request-&gt;qualcomm, 0, (VS_CONN_INFO | MMTYPE_REQ));
  206. plc-&gt;packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  207. request-&gt;REQ_TYPE = 0x04;
  208. request-&gt;CID = 0x00;
  209. request-&gt;CSPEC_VER = 0x01;
  210. request-&gt;TOT_BW_USED = TOT_BW_USED;
  211. if (SendMME (plc) &lt;= 0)
  212. {
  213. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  214. return (-1);
  215. }
  216. while (ReadMME (plc, 0, (VS_CONN_INFO | MMTYPE_CNF)) &lt;= 0);
  217. if (confirm-&gt;MSTATUS)
  218. {
  219. Failure (plc, &quot;Could not set up bandwidth notification.&quot;);
  220. }
  221. else
  222. {
  223. Confirm (plc, &quot;Set up bandwidth monitoring.&quot;);
  224. break;
  225. }
  226. sleep (1);
  227. }
  228. while (1)
  229. {
  230. /*
  231. * Wait for indications saying too much bandwidth is
  232. * in use.
  233. */
  234. while (ReadMME (plc, 0, (VS_CONN_INFO | MMTYPE_IND)) &lt;= 0)
  235. {
  236. continue;
  237. }
  238. if (indicate-&gt;MSTATUS)
  239. {
  240. Failure (plc, &quot;Connection Info Indicate error&quot;);
  241. continue;
  242. }
  243. printf (&quot;Number of Connections: %d\n&quot;, indicate-&gt;NUM_CONN);
  244. conn_info = (struct conn_info *)(confirm-&gt;CONN_INFO);
  245. bwused = 0;
  246. lowest = conn_info-&gt;CONN_COQOS_PRIO;
  247. lowcid = conn_info-&gt;CID;
  248. for (i = 0; i &lt; indicate-&gt;NUM_CONN; i++)
  249. {
  250. bwused += conn_info-&gt;BW_USED;
  251. if (conn_info-&gt;CONN_COQOS_PRIO &lt; lowest)
  252. {
  253. lowest = conn_info-&gt;CONN_COQOS_PRIO;
  254. lowcid = conn_info-&gt;CID;
  255. }
  256. conn_info++;
  257. }
  258. printf (&quot;Total bandwidth used: %d\n&quot;, bwused);
  259. if (bwused &lt;= TOT_BW_USED)
  260. {
  261. continue;
  262. }
  263. printf (&quot;Bandwidth limit exceeded dropping: %04X\n&quot;, lowcid);
  264. Request (plc, &quot;COQOS Modify Connection (suspend)&quot;);
  265. memset (message, 0, sizeof (* message));
  266. EthernetHeader (&amp;request-&gt;ethernet, channel-&gt;peer, channel-&gt;host, channel-&gt;type);
  267. QualcommHeader (&amp;request-&gt;qualcomm, 0, (VS_CONN_MOD | MMTYPE_REQ));
  268. plc-&gt;packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  269. mc_request-&gt;MOD_CTRL = 0x00;
  270. mc_request-&gt;CID = lowcid;
  271. if (SendMME (plc) &lt;= 0)
  272. {
  273. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  274. return (-1);
  275. }
  276. while (ReadMME (plc, 0, (VS_CONN_MOD | MMTYPE_CNF)) &lt;= 0);
  277. if (mc_confirm-&gt;MSTATUS)
  278. {
  279. Failure (plc, &quot;Could not suspend stream.&quot;);
  280. continue;
  281. }
  282. printf (&quot;Connection ID: %04X suspended\n&quot;, lowcid);
  283. sleep (5);
  284. /* flush out old data */
  285. while (ReadMME (plc, 0, (VS_CONN_INFO | MMTYPE_IND)) &gt; 0);
  286. }
  287. return (0);
  288. }
  289. /*====================================================================*
  290. *
  291. * int main (int argc, char const * argv[]);
  292. *
  293. *
  294. *--------------------------------------------------------------------*/
  295. int main (int argc, char const * argv [])
  296. {
  297. extern struct channel channel;
  298. static char const * optv [] =
  299. {
  300. &quot;ei:qv&quot;,
  301. &quot;limit [device] [...]&quot;,
  302. &quot;CoQos Stream Utility&quot;,
  303. &quot;e\tredirect stderr to stdout&quot;,
  304. #if defined (WINPCAP) || defined (LIBPCAP)
  305. &quot;i n\thost interface is (n) [&quot; LITERAL (CHANNEL_ETHNUMBER) &quot;]&quot;,
  306. #else
  307. &quot;i s\thost interface is (s) [&quot; LITERAL (CHANNEL_ETHDEVICE) &quot;]&quot;,
  308. #endif
  309. &quot;q\tquiet mode&quot;,
  310. &quot;v\tverbose mode&quot;,
  311. (char const *) (0)
  312. };
  313. #include &quot;../plc/plc.c&quot;
  314. uint16_t limit;
  315. signed c;
  316. if (getenv (PLCDEVICE))
  317. {
  318. #if defined (WINPCAP) || defined (LIBPCAP)
  319. channel.ifindex = atoi (getenv (PLCDEVICE));
  320. #else
  321. channel.ifname = strdup (getenv (PLCDEVICE));
  322. #endif
  323. }
  324. optind = 1;
  325. while ((c = getoptv (argc, argv, optv)) != -1)
  326. {
  327. switch (c)
  328. {
  329. case 'e':
  330. dup2 (STDOUT_FILENO, STDERR_FILENO);
  331. break;
  332. case 'i':
  333. #if defined (WINPCAP) || defined (LIBPCAP)
  334. channel.ifindex = atoi (optarg);
  335. #else
  336. channel.ifname = optarg;
  337. #endif
  338. break;
  339. case 'q':
  340. _setbits (channel.flags, CHANNEL_SILENCE);
  341. _setbits (plc.flags, PLC_SILENCE);
  342. break;
  343. case 'v':
  344. _setbits (channel.flags, CHANNEL_VERBOSE);
  345. _setbits (plc.flags, PLC_VERBOSE);
  346. break;
  347. default:
  348. break;
  349. }
  350. }
  351. argc -= optind;
  352. argv += optind;
  353. if (!argc)
  354. {
  355. error (1, ECANCELED, &quot;No limit given&quot;);
  356. }
  357. limit = (uint16_t)(uintspec (* argv++, 10, 90000));
  358. argc--;
  359. openchannel (&amp;channel);
  360. if (!(plc.message = malloc (sizeof (* plc.message))))
  361. {
  362. error (1, errno, PLC_NOMEMORY);
  363. }
  364. if (!argc)
  365. {
  366. con_man (&amp;plc, limit);
  367. }
  368. while ((argc) &amp;&amp; (* argv))
  369. {
  370. if (!hexencode (channel.peer, sizeof (channel.peer), synonym (* argv, devices, SIZEOF (devices))))
  371. {
  372. error (1, errno, PLC_BAD_MAC, * argv);
  373. }
  374. con_man (&amp;plc, limit);
  375. argc--;
  376. argv++;
  377. }
  378. free (plc.message);
  379. closechannel (&amp;channel);
  380. exit (0);
  381. }
  382. </pre>
  383. <div class='footerlink'>
  384. [<a href='coqos_info.c.html' title=' coqos_info.c '>PREV</a>]
  385. [<a href='toolkit.html' title=' Index '>HOME</a>]
  386. [<a href='coqos_mod.c.html' title=' coqos_mod.c '>NEXT</a>]
  387. </div>
  388. </body>
  389. </html>