coqos_add.c.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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_add.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='Confirm.c.html' title=' Confirm.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='coqos_info.c.html' title=' coqos_info.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_add.c - Add 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. #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/basespec.c&quot;
  101. #include &quot;../tools/uintspec.c&quot;
  102. #include &quot;../tools/hexdump.c&quot;
  103. #include &quot;../tools/hexencode.c&quot;
  104. #include &quot;../tools/bytespec.c&quot;
  105. #include &quot;../tools/ipv4spec.c&quot;
  106. #include &quot;../tools/ipv6spec.c&quot;
  107. #include &quot;../tools/hexdecode.c&quot;
  108. #include &quot;../tools/todigit.c&quot;
  109. #include &quot;../tools/typename.c&quot;
  110. #include &quot;../tools/error.c&quot;
  111. #include &quot;../tools/synonym.c&quot;
  112. #include &quot;../tools/lookup.c&quot;
  113. #include &quot;../tools/assist.c&quot;
  114. #include &quot;../tools/codelist.c&quot;
  115. #endif
  116. #ifndef MAKEFILE
  117. #include &quot;../plc/Request.c&quot;
  118. #include &quot;../plc/Confirm.c&quot;
  119. #include &quot;../plc/Failure.c&quot;
  120. #include &quot;../plc/Display.c&quot;
  121. #include &quot;../plc/ReadMME.c&quot;
  122. #include &quot;../plc/SendMME.c&quot;
  123. #include &quot;../plc/Devices.c&quot;
  124. #include &quot;../plc/rules.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. #include &quot;../mme/EthernetHeader.c&quot;
  136. #include &quot;../mme/QualcommHeader.c&quot;
  137. #include &quot;../mme/UnwantedMessage.c&quot;
  138. #endif
  139. /*====================================================================*
  140. *
  141. * signed add_conn (struct plc * plc, struct connection * connection);
  142. *
  143. *
  144. *
  145. * Contributor(s):
  146. * Bill Wike &lt;bill.wike@qca.qualcomm.com&gt;
  147. *
  148. *--------------------------------------------------------------------*/
  149. static signed add_conn (struct plc * plc, struct connection * connection)
  150. {
  151. struct channel * channel = (struct channel *)(plc-&gt;channel);
  152. struct message * message = (struct message *)(plc-&gt;message);
  153. #ifndef __GNUC__
  154. #pragma pack (push,1)
  155. #endif
  156. struct __packed vs_add_conn_req
  157. {
  158. struct ethernet_hdr ethernet;
  159. struct qualcomm_hdr qualcomm;
  160. struct connection connection;
  161. }
  162. * request = (struct vs_add_conn_req *)(message);
  163. struct __packed vs_add_conn_cnf
  164. {
  165. struct ethernet_hdr ethernet;
  166. struct qualcomm_hdr qualcomm;
  167. uint32_t REQ_ID;
  168. uint8_t MSTATUS;
  169. uint16_t ERR_REC_CODE;
  170. uint32_t RSVD;
  171. uint16_t CID;
  172. uint8_t REJECT_MAC [ETHER_ADDR_LEN];
  173. uint16_t CSPEC_VERSION;
  174. uint8_t CONN_CAP;
  175. uint8_t CONN_COQOS_PRIO;
  176. uint16_t CONN_RATE;
  177. uint32_t CONN_TTL;
  178. }
  179. * confirm = (struct vs_add_conn_cnf *)(message);
  180. #ifndef __GNUC__
  181. #pragma pack (pop)
  182. #endif
  183. Request (plc, &quot;Add COQOS connection&quot;);
  184. memset (message, 0, sizeof (* message));
  185. EthernetHeader (&amp;request-&gt;ethernet, channel-&gt;peer, channel-&gt;host, channel-&gt;type);
  186. QualcommHeader (&amp;request-&gt;qualcomm, 0, (VS_CONN_ADD | MMTYPE_REQ));
  187. memcpy (&amp;request-&gt;connection, connection, sizeof (struct connection));
  188. memcpy (&amp;request-&gt;connection.rule.CLASSIFIERS [request-&gt;connection.rule.NUM_CLASSIFIERS], &amp;request-&gt;connection.cspec, sizeof (request-&gt;connection.cspec));
  189. plc-&gt;packetsize = sizeof (struct vs_add_conn_req);
  190. if (SendMME (plc) &lt;= 0)
  191. {
  192. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  193. return (-1);
  194. }
  195. while (ReadMME (plc, 0, (VS_CONN_ADD | MMTYPE_CNF)) &lt;= 0)
  196. {
  197. if (confirm-&gt;MSTATUS)
  198. {
  199. Failure (plc, &quot;Device won't add connection&quot;);
  200. return (-1);
  201. }
  202. Confirm (plc, &quot;Setting ...&quot;);
  203. }
  204. return (0);
  205. }
  206. /*====================================================================*
  207. *
  208. * int main (int argc, char const * argv[]);
  209. *
  210. *
  211. *--------------------------------------------------------------------*/
  212. int main (int argc, char const * argv [])
  213. {
  214. extern struct channel channel;
  215. static char const * optv [] =
  216. {
  217. &quot;ei:qv&quot;,
  218. &quot;action priority destination rate ttl operand condition [...] [device] [...]\n\n where condition is field operator value&quot;,
  219. &quot;CoQos Stream Utility&quot;,
  220. &quot;e\tredirect stderr to stdout&quot;,
  221. #if defined (WINPCAP) || defined (LIBPCAP)
  222. &quot;i n\thost interface is (n) [&quot; LITERAL (CHANNEL_ETHNUMBER) &quot;]&quot;,
  223. #else
  224. &quot;i s\thost interface is (s) [&quot; LITERAL (CHANNEL_ETHDEVICE) &quot;]&quot;,
  225. #endif
  226. &quot;q\tquiet mode&quot;,
  227. &quot;v\tverbose mode&quot;,
  228. (char const *) (0)
  229. };
  230. #include &quot;../plc/plc.c&quot;
  231. struct connection connection;
  232. struct MMEClassifier * rule = (struct MMEClassifier *)(&amp;connection.rule.CLASSIFIERS);
  233. uint16_t * word;
  234. uint8_t * byte;
  235. signed code;
  236. signed c;
  237. if (getenv (PLCDEVICE))
  238. {
  239. #if defined (WINPCAP) || defined (LIBPCAP)
  240. channel.ifindex = atoi (getenv (PLCDEVICE));
  241. #else
  242. channel.ifname = strdup (getenv (PLCDEVICE));
  243. #endif
  244. }
  245. optind = 1;
  246. while ((c = getoptv (argc, argv, optv)) != -1)
  247. {
  248. switch (c)
  249. {
  250. case 'e':
  251. dup2 (STDOUT_FILENO, STDERR_FILENO);
  252. break;
  253. case 'i':
  254. #if defined (WINPCAP) || defined (LIBPCAP)
  255. channel.ifindex = atoi (optarg);
  256. #else
  257. channel.ifname = optarg;
  258. #endif
  259. break;
  260. case 'q':
  261. _setbits (channel.flags, CHANNEL_SILENCE);
  262. _setbits (plc.flags, PLC_SILENCE);
  263. break;
  264. case 'v':
  265. _setbits (channel.flags, CHANNEL_VERBOSE);
  266. _setbits (plc.flags, PLC_VERBOSE);
  267. break;
  268. default:
  269. break;
  270. }
  271. }
  272. argc -= optind;
  273. argv += optind;
  274. memset (&amp;connection, 0, sizeof (connection));
  275. if ((code = lookup (* argv++, actions, SIZEOF (actions))) == -1)
  276. {
  277. assist (*--argv, CLASSIFIER_ACTION_NAME, actions, SIZEOF (actions));
  278. }
  279. connection.cspec.CONN_CAP = (uint8_t)(code);
  280. argc--;
  281. if (!argc)
  282. {
  283. error (1, ECANCELED, &quot;Expected Priority: 0-15&quot;);
  284. }
  285. connection.cspec.CONN_COQOS_PRIO = (uint8_t)(uintspec (* argv++, 0, 15));
  286. argc--;
  287. if (!argc)
  288. {
  289. error (1, ECANCELED, &quot;Expected Destination MAC Address&quot;);
  290. }
  291. if (!hexencode (connection.APP_DA, sizeof (connection.APP_DA), synonym (* argv++, devices, SIZEOF (devices))))
  292. {
  293. error (1, errno, &quot;Invalid MAC=[%s]&quot;, *--argv);
  294. }
  295. argc--;
  296. if (!argc)
  297. {
  298. error (1, ECANCELED, &quot;Expected Data Rate: 10-9000 (kbps)&quot;);
  299. }
  300. connection.cspec.CONN_RATE = (uint16_t)(uintspec (* argv++, 1, 9000));
  301. argc--;
  302. if (!argc)
  303. {
  304. error (1, ECANCELED, &quot;Expected TTL: 10000-2000000 (microseconds)&quot;);
  305. }
  306. connection.cspec.CONN_TTL = (uint32_t)(uintspec (* argv++, 10000, 2000000));
  307. argc--;
  308. if ((code = lookup (* argv++, operands, SIZEOF (operands))) == -1)
  309. {
  310. assist (*--argv, CLASSIFIER_OPERAND_NAME, operands, SIZEOF (operands));
  311. }
  312. connection.rule.MOPERAND = (uint8_t)(code);
  313. argc--;
  314. while ((* argv) &amp;&amp; (lookup (* argv, controls, SIZEOF (controls)) == -1))
  315. {
  316. if ((code = lookup (* argv++, fields, SIZEOF (fields))) == -1)
  317. {
  318. assist (*--argv, CLASSIFIER_FIELD_NAME, fields, SIZEOF (fields));
  319. }
  320. rule-&gt;CR_PID = (uint8_t)(code);
  321. argc--;
  322. if ((code = lookup (* argv++, operators, SIZEOF (operators))) == -1)
  323. {
  324. assist (*--argv, CLASSIFIER_OPERATOR_NAME, operators, SIZEOF (operators));
  325. }
  326. rule-&gt;CR_OPERAND = (uint8_t)(code);
  327. argc--;
  328. if (!argc || !* argv)
  329. {
  330. error (1, ENOTSUP, &quot;Have %s '%s' without any value&quot;, CLASSIFIER_OPERATOR_NAME, *--argv);
  331. }
  332. switch (rule-&gt;CR_PID)
  333. {
  334. case FIELD_ETH_SA:
  335. case FIELD_ETH_DA:
  336. bytespec (* argv++, rule-&gt;CR_VALUE, ETHER_ADDR_LEN);
  337. break;
  338. case FIELD_IPV4_SA:
  339. case FIELD_IPV4_DA:
  340. ipv4spec (* argv++, rule-&gt;CR_VALUE);
  341. break;
  342. case FIELD_IPV6_SA:
  343. case FIELD_IPV6_DA:
  344. ipv6spec (* argv++, rule-&gt;CR_VALUE);
  345. break;
  346. case FIELD_VLAN_UP:
  347. case FIELD_IPV4_TOS:
  348. case FIELD_IPV4_PROT:
  349. byte = (uint8_t *)(rule-&gt;CR_VALUE);
  350. *byte = (uint8_t)(basespec (* argv++, 0, sizeof (* byte)));
  351. break;
  352. case FIELD_VLAN_ID:
  353. case FIELD_TCP_SP:
  354. case FIELD_TCP_DP:
  355. case FIELD_UDP_SP:
  356. case FIELD_UDP_DP:
  357. case FIELD_IP_SP:
  358. case FIELD_IP_DP:
  359. word = (uint16_t *)(rule-&gt;CR_VALUE);
  360. *word = (uint16_t)(basespec (* argv++, 0, sizeof (* word)));
  361. *word = htons (*word);
  362. break;
  363. case FIELD_ETH_TYPE:
  364. word = (uint16_t *)(rule-&gt;CR_VALUE);
  365. *word = (uint16_t)(basespec (* argv++, 0, sizeof (* word)));
  366. *word = htons (*word);
  367. break;
  368. case FIELD_HPAV_MME:
  369. bytespec (* argv++, rule-&gt;CR_VALUE, sizeof (uint8_t) + sizeof (uint16_t));
  370. byte = (uint8_t *)(rule-&gt;CR_VALUE);
  371. HTOBE16 ((uint16_t)(* ++byte));
  372. break;
  373. case FIELD_IPV6_TC:
  374. case FIELD_IPV6_FL:
  375. case FIELD_TCP_ACK:
  376. default:
  377. error (1, ENOTSUP, &quot;Field '%s' (0x%02X)&quot;, argv [-2], rule-&gt;CR_PID);
  378. break;
  379. }
  380. connection.rule.NUM_CLASSIFIERS++;
  381. if (connection.rule.NUM_CLASSIFIERS &gt; RULE_MAX_CLASSIFIERS)
  382. {
  383. error (1, ENOTSUP, &quot;More than %d classifiers in rule&quot;, RULE_MAX_CLASSIFIERS);
  384. }
  385. rule++;
  386. argc--;
  387. }
  388. connection.cspec.CSPEC_VERSION = 0x0001;
  389. openchannel (&amp;channel);
  390. if (!(plc.message = malloc (sizeof (* plc.message))))
  391. {
  392. error (1, errno, PLC_NOMEMORY);
  393. }
  394. if (!argc)
  395. {
  396. add_conn (&amp;plc, &amp;connection);
  397. }
  398. while ((argc) &amp;&amp; (* argv))
  399. {
  400. if (!hexencode (channel.peer, sizeof (channel.peer), synonym (* argv, devices, SIZEOF (devices))))
  401. {
  402. error (1, errno, PLC_BAD_MAC, * argv);
  403. }
  404. add_conn (&amp;plc, &amp;connection);
  405. argc--;
  406. argv++;
  407. }
  408. free (plc.message);
  409. closechannel (&amp;channel);
  410. exit (0);
  411. }
  412. </pre>
  413. <div class='footerlink'>
  414. [<a href='Confirm.c.html' title=' Confirm.c '>PREV</a>]
  415. [<a href='toolkit.html' title=' Index '>HOME</a>]
  416. [<a href='coqos_info.c.html' title=' coqos_info.c '>NEXT</a>]
  417. </div>
  418. </body>
  419. </html>