coqos_info.c.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  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_info.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_add.c.html' title=' coqos_add.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='coqos_man.c.html' title=' coqos_man.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_info.c - Retrieve MCMSA stream info
  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/hexdump.c&quot;
  101. #include &quot;../tools/hexencode.c&quot;
  102. #include &quot;../tools/bytespec.c&quot;
  103. #include &quot;../tools/ipv4spec.c&quot;
  104. #include &quot;../tools/ipv6spec.c&quot;
  105. #include &quot;../tools/hexdecode.c&quot;
  106. #include &quot;../tools/todigit.c&quot;
  107. #include &quot;../tools/typename.c&quot;
  108. #include &quot;../tools/error.c&quot;
  109. #include &quot;../tools/synonym.c&quot;
  110. #include &quot;../tools/lookup.c&quot;
  111. #include &quot;../tools/assist.c&quot;
  112. #include &quot;../tools/codelist.c&quot;
  113. #endif
  114. #ifndef MAKEFILE
  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/Request.c&quot;
  120. #include &quot;../plc/SendMME.c&quot;
  121. #include &quot;../plc/Devices.c&quot;
  122. #include &quot;../mme/EthernetHeader.c&quot;
  123. #include &quot;../mme/QualcommHeader.c&quot;
  124. #include &quot;../mme/UnwantedMessage.c&quot;
  125. #endif
  126. #ifndef MAKEFILE
  127. #include &quot;../ether/channel.c&quot;
  128. #include &quot;../ether/openchannel.c&quot;
  129. #include &quot;../ether/closechannel.c&quot;
  130. #include &quot;../ether/readpacket.c&quot;
  131. #include &quot;../ether/sendpacket.c&quot;
  132. #endif
  133. #ifndef MAKEFILE
  134. #include &quot;../mme/MMECode.c&quot;
  135. #endif
  136. /*====================================================================*
  137. * constants;
  138. *--------------------------------------------------------------------*/
  139. #define CONTROL &quot;control&quot;
  140. /*====================================================================*
  141. * program variables;
  142. *--------------------------------------------------------------------*/
  143. #define CONTROL_STA 0x00
  144. #define CONTROL_CID 0x01
  145. #define CONTROL_RSVD 0x02
  146. #define CONTROL_VIC 0x03
  147. #define CONTROL_BW 0x04
  148. #define CONTROL_BWC 0xFF
  149. static struct _code_ const types [] =
  150. {
  151. {
  152. CONTROL_STA,
  153. &quot;STA&quot;
  154. },
  155. {
  156. CONTROL_CID,
  157. &quot;CID&quot;
  158. },
  159. {
  160. CONTROL_RSVD,
  161. &quot;RSVD&quot;
  162. },
  163. {
  164. CONTROL_VIC,
  165. &quot;VIC&quot;
  166. },
  167. {
  168. CONTROL_BW,
  169. &quot;BW&quot;
  170. },
  171. {
  172. CONTROL_BWC,
  173. &quot;BWC&quot;
  174. }
  175. };
  176. /*====================================================================*
  177. *
  178. * signed con_info (struct plc * plc, uint8_t TYPE, uint16_t CID, uint16_t TOT_BW_USED);
  179. *
  180. *
  181. *
  182. * Contributor(s):
  183. * Bill Wike &lt;bill.wike@qca.qualcomm.com&gt;
  184. *
  185. *--------------------------------------------------------------------*/
  186. static signed con_info (struct plc * plc, uint8_t TYPE, uint16_t CID, uint16_t TOT_BW_USED)
  187. {
  188. struct channel * channel = (struct channel *)(plc-&gt;channel);
  189. struct message * message = (struct message *)(plc-&gt;message);
  190. #ifndef __GNUC__
  191. #pragma pack (push,1)
  192. #endif
  193. struct __packed vs_con_info_req
  194. {
  195. struct ethernet_hdr ethernet;
  196. struct qualcomm_hdr qualcomm;
  197. uint8_t REQ_TYPE;
  198. uint32_t RSVD;
  199. uint16_t CSPEC_VER;
  200. uint16_t CID;
  201. uint16_t TOT_BW_USED;
  202. }
  203. * request = (struct vs_con_info_req *)(message);
  204. struct __packed vs_con_info_cnf
  205. {
  206. struct ethernet_hdr ethernet;
  207. struct qualcomm_hdr qualcomm;
  208. uint8_t REQ_TYPE;
  209. uint8_t MSTATUS;
  210. uint16_t ERR_REC_CODE;
  211. uint32_t RSVD;
  212. uint8_t NUM_CONN;
  213. struct conn_info CONN_INFO [64];
  214. }
  215. * confirm = (struct vs_con_info_cnf *)(message);
  216. struct conn_info * conn_info = (struct conn_info*)(confirm-&gt;CONN_INFO);
  217. struct vs_con_info_cnf * indicate = (struct vs_con_info_cnf *)(message);
  218. #ifndef __GNUC__
  219. #pragma pack (pop)
  220. #endif
  221. int i;
  222. Request (plc, &quot;COQOS connection information&quot;);
  223. memset (message, 0, sizeof (* message));
  224. EthernetHeader (&amp;request-&gt;ethernet, channel-&gt;peer, channel-&gt;host, channel-&gt;type);
  225. QualcommHeader (&amp;request-&gt;qualcomm, 0, (VS_CONN_INFO | MMTYPE_REQ));
  226. plc-&gt;packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  227. request-&gt;REQ_TYPE = TYPE;
  228. request-&gt;CID = CID;
  229. request-&gt;TOT_BW_USED = TOT_BW_USED;
  230. request-&gt;CSPEC_VER = 0x01;
  231. if (SendMME (plc) &lt;= 0)
  232. {
  233. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  234. return (-1);
  235. }
  236. while (ReadMME (plc, 0, (VS_CONN_INFO | MMTYPE_CNF)) &lt;= 0);
  237. if (confirm-&gt;MSTATUS)
  238. {
  239. Failure (plc, &quot;Error requesting information.&quot;);
  240. return (-1);
  241. }
  242. /* BW exceeded request and &quot;cancel all requests&quot; do not send indicate */
  243. if ((TYPE == CONTROL_BW) || (TYPE == CONTROL_BWC))
  244. {
  245. Confirm (plc, &quot;Success&quot;);
  246. return (0);
  247. }
  248. Confirm (plc, &quot;Received confirm, waiting for indicate...&quot;);
  249. while (ReadMME (plc, 0, (VS_CONN_INFO | MMTYPE_IND)) &lt;= 0);
  250. if (indicate-&gt;MSTATUS)
  251. {
  252. Failure (plc, &quot;Error requesting information.&quot;);
  253. return (-1);
  254. }
  255. printf (&quot;Number of Connections: %d\n&quot;, (int)indicate-&gt;NUM_CONN);
  256. conn_info = (struct conn_info *)(indicate-&gt;CONN_INFO);
  257. for (i = 0; i &lt; indicate-&gt;NUM_CONN; i++)
  258. {
  259. printf (&quot;SNID: %02X &quot;, conn_info-&gt;SNID);
  260. printf (&quot;CID: %04X &quot;, conn_info-&gt;CID);
  261. printf (&quot;STEI: %02X &quot;, conn_info-&gt;STEI);
  262. printf (&quot;DTEI: %02X &quot;, conn_info-&gt;DTEI);
  263. printf (&quot;LLID: %02X &quot;, conn_info-&gt;LLID);
  264. printf (&quot;CSPEC_VERSION: %04X &quot;, conn_info-&gt;CSPECVERSION);
  265. printf (&quot;CONN_CAP: %02d &quot;, conn_info-&gt;CONN_CAP);
  266. printf (&quot;CONN_COQOS_PRIO: %02d &quot;, conn_info-&gt;CONN_COQOS_PRIO);
  267. printf (&quot;CONN_RATE: %d &quot;, conn_info-&gt;CONN_RATE);
  268. printf (&quot;CONN_TTL: %d &quot;, conn_info-&gt;CONN_TTL);
  269. printf (&quot;BW_USED: %d \n&quot;, conn_info-&gt;BW_USED);
  270. conn_info++;
  271. }
  272. return (0);
  273. }
  274. /*====================================================================*
  275. *
  276. * int main (int argc, char const * argv[]);
  277. *
  278. *
  279. *--------------------------------------------------------------------*/
  280. int main (int argc, char const * argv [])
  281. {
  282. extern struct channel channel;
  283. static char const * optv [] =
  284. {
  285. &quot;ei:qv&quot;,
  286. &quot;[sta|cid|rsvd|vic|bw|bwc] [limit] [device] [...]&quot;,
  287. &quot;CoQos Stream Utility&quot;,
  288. &quot;e\tredirect stderr to stdout&quot;,
  289. #if defined (WINPCAP) || defined (LIBPCAP)
  290. &quot;i n\thost interface is (n) [&quot; LITERAL (CHANNEL_ETHNUMBER) &quot;]&quot;,
  291. #else
  292. &quot;i s\thost interface is (s) [&quot; LITERAL (CHANNEL_ETHDEVICE) &quot;]&quot;,
  293. #endif
  294. &quot;q\tquiet mode&quot;,
  295. &quot;v\tverbose mode&quot;,
  296. (char const *) (0)
  297. };
  298. #include &quot;../plc/plc.c&quot;
  299. uint16_t cid = 0;
  300. uint16_t limit = 0;
  301. uint8_t type;
  302. signed code;
  303. signed c;
  304. if (getenv (PLCDEVICE))
  305. {
  306. #if defined (WINPCAP) || defined (LIBPCAP)
  307. channel.ifindex = atoi (getenv (PLCDEVICE));
  308. #else
  309. channel.ifname = strdup (getenv (PLCDEVICE));
  310. #endif
  311. }
  312. optind = 1;
  313. while ((c = getoptv (argc, argv, optv)) != -1)
  314. {
  315. switch (c)
  316. {
  317. case 'e':
  318. dup2 (STDOUT_FILENO, STDERR_FILENO);
  319. break;
  320. case 'i':
  321. #if defined (WINPCAP) || defined (LIBPCAP)
  322. channel.ifindex = atoi (optarg);
  323. #else
  324. channel.ifname = optarg;
  325. #endif
  326. break;
  327. case 'q':
  328. _setbits (channel.flags, CHANNEL_SILENCE);
  329. _setbits (plc.flags, PLC_SILENCE);
  330. break;
  331. case 'v':
  332. _setbits (channel.flags, CHANNEL_VERBOSE);
  333. _setbits (plc.flags, PLC_VERBOSE);
  334. break;
  335. default:
  336. break;
  337. }
  338. }
  339. argc -= optind;
  340. argv += optind;
  341. if ((code = lookup (* argv++, types, SIZEOF (types))) == -1)
  342. {
  343. assist (*--argv, CONTROL, types, SIZEOF (types));
  344. }
  345. type = (uint8_t)(code);
  346. argc--;
  347. if (type == CONTROL_CID)
  348. {
  349. if (!argc)
  350. {
  351. error (1, errno, &quot;Expected Connection Identifier&quot;);
  352. }
  353. if (!hexencode ((uint8_t *)(&amp;cid), sizeof (cid), * argv++))
  354. {
  355. error (1, errno, &quot;Invalid CID&quot;);
  356. }
  357. cid = htons (cid);
  358. argc--;
  359. }
  360. else if (type == CONTROL_BW)
  361. {
  362. if (!argc)
  363. {
  364. error (1, errno, &quot;Expected Bandwidth Limit&quot;);
  365. }
  366. limit = atoi (* argv++);
  367. argc--;
  368. }
  369. openchannel (&amp;channel);
  370. if (!(plc.message = malloc (sizeof (* plc.message))))
  371. {
  372. error (1, errno, PLC_NOMEMORY);
  373. }
  374. if (!argc)
  375. {
  376. con_info (&amp;plc, type, cid, limit);
  377. }
  378. while ((argc) &amp;&amp; (* argv))
  379. {
  380. if (!hexencode (channel.peer, sizeof (channel.peer), synonym (* argv, devices, SIZEOF (devices))))
  381. {
  382. error (1, errno, PLC_BAD_MAC, * argv);
  383. }
  384. con_info (&amp;plc, type, cid, limit);
  385. argc--;
  386. argv++;
  387. }
  388. free (plc.message);
  389. closechannel (&amp;channel);
  390. exit (0);
  391. }
  392. </pre>
  393. <div class='footerlink'>
  394. [<a href='coqos_add.c.html' title=' coqos_add.c '>PREV</a>]
  395. [<a href='toolkit.html' title=' Index '>HOME</a>]
  396. [<a href='coqos_man.c.html' title=' coqos_man.c '>NEXT</a>]
  397. </div>
  398. </body>
  399. </html>