psout.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. * psout.c - Export PIB Prescalers;
  44. *
  45. *
  46. * Contributor(s):
  47. * Charles Maier
  48. *
  49. *--------------------------------------------------------------------*/
  50. /*====================================================================*
  51. * system header files;
  52. *--------------------------------------------------------------------*/
  53. #include <stdio.h>
  54. #include <string.h>
  55. #include <unistd.h>
  56. #include <errno.h>
  57. #include <sys/stat.h>
  58. /*====================================================================*
  59. * custom header files;
  60. *--------------------------------------------------------------------*/
  61. #include "../tools/getoptv.h"
  62. #include "../tools/number.h"
  63. #include "../tools/chars.h"
  64. #include "../tools/types.h"
  65. #include "../tools/error.h"
  66. #include "../tools/files.h"
  67. #include "../tools/endian.h"
  68. #include "../pib/pib.h"
  69. #include "../plc/plc.h"
  70. /*====================================================================*
  71. * custom source files;
  72. *--------------------------------------------------------------------*/
  73. #ifndef MAKEFILE
  74. #include "../tools/getoptv.c"
  75. #include "../tools/putoptv.c"
  76. #include "../tools/version.c"
  77. #include "../tools/checksum32.c"
  78. #include "../tools/fdchecksum32.c"
  79. #include "../tools/error.c"
  80. #endif
  81. #ifndef MAKEFILE
  82. #include "../pib/pibfile.c"
  83. #include "../pib/pibfile1.c"
  84. #include "../pib/pibfile2.c"
  85. #include "../pib/pibscalers.c"
  86. #endif
  87. /*====================================================================*
  88. * program constants;
  89. *--------------------------------------------------------------------*/
  90. #define PSOUT_VERBOSE (1 << 0)
  91. #define PSOUT_SILENCE (1 << 1)
  92. /*====================================================================*
  93. *
  94. * void ar7x00Prescalers (struct _file_ * pib);
  95. *
  96. *--------------------------------------------------------------------*/
  97. static void ar7x00Prescalers (struct _file_ * pib)
  98. {
  99. uint16_t upper;
  100. uint16_t lower;
  101. unsigned index = 0;
  102. byte buffer [AMP_PRESCALER_LENGTH];
  103. byte * p = buffer;
  104. if (lseek (pib->file, AMP_PRESCALER_OFFSET, SEEK_SET) != AMP_PRESCALER_OFFSET)
  105. {
  106. error (1, errno, FILE_CANTSEEK, pib->name);
  107. }
  108. if (read (pib->file, buffer, sizeof (buffer)) != sizeof (buffer))
  109. {
  110. error (1, errno, FILE_CANTREAD, pib->name);
  111. }
  112. /*
  113. * |00000000|00111111|11112222|22222233|33333333|
  114. * |01234567|89012345|67890123|45678901|23456789|
  115. */
  116. while (index < AMP_CARRIERS)
  117. {
  118. lower = (*p++ & 0xFF) >> 0;
  119. upper = (*p & 0x03) << 8;
  120. printf ("%08d %08X\n", index++, upper | lower);
  121. lower = (*p++ & 0xFC) >> 2;
  122. upper = (*p & 0x0F) << 6;
  123. printf ("%08d %08X\n", index++, upper | lower);
  124. lower = (*p++ & 0xF0) >> 4;
  125. upper = (*p & 0x3F) << 4;
  126. printf ("%08d %08X\n", index++, upper | lower);
  127. lower = (*p++ & 0xC0) >> 6;
  128. upper = (*p++ & 0xFF) << 2;
  129. printf ("%08d %08X\n", index++, upper | lower);
  130. }
  131. return;
  132. }
  133. /*====================================================================*
  134. *
  135. * void int6x00Prescalers (struct _file_ * pib);
  136. *
  137. *--------------------------------------------------------------------*/
  138. static void int6x00Prescalers (struct _file_ * pib)
  139. {
  140. unsigned index = 0;
  141. if (lseek (pib->file, INT_PRESCALER_OFFSET, SEEK_SET) != INT_PRESCALER_OFFSET)
  142. {
  143. error (1, errno, FILE_CANTSEEK, pib->name);
  144. }
  145. while (index < INT_CARRIERS)
  146. {
  147. uint32_t value;
  148. if (read (pib->file, &value, sizeof (value)) != sizeof (value))
  149. {
  150. error (1, errno, FILE_CANTREAD, pib->name);
  151. }
  152. printf ("%08d %08X\n", index++, LE32TOH (value));
  153. }
  154. return;
  155. }
  156. /*====================================================================*
  157. *
  158. * void qca7x00Prescalers (struct _file_ * pib);
  159. *
  160. *--------------------------------------------------------------------*/
  161. static void qca7x00Prescalers (struct _file_ * pib)
  162. {
  163. unsigned index = 0;
  164. byte buffer [QCA_PRESCALER_LENGTH];
  165. byte * p = buffer;
  166. if (lseek (pib->file, QCA_PRESCALER_OFFSET, SEEK_SET) != QCA_PRESCALER_OFFSET)
  167. {
  168. error (1, errno, FILE_CANTSEEK, pib->name);
  169. }
  170. if (read (pib->file, buffer, sizeof (buffer)) != sizeof (buffer))
  171. {
  172. error (1, errno, FILE_CANTREAD, pib->name);
  173. }
  174. while (index < PLC_CARRIERS)
  175. {
  176. printf ("%08d %08x\n", index++, *p++);
  177. }
  178. }
  179. /*====================================================================*
  180. *
  181. * int main (int argc, char const * argv [])
  182. *
  183. *
  184. *--------------------------------------------------------------------*/
  185. int main (int argc, char const * argv [])
  186. {
  187. static char const * optv [] =
  188. {
  189. "",
  190. "pibfile [> scalers]",
  191. "Export PIB Prescalers",
  192. (char const *) (0)
  193. };
  194. struct _file_ pib;
  195. unsigned scalers;
  196. signed c;
  197. optind = 1;
  198. while ((c = getoptv (argc, argv, optv)) != -1)
  199. {
  200. switch ((char) (c))
  201. {
  202. default:
  203. break;
  204. }
  205. }
  206. argc -= optind;
  207. argv += optind;
  208. if (argc > 1)
  209. {
  210. error (1, ENOTSUP, "Only one file is permitted");
  211. }
  212. if ((argc) && (* argv))
  213. {
  214. pib.name = * argv;
  215. if ((pib.file = open (pib.name, O_BINARY|O_RDONLY)) == -1)
  216. {
  217. error (1, errno, "Can't open %s", pib.name);
  218. }
  219. if (pibfile (&pib))
  220. {
  221. error (1, errno, "Bad PIB file: %s", pib.name);
  222. }
  223. scalers = pibscalers (&pib);
  224. if (scalers == PLC_CARRIERS)
  225. {
  226. qca7x00Prescalers (&pib);
  227. }
  228. else if (scalers == AMP_CARRIERS)
  229. {
  230. ar7x00Prescalers (&pib);
  231. }
  232. else if (scalers == INT_CARRIERS)
  233. {
  234. int6x00Prescalers (&pib);
  235. }
  236. else
  237. {
  238. error (1, ENOTSUP, "Unexpected number of carriers");
  239. }
  240. close (pib.file);
  241. }
  242. return (0);
  243. }