coqos_info.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or
  8. * without modification, are permitted (subject to the limitations
  9. * in the disclaimer below) provided that the following conditions
  10. * are met:
  11. *
  12. * * Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * * Redistributions in binary form must reproduce the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer in the documentation and/or other materials
  18. * provided with the distribution.
  19. *
  20. * * Neither the name of Qualcomm Atheros nor the names of
  21. * its contributors may be used to endorse or promote products
  22. * derived from this software without specific prior written
  23. * permission.
  24. *
  25. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
  26. * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE
  27. * COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  28. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  29. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  31. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  32. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  33. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  34. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  36. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  37. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. *--------------------------------------------------------------------*/
  41. /*====================================================================*
  42. *
  43. * coqos_info.c - Retrieve MCMSA stream info
  44. *
  45. *
  46. * Contributor(s):
  47. * Bill Wike
  48. * Nathaniel Houghton
  49. * Charles Maier
  50. *
  51. *--------------------------------------------------------------------*/
  52. /*====================================================================*"
  53. * system header files;
  54. *--------------------------------------------------------------------*/
  55. #include <unistd.h>
  56. #include <stdlib.h>
  57. #include <stdint.h>
  58. #include <limits.h>
  59. /*====================================================================*
  60. * custom header files;
  61. *--------------------------------------------------------------------*/
  62. #include "../tools/getoptv.h"
  63. #include "../tools/putoptv.h"
  64. #include "../tools/memory.h"
  65. #include "../tools/number.h"
  66. #include "../tools/symbol.h"
  67. #include "../tools/types.h"
  68. #include "../tools/flags.h"
  69. #include "../tools/files.h"
  70. #include "../tools/error.h"
  71. #include "../plc/plc.h"
  72. #include "../plc/coqos.h"
  73. /*====================================================================*
  74. * custom source files;
  75. *--------------------------------------------------------------------*/
  76. #ifndef MAKEFILE
  77. #include "../tools/getoptv.c"
  78. #include "../tools/putoptv.c"
  79. #include "../tools/version.c"
  80. #include "../tools/hexdump.c"
  81. #include "../tools/hexencode.c"
  82. #include "../tools/bytespec.c"
  83. #include "../tools/ipv4spec.c"
  84. #include "../tools/ipv6spec.c"
  85. #include "../tools/hexdecode.c"
  86. #include "../tools/todigit.c"
  87. #include "../tools/typename.c"
  88. #include "../tools/error.c"
  89. #include "../tools/synonym.c"
  90. #include "../tools/lookup.c"
  91. #include "../tools/assist.c"
  92. #include "../tools/codelist.c"
  93. #endif
  94. #ifndef MAKEFILE
  95. #include "../plc/Confirm.c"
  96. #include "../plc/Display.c"
  97. #include "../plc/Failure.c"
  98. #include "../plc/ReadMME.c"
  99. #include "../plc/Request.c"
  100. #include "../plc/SendMME.c"
  101. #include "../plc/Devices.c"
  102. #include "../mme/EthernetHeader.c"
  103. #include "../mme/QualcommHeader.c"
  104. #include "../mme/UnwantedMessage.c"
  105. #endif
  106. #ifndef MAKEFILE
  107. #include "../ether/channel.c"
  108. #include "../ether/openchannel.c"
  109. #include "../ether/closechannel.c"
  110. #include "../ether/readpacket.c"
  111. #include "../ether/sendpacket.c"
  112. #endif
  113. #ifndef MAKEFILE
  114. #include "../mme/MMECode.c"
  115. #endif
  116. /*====================================================================*
  117. * constants;
  118. *--------------------------------------------------------------------*/
  119. #define CONTROL "control"
  120. /*====================================================================*
  121. * program variables;
  122. *--------------------------------------------------------------------*/
  123. #define CONTROL_STA 0x00
  124. #define CONTROL_CID 0x01
  125. #define CONTROL_RSVD 0x02
  126. #define CONTROL_VIC 0x03
  127. #define CONTROL_BW 0x04
  128. #define CONTROL_BWC 0xFF
  129. static struct _code_ const types [] =
  130. {
  131. {
  132. CONTROL_STA,
  133. "STA"
  134. },
  135. {
  136. CONTROL_CID,
  137. "CID"
  138. },
  139. {
  140. CONTROL_RSVD,
  141. "RSVD"
  142. },
  143. {
  144. CONTROL_VIC,
  145. "VIC"
  146. },
  147. {
  148. CONTROL_BW,
  149. "BW"
  150. },
  151. {
  152. CONTROL_BWC,
  153. "BWC"
  154. }
  155. };
  156. /*====================================================================*
  157. *
  158. * signed con_info (struct plc * plc, uint8_t TYPE, uint16_t CID, uint16_t TOT_BW_USED);
  159. *
  160. *
  161. *
  162. * Contributor(s):
  163. * Bill Wike
  164. *
  165. *--------------------------------------------------------------------*/
  166. static signed con_info (struct plc * plc, uint8_t TYPE, uint16_t CID, uint16_t TOT_BW_USED)
  167. {
  168. struct channel * channel = (struct channel *)(plc->channel);
  169. struct message * message = (struct message *)(plc->message);
  170. #ifndef __GNUC__
  171. #pragma pack (push,1)
  172. #endif
  173. struct __packed vs_con_info_req
  174. {
  175. struct ethernet_hdr ethernet;
  176. struct qualcomm_hdr qualcomm;
  177. uint8_t REQ_TYPE;
  178. uint32_t RSVD;
  179. uint16_t CSPEC_VER;
  180. uint16_t CID;
  181. uint16_t TOT_BW_USED;
  182. }
  183. * request = (struct vs_con_info_req *)(message);
  184. struct __packed vs_con_info_cnf
  185. {
  186. struct ethernet_hdr ethernet;
  187. struct qualcomm_hdr qualcomm;
  188. uint8_t REQ_TYPE;
  189. uint8_t MSTATUS;
  190. uint16_t ERR_REC_CODE;
  191. uint32_t RSVD;
  192. uint8_t NUM_CONN;
  193. struct conn_info CONN_INFO [64];
  194. }
  195. * confirm = (struct vs_con_info_cnf *)(message);
  196. struct conn_info * conn_info = (struct conn_info*)(confirm->CONN_INFO);
  197. struct vs_con_info_cnf * indicate = (struct vs_con_info_cnf *)(message);
  198. #ifndef __GNUC__
  199. #pragma pack (pop)
  200. #endif
  201. int i;
  202. Request (plc, "COQOS connection information");
  203. memset (message, 0, sizeof (* message));
  204. EthernetHeader (&request->ethernet, channel->peer, channel->host, channel->type);
  205. QualcommHeader (&request->qualcomm, 0, (VS_CONN_INFO | MMTYPE_REQ));
  206. plc->packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  207. request->REQ_TYPE = TYPE;
  208. request->CID = CID;
  209. request->TOT_BW_USED = TOT_BW_USED;
  210. request->CSPEC_VER = 0x01;
  211. if (SendMME (plc) <= 0)
  212. {
  213. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  214. return (-1);
  215. }
  216. while (ReadMME (plc, 0, (VS_CONN_INFO | MMTYPE_CNF)) <= 0);
  217. if (confirm->MSTATUS)
  218. {
  219. Failure (plc, "Error requesting information.");
  220. return (-1);
  221. }
  222. /* BW exceeded request and "cancel all requests" do not send indicate */
  223. if ((TYPE == CONTROL_BW) || (TYPE == CONTROL_BWC))
  224. {
  225. Confirm (plc, "Success");
  226. return (0);
  227. }
  228. Confirm (plc, "Received confirm, waiting for indicate...");
  229. while (ReadMME (plc, 0, (VS_CONN_INFO | MMTYPE_IND)) <= 0);
  230. if (indicate->MSTATUS)
  231. {
  232. Failure (plc, "Error requesting information.");
  233. return (-1);
  234. }
  235. printf ("Number of Connections: %d\n", (int)indicate->NUM_CONN);
  236. conn_info = (struct conn_info *)(indicate->CONN_INFO);
  237. for (i = 0; i < indicate->NUM_CONN; i++)
  238. {
  239. printf ("SNID: %02X ", conn_info->SNID);
  240. printf ("CID: %04X ", conn_info->CID);
  241. printf ("STEI: %02X ", conn_info->STEI);
  242. printf ("DTEI: %02X ", conn_info->DTEI);
  243. printf ("LLID: %02X ", conn_info->LLID);
  244. printf ("CSPEC_VERSION: %04X ", conn_info->CSPECVERSION);
  245. printf ("CONN_CAP: %02d ", conn_info->CONN_CAP);
  246. printf ("CONN_COQOS_PRIO: %02d ", conn_info->CONN_COQOS_PRIO);
  247. printf ("CONN_RATE: %d ", conn_info->CONN_RATE);
  248. printf ("CONN_TTL: %d ", conn_info->CONN_TTL);
  249. printf ("BW_USED: %d \n", conn_info->BW_USED);
  250. conn_info++;
  251. }
  252. return (0);
  253. }
  254. /*====================================================================*
  255. *
  256. * int main (int argc, char const * argv[]);
  257. *
  258. *
  259. *--------------------------------------------------------------------*/
  260. int main (int argc, char const * argv [])
  261. {
  262. extern struct channel channel;
  263. static char const * optv [] =
  264. {
  265. "ei:qv",
  266. "[sta|cid|rsvd|vic|bw|bwc] [limit] [device] [...]",
  267. "CoQos Stream Utility",
  268. "e\tredirect stderr to stdout",
  269. #if defined (WINPCAP) || defined (LIBPCAP)
  270. "i n\thost interface is (n) [" LITERAL (CHANNEL_ETHNUMBER) "]",
  271. #else
  272. "i s\thost interface is (s) [" LITERAL (CHANNEL_ETHDEVICE) "]",
  273. #endif
  274. "q\tquiet mode",
  275. "v\tverbose mode",
  276. (char const *) (0)
  277. };
  278. #include "../plc/plc.c"
  279. uint16_t cid = 0;
  280. uint16_t limit = 0;
  281. uint8_t type;
  282. signed code;
  283. signed c;
  284. if (getenv (PLCDEVICE))
  285. {
  286. #if defined (WINPCAP) || defined (LIBPCAP)
  287. channel.ifindex = atoi (getenv (PLCDEVICE));
  288. #else
  289. channel.ifname = strdup (getenv (PLCDEVICE));
  290. #endif
  291. }
  292. optind = 1;
  293. while ((c = getoptv (argc, argv, optv)) != -1)
  294. {
  295. switch (c)
  296. {
  297. case 'e':
  298. dup2 (STDOUT_FILENO, STDERR_FILENO);
  299. break;
  300. case 'i':
  301. #if defined (WINPCAP) || defined (LIBPCAP)
  302. channel.ifindex = atoi (optarg);
  303. #else
  304. channel.ifname = optarg;
  305. #endif
  306. break;
  307. case 'q':
  308. _setbits (channel.flags, CHANNEL_SILENCE);
  309. _setbits (plc.flags, PLC_SILENCE);
  310. break;
  311. case 'v':
  312. _setbits (channel.flags, CHANNEL_VERBOSE);
  313. _setbits (plc.flags, PLC_VERBOSE);
  314. break;
  315. default:
  316. break;
  317. }
  318. }
  319. argc -= optind;
  320. argv += optind;
  321. if ((code = lookup (* argv++, types, SIZEOF (types))) == -1)
  322. {
  323. assist (*--argv, CONTROL, types, SIZEOF (types));
  324. }
  325. type = (uint8_t)(code);
  326. argc--;
  327. if (type == CONTROL_CID)
  328. {
  329. if (!argc)
  330. {
  331. error (1, errno, "Expected Connection Identifier");
  332. }
  333. if (!hexencode ((uint8_t *)(&cid), sizeof (cid), * argv++))
  334. {
  335. error (1, errno, "Invalid CID");
  336. }
  337. cid = htons (cid);
  338. argc--;
  339. }
  340. else if (type == CONTROL_BW)
  341. {
  342. if (!argc)
  343. {
  344. error (1, errno, "Expected Bandwidth Limit");
  345. }
  346. limit = atoi (* argv++);
  347. argc--;
  348. }
  349. openchannel (&channel);
  350. if (!(plc.message = malloc (sizeof (* plc.message))))
  351. {
  352. error (1, errno, PLC_NOMEMORY);
  353. }
  354. if (!argc)
  355. {
  356. con_info (&plc, type, cid, limit);
  357. }
  358. while ((argc) && (* argv))
  359. {
  360. if (!hexencode (channel.peer, sizeof (channel.peer), synonym (* argv, devices, SIZEOF (devices))))
  361. {
  362. error (1, errno, PLC_BAD_MAC, * argv);
  363. }
  364. con_info (&plc, type, cid, limit);
  365. argc--;
  366. argv++;
  367. }
  368. free (plc.message);
  369. closechannel (&channel);
  370. exit (0);
  371. }