psnotch.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770
  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. /*====================================================================r
  42. *
  43. * psnotch.c - Atheros Prescaler Notching Utility
  44. *
  45. * Atheros Powerline Toolkit;
  46. *
  47. * this program is the Atheros INT6000 Dynamic Notching Utility
  48. *
  49. * this program inspects the following frequency bands for SW signals:
  50. *
  51. * 120 m 2,300 - 2,495 kHz tropic band
  52. * 90 m 3,200 - 3,400 kHz tropic band
  53. * 75 m 3,900 - 4,000 kHz shared with the amateur radio 75/80 meter band
  54. * 60 m 4,750 - 5,060 kHz tropic band
  55. * 49 m 5,900 - 6,200 kHz
  56. * 40 m/41m 7,100 - 7,350 kHz shared with the amateur radio 40 meter band
  57. * 31 m 9,400 - 9,900 kHz Currently most heavily used band
  58. * 25 m 11,600 - 12,100 kHz
  59. * 22 m 13,570 - 13,870 kHz substantially used only in Eurasia
  60. * 19 m 15,100 - 15,800 kHz
  61. * 16 m 17,480 - 17,900 kHz
  62. * 15 m 18,900 - 19,020 kHz almost unused, could become a DRM band
  63. * 13 m 21,450 - 21,850 kHz
  64. * 11 m 25,600 - 26,100 kHz may be used for local DRM broadcasting
  65. *
  66. *
  67. * Contributor(s):
  68. * Nathaniel Houghton
  69. *
  70. *--------------------------------------------------------------------*/
  71. /*====================================================================*"
  72. * system header files;
  73. *--------------------------------------------------------------------*/
  74. #include <stdio.h>
  75. #include <ctype.h>
  76. #include <ctype.h>
  77. #include <sys/types.h>
  78. #include <sys/stat.h>
  79. #include <fcntl.h>
  80. #include <string.h>
  81. /*====================================================================*
  82. * custom header files;
  83. *--------------------------------------------------------------------*/
  84. #include "../tools/getoptv.h"
  85. #include "../tools/putoptv.h"
  86. #include "../tools/error.h"
  87. #include "../tools/flags.h"
  88. #include "../tools/chars.h"
  89. #include "../tools/number.h"
  90. /*====================================================================*
  91. * custom source files;
  92. *--------------------------------------------------------------------*/
  93. #ifndef MAKEFILE
  94. #include "../tools/getoptv.c"
  95. #include "../tools/putoptv.c"
  96. #include "../tools/version.c"
  97. #include "../tools/error.c"
  98. #include "../tools/uintspec.c"
  99. #include "../tools/todigit.c"
  100. #endif
  101. /*====================================================================*
  102. * program constants;
  103. *--------------------------------------------------------------------*/
  104. #define _PRINTF_DEBUG
  105. #define PSNOTCH_VERBOSE (1 << 0)
  106. #define PSNOTCH_SILENCE (1 << 1)
  107. #define PSNOTCH_COMMA (1 << 2)
  108. #define CARRIERS 1155
  109. #define TONES 917
  110. #define SLOTS 6
  111. #define INDEX_TO_FREQ(index) ((float)(index + 74)/40.96)
  112. #define FREQ_TO_INDEX(freq) ((unsigned)(40.96 * freq)-74)
  113. /*====================================================================*
  114. * program variables;
  115. *--------------------------------------------------------------------*/
  116. typedef struct carrier
  117. {
  118. uint16_t amplitude;
  119. uint8_t slots [SLOTS];
  120. }
  121. carrier;
  122. typedef struct map
  123. {
  124. unsigned slots;
  125. struct carrier carriers [CARRIERS];
  126. }
  127. map;
  128. uint8_t hambands [CARRIERS] =
  129. {
  130. 0,
  131. 0,
  132. 0,
  133. 0,
  134. 0,
  135. 0,
  136. 0,
  137. 0,
  138. 0,
  139. 0,
  140. 0,
  141. 0,
  142. 1,
  143. 1,
  144. 1,
  145. 1,
  146. 1,
  147. 1,
  148. 1,
  149. 1,
  150. 1,
  151. 1,
  152. 1,
  153. 1,
  154. 1,
  155. 1,
  156. 1,
  157. 1,
  158. 1,
  159. 1,
  160. 1,
  161. 1,
  162. 1,
  163. 1,
  164. 1,
  165. 1,
  166. 1,
  167. 1,
  168. 1,
  169. 1,
  170. 1,
  171. 1,
  172. 1,
  173. 1,
  174. 1,
  175. 1,
  176. 1,
  177. 1,
  178. 1,
  179. 1,
  180. 1,
  181. 1,
  182. 1,
  183. 1,
  184. 1,
  185. 1,
  186. 1,
  187. 1,
  188. 1,
  189. 1,
  190. 1,
  191. 1,
  192. 1,
  193. 1,
  194. 1,
  195. 1,
  196. 2,
  197. 2,
  198. 2,
  199. 2,
  200. 2,
  201. 2,
  202. 2,
  203. 2,
  204. 2,
  205. 2,
  206. 2,
  207. 2,
  208. 2,
  209. 2,
  210. 2,
  211. 2,
  212. 2,
  213. 2,
  214. 2,
  215. 2,
  216. 2,
  217. 2,
  218. 2,
  219. 2,
  220. 2,
  221. 2,
  222. 2,
  223. 2,
  224. 1,
  225. 1,
  226. 1,
  227. 1,
  228. 1,
  229. 1,
  230. 1,
  231. 1,
  232. 1,
  233. 1,
  234. 1,
  235. 1,
  236. 1,
  237. 1,
  238. 1,
  239. 1,
  240. 1,
  241. 1,
  242. 1,
  243. 1,
  244. 1,
  245. 1,
  246. 1,
  247. 1,
  248. 1,
  249. 1,
  250. 1,
  251. 1,
  252. 1,
  253. 1,
  254. 1,
  255. 1,
  256. 1,
  257. 1,
  258. 1,
  259. 1,
  260. 1,
  261. 1,
  262. 1,
  263. 1,
  264. 1,
  265. 1,
  266. 1,
  267. 1,
  268. 1,
  269. 1,
  270. 1,
  271. 2,
  272. 2,
  273. 2,
  274. 2,
  275. 2,
  276. 2,
  277. 2,
  278. 2,
  279. 2,
  280. 2,
  281. 2,
  282. 1,
  283. 1,
  284. 1,
  285. 1,
  286. 1,
  287. 1,
  288. 1,
  289. 1,
  290. 1,
  291. 1,
  292. 1,
  293. 1,
  294. 1,
  295. 1,
  296. 1,
  297. 1,
  298. 1,
  299. 1,
  300. 1,
  301. 1,
  302. 1,
  303. 1,
  304. 1,
  305. 1,
  306. 1,
  307. 1,
  308. 1,
  309. 1,
  310. 1,
  311. 1,
  312. 1,
  313. 1,
  314. 1,
  315. 1,
  316. 1,
  317. 1,
  318. 1,
  319. 1,
  320. 1,
  321. 1,
  322. 1,
  323. 1,
  324. 1,
  325. 1,
  326. 1,
  327. 1,
  328. 1,
  329. 1,
  330. 1,
  331. 1,
  332. 1,
  333. 1,
  334. 1,
  335. 1,
  336. 1,
  337. 1,
  338. 1,
  339. 2,
  340. 2,
  341. 2,
  342. 2,
  343. 2,
  344. 2,
  345. 2,
  346. 2,
  347. 2,
  348. 2,
  349. 2,
  350. 2,
  351. 2,
  352. 2,
  353. 2,
  354. 2,
  355. 2,
  356. 2,
  357. 2,
  358. 2,
  359. 1,
  360. 1,
  361. 1,
  362. 1,
  363. 1,
  364. 1,
  365. 1,
  366. 1,
  367. 1,
  368. 1,
  369. 1,
  370. 1,
  371. 1,
  372. 1,
  373. 1,
  374. 1,
  375. 1,
  376. 1,
  377. 1,
  378. 1,
  379. 1,
  380. 1,
  381. 1,
  382. 1,
  383. 1,
  384. 1,
  385. 1,
  386. 1,
  387. 1,
  388. 1,
  389. 1,
  390. 1,
  391. 1,
  392. 1,
  393. 1,
  394. 1,
  395. 1,
  396. 1,
  397. 1,
  398. 1,
  399. 1,
  400. 1,
  401. 1,
  402. 1,
  403. 1,
  404. 1,
  405. 1,
  406. 1,
  407. 1,
  408. 1,
  409. 1,
  410. 1,
  411. 1,
  412. 1,
  413. 1,
  414. 1,
  415. 1,
  416. 1,
  417. 1,
  418. 1,
  419. 1,
  420. 1,
  421. 1,
  422. 1,
  423. 1,
  424. 1,
  425. 1,
  426. 1,
  427. 1,
  428. 1,
  429. 1,
  430. 1,
  431. 1,
  432. 1,
  433. 1,
  434. 1,
  435. 1,
  436. 1,
  437. 1,
  438. 1,
  439. 1,
  440. 1,
  441. 1,
  442. 1,
  443. 1,
  444. 1,
  445. 1,
  446. 1,
  447. 1,
  448. 1,
  449. 1,
  450. 1,
  451. 1,
  452. 1,
  453. 1,
  454. 1,
  455. 1,
  456. 1,
  457. 1,
  458. 1,
  459. 1,
  460. 1,
  461. 1,
  462. 1,
  463. 1,
  464. 1,
  465. 1,
  466. 2,
  467. 2,
  468. 2,
  469. 2,
  470. 2,
  471. 2,
  472. 2,
  473. 2,
  474. 2,
  475. 2,
  476. 1,
  477. 1,
  478. 1,
  479. 1,
  480. 1,
  481. 1,
  482. 1,
  483. 1,
  484. 1,
  485. 1,
  486. 1,
  487. 1,
  488. 1,
  489. 1,
  490. 1,
  491. 1,
  492. 1,
  493. 1,
  494. 1,
  495. 1,
  496. 1,
  497. 1,
  498. 1,
  499. 1,
  500. 1,
  501. 1,
  502. 1,
  503. 1,
  504. 1,
  505. 1,
  506. 1,
  507. 1,
  508. 1,
  509. 1,
  510. 1,
  511. 1,
  512. 1,
  513. 1,
  514. 1,
  515. 1,
  516. 1,
  517. 1,
  518. 1,
  519. 1,
  520. 1,
  521. 1,
  522. 1,
  523. 1,
  524. 1,
  525. 1,
  526. 1,
  527. 1,
  528. 1,
  529. 1,
  530. 1,
  531. 1,
  532. 1,
  533. 1,
  534. 1,
  535. 1,
  536. 1,
  537. 1,
  538. 1,
  539. 1,
  540. 1,
  541. 1,
  542. 1,
  543. 1,
  544. 1,
  545. 1,
  546. 1,
  547. 1,
  548. 1,
  549. 1,
  550. 1,
  551. 1,
  552. 1,
  553. 1,
  554. 1,
  555. 1,
  556. 1,
  557. 1,
  558. 1,
  559. 1,
  560. 1,
  561. 1,
  562. 1,
  563. 1,
  564. 1,
  565. 1,
  566. 1,
  567. 1,
  568. 1,
  569. 1,
  570. 1,
  571. 1,
  572. 1,
  573. 1,
  574. 1,
  575. 1,
  576. 1,
  577. 1,
  578. 1,
  579. 1,
  580. 1,
  581. 1,
  582. 1,
  583. 1,
  584. 1,
  585. 1,
  586. 1,
  587. 1,
  588. 1,
  589. 1,
  590. 1,
  591. 1,
  592. 1,
  593. 1,
  594. 1,
  595. 1,
  596. 1,
  597. 1,
  598. 1,
  599. 1,
  600. 1,
  601. 1,
  602. 1,
  603. 1,
  604. 1,
  605. 1,
  606. 1,
  607. 1,
  608. 1,
  609. 1,
  610. 1,
  611. 1,
  612. 1,
  613. 1,
  614. 1,
  615. 1,
  616. 1,
  617. 1,
  618. 1,
  619. 1,
  620. 1,
  621. 1,
  622. 1,
  623. 1,
  624. 1,
  625. 1,
  626. 2,
  627. 2,
  628. 2,
  629. 2,
  630. 2,
  631. 2,
  632. 2,
  633. 2,
  634. 2,
  635. 2,
  636. 2,
  637. 2,
  638. 2,
  639. 2,
  640. 2,
  641. 2,
  642. 2,
  643. 2,
  644. 2,
  645. 2,
  646. 2,
  647. 2,
  648. 1,
  649. 1,
  650. 1,
  651. 1,
  652. 1,
  653. 1,
  654. 1,
  655. 1,
  656. 1,
  657. 1,
  658. 1,
  659. 1,
  660. 1,
  661. 1,
  662. 1,
  663. 1,
  664. 1,
  665. 1,
  666. 1,
  667. 1,
  668. 1,
  669. 1,
  670. 1,
  671. 1,
  672. 1,
  673. 1,
  674. 1,
  675. 1,
  676. 1,
  677. 1,
  678. 1,
  679. 1,
  680. 1,
  681. 1,
  682. 1,
  683. 1,
  684. 1,
  685. 1,
  686. 1,
  687. 1,
  688. 1,
  689. 1,
  690. 1,
  691. 1,
  692. 1,
  693. 1,
  694. 1,
  695. 1,
  696. 1,
  697. 1,
  698. 1,
  699. 1,
  700. 1,
  701. 1,
  702. 1,
  703. 1,
  704. 1,
  705. 1,
  706. 1,
  707. 1,
  708. 1,
  709. 1,
  710. 1,
  711. 1,
  712. 1,
  713. 1,
  714. 1,
  715. 1,
  716. 1,
  717. 1,
  718. 1,
  719. 1,
  720. 1,
  721. 1,
  722. 1,
  723. 1,
  724. 1,
  725. 1,
  726. 1,
  727. 1,
  728. 1,
  729. 1,
  730. 1,
  731. 1,
  732. 1,
  733. 1,
  734. 1,
  735. 1,
  736. 1,
  737. 1,
  738. 1,
  739. 1,
  740. 1,
  741. 1,
  742. 1,
  743. 1,
  744. 1,
  745. 1,
  746. 1,
  747. 1,
  748. 1,
  749. 1,
  750. 1,
  751. 1,
  752. 1,
  753. 1,
  754. 1,
  755. 1,
  756. 1,
  757. 1,
  758. 1,
  759. 1,
  760. 1,
  761. 1,
  762. 1,
  763. 1,
  764. 1,
  765. 1,
  766. 1,
  767. 1,
  768. 1,
  769. 1,
  770. 1,
  771. 1,
  772. 1,
  773. 1,
  774. 1,
  775. 1,
  776. 1,
  777. 1,
  778. 1,
  779. 1,
  780. 1,
  781. 1,
  782. 1,
  783. 1,
  784. 1,
  785. 1,
  786. 1,
  787. 1,
  788. 1,
  789. 1,
  790. 1,
  791. 1,
  792. 1,
  793. 2,
  794. 2,
  795. 2,
  796. 2,
  797. 2,
  798. 2,
  799. 2,
  800. 2,
  801. 2,
  802. 2,
  803. 2,
  804. 2,
  805. 1,
  806. 1,
  807. 1,
  808. 1,
  809. 1,
  810. 1,
  811. 1,
  812. 1,
  813. 1,
  814. 1,
  815. 1,
  816. 1,
  817. 1,
  818. 1,
  819. 1,
  820. 1,
  821. 1,
  822. 1,
  823. 1,
  824. 1,
  825. 1,
  826. 1,
  827. 1,
  828. 1,
  829. 1,
  830. 1,
  831. 1,
  832. 1,
  833. 1,
  834. 1,
  835. 1,
  836. 1,
  837. 1,
  838. 1,
  839. 1,
  840. 1,
  841. 1,
  842. 1,
  843. 1,
  844. 1,
  845. 1,
  846. 1,
  847. 1,
  848. 1,
  849. 1,
  850. 1,
  851. 1,
  852. 1,
  853. 1,
  854. 1,
  855. 1,
  856. 1,
  857. 1,
  858. 1,
  859. 1,
  860. 1,
  861. 1,
  862. 1,
  863. 1,
  864. 1,
  865. 1,
  866. 1,
  867. 1,
  868. 1,
  869. 1,
  870. 1,
  871. 1,
  872. 1,
  873. 1,
  874. 1,
  875. 1,
  876. 1,
  877. 1,
  878. 1,
  879. 1,
  880. 1,
  881. 1,
  882. 1,
  883. 1,
  884. 1,
  885. 1,
  886. 1,
  887. 1,
  888. 1,
  889. 1,
  890. 1,
  891. 1,
  892. 1,
  893. 1,
  894. 1,
  895. 1,
  896. 1,
  897. 1,
  898. 1,
  899. 1,
  900. 1,
  901. 1,
  902. 1,
  903. 1,
  904. 1,
  905. 1,
  906. 1,
  907. 1,
  908. 1,
  909. 1,
  910. 1,
  911. 1,
  912. 1,
  913. 2,
  914. 2,
  915. 2,
  916. 2,
  917. 2,
  918. 2,
  919. 2,
  920. 2,
  921. 2,
  922. 2,
  923. 2,
  924. 2,
  925. 2,
  926. 2,
  927. 2,
  928. 2,
  929. 2,
  930. 2,
  931. 2,
  932. 2,
  933. 2,
  934. 2,
  935. 2,
  936. 2,
  937. 2,
  938. 2,
  939. 1,
  940. 1,
  941. 1,
  942. 1,
  943. 1,
  944. 1,
  945. 1,
  946. 1,
  947. 1,
  948. 1,
  949. 1,
  950. 1,
  951. 1,
  952. 1,
  953. 1,
  954. 1,
  955. 1,
  956. 1,
  957. 1,
  958. 1,
  959. 1,
  960. 1,
  961. 1,
  962. 1,
  963. 1,
  964. 1,
  965. 1,
  966. 1,
  967. 1,
  968. 1,
  969. 1,
  970. 1,
  971. 1,
  972. 1,
  973. 1,
  974. 1,
  975. 1,
  976. 1,
  977. 1,
  978. 1,
  979. 1,
  980. 1,
  981. 1,
  982. 1,
  983. 1,
  984. 1,
  985. 1,
  986. 1,
  987. 1,
  988. 1,
  989. 1,
  990. 1,
  991. 1,
  992. 1,
  993. 1,
  994. 1,
  995. 1,
  996. 1,
  997. 1,
  998. 1,
  999. 1,
  1000. 1,
  1001. 1,
  1002. 1,
  1003. 1,
  1004. 1,
  1005. 1,
  1006. 1,
  1007. 1,
  1008. 1,
  1009. 1,
  1010. 1,
  1011. 1,
  1012. 1,
  1013. 1,
  1014. 1,
  1015. 1,
  1016. 1,
  1017. 1,
  1018. 1,
  1019. 1,
  1020. 1,
  1021. 1,
  1022. 1,
  1023. 1,
  1024. 1,
  1025. 1,
  1026. 1,
  1027. 1,
  1028. 1,
  1029. 1,
  1030. 1,
  1031. 1,
  1032. 1,
  1033. 1,
  1034. 1,
  1035. 1,
  1036. 1,
  1037. 1,
  1038. 1,
  1039. 1,
  1040. 1,
  1041. 1,
  1042. 1,
  1043. 1,
  1044. 1,
  1045. 1,
  1046. 1,
  1047. 1,
  1048. 1,
  1049. 1,
  1050. 1,
  1051. 1,
  1052. 1,
  1053. 1,
  1054. 1,
  1055. 1,
  1056. 1,
  1057. 1,
  1058. 1,
  1059. 1,
  1060. 1,
  1061. 1,
  1062. 1,
  1063. 1,
  1064. 1,
  1065. 1,
  1066. 1,
  1067. 1,
  1068. 1,
  1069. 1,
  1070. 1,
  1071. 1,
  1072. 2,
  1073. 2,
  1074. 2,
  1075. 2,
  1076. 2,
  1077. 2,
  1078. 2,
  1079. 2,
  1080. 2,
  1081. 2,
  1082. 2,
  1083. 2,
  1084. 1,
  1085. 1,
  1086. 1,
  1087. 1,
  1088. 1,
  1089. 1,
  1090. 1,
  1091. 1,
  1092. 1,
  1093. 1,
  1094. 1,
  1095. 1,
  1096. 1,
  1097. 1,
  1098. 1,
  1099. 1,
  1100. 1,
  1101. 1,
  1102. 1,
  1103. 1,
  1104. 1,
  1105. 1,
  1106. 1,
  1107. 1,
  1108. 1,
  1109. 1,
  1110. 1,
  1111. 1,
  1112. 1,
  1113. 1,
  1114. 1,
  1115. 1,
  1116. 1,
  1117. 1,
  1118. 1,
  1119. 1,
  1120. 1,
  1121. 1,
  1122. 1,
  1123. 1,
  1124. 1,
  1125. 1,
  1126. 1,
  1127. 1,
  1128. 1,
  1129. 1,
  1130. 1,
  1131. 1,
  1132. 1,
  1133. 1,
  1134. 1,
  1135. 1,
  1136. 1,
  1137. 1,
  1138. 1,
  1139. 1,
  1140. 1,
  1141. 1,
  1142. 1,
  1143. 1,
  1144. 1,
  1145. 1,
  1146. 1,
  1147. 1,
  1148. 1,
  1149. 1,
  1150. 1,
  1151. 1,
  1152. 1,
  1153. 1,
  1154. 1,
  1155. 1,
  1156. 1,
  1157. 1,
  1158. 1,
  1159. 1,
  1160. 1,
  1161. 1,
  1162. 1,
  1163. 1,
  1164. 1,
  1165. 1,
  1166. 1,
  1167. 1,
  1168. 1,
  1169. 1,
  1170. 1,
  1171. 1,
  1172. 1,
  1173. 1,
  1174. 1,
  1175. 1,
  1176. 1,
  1177. 1,
  1178. 1,
  1179. 1,
  1180. 1,
  1181. 1,
  1182. 1,
  1183. 1,
  1184. 1,
  1185. 1,
  1186. 1,
  1187. 1,
  1188. 1,
  1189. 1,
  1190. 1,
  1191. 1,
  1192. 1,
  1193. 1,
  1194. 1,
  1195. 1,
  1196. 1,
  1197. 1,
  1198. 1,
  1199. 1,
  1200. 0,
  1201. 0,
  1202. 0,
  1203. 0,
  1204. 0,
  1205. 0,
  1206. 0,
  1207. 0,
  1208. 0,
  1209. 0,
  1210. 0,
  1211. 0,
  1212. 0,
  1213. 0,
  1214. 0,
  1215. 0,
  1216. 0,
  1217. 0,
  1218. 0,
  1219. 0,
  1220. 0,
  1221. 0,
  1222. 0,
  1223. 0,
  1224. 0,
  1225. 0,
  1226. 0,
  1227. 0,
  1228. 0,
  1229. 0,
  1230. 0,
  1231. 0,
  1232. 0,
  1233. 0,
  1234. 0,
  1235. 0,
  1236. 0,
  1237. 0,
  1238. 0,
  1239. 0,
  1240. 0,
  1241. 0,
  1242. 0,
  1243. 0,
  1244. 0,
  1245. 0,
  1246. 0,
  1247. 0,
  1248. 0,
  1249. 0,
  1250. 0,
  1251. 0,
  1252. 0,
  1253. 0,
  1254. 0,
  1255. 0,
  1256. 0,
  1257. 0,
  1258. 0,
  1259. 0,
  1260. 0,
  1261. 0,
  1262. 0,
  1263. 0,
  1264. 0,
  1265. 0,
  1266. 0,
  1267. 0,
  1268. 0,
  1269. 0,
  1270. 0,
  1271. 0,
  1272. 0,
  1273. 0,
  1274. 0,
  1275. 0,
  1276. 0,
  1277. 0,
  1278. 0,
  1279. 0,
  1280. 0,
  1281. 0,
  1282. 0,
  1283. 0,
  1284. 0
  1285. };
  1286. /*====================================================================*
  1287. *
  1288. * int read_scalers (struct map * map);
  1289. *
  1290. * read a prescaler file from stdin; permit comments and blank
  1291. * input lines; the set of prescalers are technically known as
  1292. * an amplitude map;
  1293. *
  1294. * an amplitude map consists an offset (frequency) and a scaler
  1295. * (amplitude); we read, check and discard the offset but store
  1296. * the scaler;
  1297. *
  1298. *--------------------------------------------------------------------*/
  1299. void read_scalers (struct map * map)
  1300. {
  1301. unsigned carriers = 0;
  1302. unsigned tones = 0;
  1303. uint32_t carrier;
  1304. uint32_t amplitude;
  1305. signed c;
  1306. while ((c = getc (stdin)) != EOF)
  1307. {
  1308. if (isspace (c))
  1309. {
  1310. continue;
  1311. }
  1312. if ((c == '#') || (c == ';'))
  1313. {
  1314. do
  1315. {
  1316. c = getc (stdin);
  1317. }
  1318. while (nobreak (c));
  1319. continue;
  1320. }
  1321. carrier = 0;
  1322. while (isdigit (c))
  1323. {
  1324. carrier *= 10;
  1325. carrier += c - '0';
  1326. c = getc (stdin);
  1327. }
  1328. if (carrier != carriers)
  1329. {
  1330. error (1, 0, "Prescaler %d/%d out of order", carrier, carriers);
  1331. }
  1332. if (carrier >= CARRIERS)
  1333. {
  1334. break;
  1335. }
  1336. while (isblank (c))
  1337. {
  1338. c = getc (stdin);
  1339. }
  1340. amplitude = 0;
  1341. while (isxdigit (c))
  1342. {
  1343. amplitude *= 16;
  1344. amplitude += todigit (c);
  1345. c = getc (stdin);
  1346. }
  1347. map->carriers [carrier].amplitude = amplitude;
  1348. if (amplitude)
  1349. {
  1350. tones++;
  1351. }
  1352. while ((c != EOF) && (c != '\n'))
  1353. {
  1354. c = getc (stdin);
  1355. }
  1356. carriers++;
  1357. }
  1358. if (carriers != CARRIERS)
  1359. {
  1360. error (1, 0, "Have %d amplitude map carriers but need %d", carriers, CARRIERS);
  1361. }
  1362. if (tones != TONES)
  1363. {
  1364. error (1, 0, "Expected %d amplitude map scalers but read %d", TONES, tones);
  1365. }
  1366. return;
  1367. }
  1368. /*====================================================================*
  1369. *
  1370. * void write_scalers (struct map * map);
  1371. *
  1372. * print amplitude map on stdout in a format suitabl for input to
  1373. * program psin or the Windows Device Manager;
  1374. *
  1375. *
  1376. *--------------------------------------------------------------------*/
  1377. void write_scalers (struct map * map)
  1378. {
  1379. unsigned carrier = 0;
  1380. for (carrier = 0; carrier < CARRIERS; carrier++)
  1381. {
  1382. printf ("%.8u %.8hX\n", carrier, map->carriers [carrier].amplitude);
  1383. }
  1384. return;
  1385. }
  1386. /*====================================================================*
  1387. *
  1388. * void read_tonemaps (struct map * map, FILE *fp);
  1389. *
  1390. * read tone map from a file; a tonemap file can be created using
  1391. * program int6ktone;
  1392. *
  1393. * input consists of 1159 lines; the first line is a comment; the
  1394. * next two lines contain GIL and AGC information; the remaining
  1395. * 1155 lines consist of an offset follwed by 5 or 6 slot values;
  1396. *
  1397. * although 1155 values are read, the first 917 contain tonemap
  1398. * data and rest contain 0 values; the 917 values correspond to
  1399. * the 917 amplitude scalers;
  1400. *
  1401. * the tone map may be read either before or after the amplitude
  1402. * map is read;
  1403. *
  1404. *
  1405. *--------------------------------------------------------------------*/
  1406. void read_tonemaps (struct map * map, FILE *fp)
  1407. {
  1408. uint8_t slots [SLOTS];
  1409. unsigned tones = 0;
  1410. unsigned tone = 0;
  1411. unsigned slot = 0;
  1412. signed c;
  1413. map->slots = SLOTS;
  1414. memset (slots, 0, sizeof (slots));
  1415. while ((c = getc (fp)) != EOF)
  1416. {
  1417. if (c == '#')
  1418. {
  1419. while (((c = getc (fp)) != EOF) && (c != '\n'));
  1420. }
  1421. if (isspace (c))
  1422. {
  1423. continue;
  1424. }
  1425. tone = 0;
  1426. while (isdigit (c))
  1427. {
  1428. tone *= 10;
  1429. tone += c - '0';
  1430. c = getc (fp);
  1431. }
  1432. if (tone != tones)
  1433. {
  1434. error (1, ECANCELED, "Tonemap %d/%d is out of order", tone, tones);
  1435. }
  1436. while (isblank (c))
  1437. {
  1438. c = getc (fp);
  1439. }
  1440. for (slot = 0; slot < SLOTS; slot++)
  1441. {
  1442. unsigned value = 0;
  1443. while (isdigit (c))
  1444. {
  1445. value *= 10;
  1446. value += c - '0';
  1447. c = getc (fp);
  1448. }
  1449. map->carriers [tone].slots [slot] = value;
  1450. while (isblank (c))
  1451. {
  1452. c = getc (fp);
  1453. }
  1454. }
  1455. while ((c != EOF) && (c != '\n'))
  1456. {
  1457. c = getc (fp);
  1458. }
  1459. tones++;
  1460. }
  1461. if (tones != TONES)
  1462. {
  1463. error (0, 0, "Have %d tone map carriers but need %d", tones, TONES);
  1464. }
  1465. return;
  1466. }
  1467. /*====================================================================*
  1468. *
  1469. * void align_tones (struct map * map);
  1470. *
  1471. * the tonemap consists of 917 consecutive carriers the amplitude
  1472. * map consists of 1155 carriers having 917 non-zero values; this
  1473. * function distributes the tonemap entries so that they align to
  1474. * corresponding amplitude map entries;
  1475. *
  1476. * alignment cannot be performed until both the amplitude map and
  1477. * tone map have been read;
  1478. *
  1479. *
  1480. *--------------------------------------------------------------------*/
  1481. void align_tones (struct map * map)
  1482. {
  1483. unsigned carriers = CARRIERS;
  1484. unsigned tones = TONES;
  1485. while (carriers--)
  1486. {
  1487. if (map->carriers [carriers].amplitude)
  1488. {
  1489. if (tones)
  1490. {
  1491. tones--;
  1492. memcpy (&map->carriers [carriers].slots, &map->carriers [tones].slots, SLOTS);
  1493. memset (&map->carriers [tones].slots, 0, SLOTS);
  1494. }
  1495. }
  1496. }
  1497. return;
  1498. }
  1499. /*====================================================================*
  1500. *
  1501. * unsigned notch_tones (struct map * scalers, unsigned lower, unsigned upper);
  1502. *
  1503. * scan a range of tones for signals; signals are indicated by low
  1504. * mean-square values computed across all slots for a given tone;
  1505. *
  1506. * there may not be much change from one carrier to the next; we
  1507. * accentuate changes by squaring then summing slot values; this
  1508. * produces a reasonably clean parabolic dip in the map where the
  1509. * signal occurs;
  1510. *
  1511. * function watch_tones can be used to observe tone map values and
  1512. * signal dips over a given range of map values; generally, it is
  1513. * best to display a wider range of tones than those being notched;
  1514. *
  1515. *
  1516. *--------------------------------------------------------------------*/
  1517. unsigned notch_tones (struct map * map, unsigned lower, unsigned upper, unsigned limit)
  1518. {
  1519. unsigned slot;
  1520. unsigned notch = 0;
  1521. while (lower < upper)
  1522. {
  1523. unsigned total = 0;
  1524. for (slot = 0; slot < map->slots; slot++)
  1525. {
  1526. unsigned value = 0;
  1527. value = map->carriers [lower].slots [slot];
  1528. value *= value;
  1529. total += value;
  1530. }
  1531. if (slot)
  1532. {
  1533. total /= slot;
  1534. }
  1535. if (total < limit)
  1536. {
  1537. map->carriers [lower].amplitude = 0;
  1538. notch = 2;
  1539. }
  1540. lower++;
  1541. }
  1542. return (notch);
  1543. }
  1544. /*====================================================================*
  1545. *
  1546. * void watch_tones (struct map * map, unsigned lower, unsigned upper);
  1547. *
  1548. * print amplitude and tone values over a given range along with a
  1549. * plot of the values used to detect signal dips; for best effect,
  1550. * the range used here should exceed the notching range to provide
  1551. * context information;
  1552. *
  1553. *
  1554. *--------------------------------------------------------------------*/
  1555. void watch_tones (struct map * map, unsigned lower, unsigned upper)
  1556. {
  1557. unsigned slot;
  1558. while (lower < upper)
  1559. {
  1560. unsigned total = 0;
  1561. fprintf (stderr, "%04u %04X", lower, map->carriers [lower].amplitude);
  1562. for (slot = 0; slot < map->slots; slot++)
  1563. {
  1564. unsigned value = 0;
  1565. value = map->carriers [lower].slots [slot];
  1566. fprintf (stderr, " %02X", value);
  1567. value *= value;
  1568. total += value;
  1569. }
  1570. if (slot)
  1571. {
  1572. total /= slot;
  1573. }
  1574. fprintf (stderr, " %6.3f ", INDEX_TO_FREQ (lower));
  1575. while (total--)
  1576. {
  1577. fprintf (stderr, "#");
  1578. }
  1579. fprintf (stderr, "\n");
  1580. lower++;
  1581. }
  1582. return;
  1583. }
  1584. /*====================================================================*
  1585. *
  1586. * void watch_tone2 (struct map * map, unsigned lower, unsigned upper);
  1587. *
  1588. * print amplitude and tone values over a given range along with a
  1589. * plot of the values used to detect signal dips; for best effect,
  1590. * the range used here should exceed the notching range to provide
  1591. * context information;
  1592. *
  1593. *
  1594. *--------------------------------------------------------------------*/
  1595. void watch_tone2 (struct map * map, unsigned lower, unsigned upper)
  1596. {
  1597. unsigned slot;
  1598. while (lower < upper)
  1599. {
  1600. unsigned total = 0;
  1601. fprintf (stderr, "%u,%d", lower, map->carriers [lower].amplitude);
  1602. for (slot = 0; slot < map->slots; slot++)
  1603. {
  1604. unsigned value = 0;
  1605. value = map->carriers [lower].slots [slot];
  1606. fprintf (stderr, ",%u", value);
  1607. value *= value;
  1608. total += value;
  1609. }
  1610. if (slot)
  1611. {
  1612. total /= slot;
  1613. }
  1614. fprintf (stderr, ",%u", total);
  1615. fprintf (stderr, ",%6.3f", INDEX_TO_FREQ (lower));
  1616. fprintf (stderr, "\n");
  1617. lower++;
  1618. }
  1619. return;
  1620. }
  1621. /*====================================================================*
  1622. *
  1623. * int main (int argc, char const * argv[]);
  1624. *
  1625. * read an amplitude map from stdin and print a notched amplitude
  1626. * map on stdout; use a tone map file to determine if a signal is
  1627. * present where notching chould occur; notching ranges are input
  1628. * as map offsets, not carrier frequencies;
  1629. *
  1630. *
  1631. *--------------------------------------------------------------------*/
  1632. int main (int argc, char const * argv [])
  1633. {
  1634. char const * optv [] =
  1635. {
  1636. "cf:l:L:t:u:U:qv",
  1637. PUTOPTV_S_FILTER,
  1638. "Atheros Prescaler Notching Utility",
  1639. "c\tcomma delimited output",
  1640. "f f\tread tonemap file (f)",
  1641. "t n\tthreshold is (n) units",
  1642. "l n\tlower notch range is (n)",
  1643. "L n\tlower graph range is (n)",
  1644. "u n\tupper notch range is (n)",
  1645. "U n\tupper graph range is (n)",
  1646. "v\tverbose output",
  1647. (char const *)(0)
  1648. };
  1649. struct map map;
  1650. FILE * fp = (FILE *)(0);
  1651. unsigned lower = CARRIERS-1;
  1652. unsigned upper = 0;
  1653. unsigned LOWER = 0;
  1654. unsigned UPPER = CARRIERS-1;
  1655. signed limit = 4;
  1656. signed status = 0;
  1657. flag_t flags = (flag_t)(0);
  1658. signed c;
  1659. memset (&map, 0, sizeof (map));
  1660. while ((c = getoptv (argc, argv, optv)) != -1)
  1661. {
  1662. switch (c)
  1663. {
  1664. case 'c':
  1665. _setbits (flags, PSNOTCH_COMMA);
  1666. break;
  1667. case 'f':
  1668. if ((fp = fopen (optarg, "rb")) == (FILE *)(0))
  1669. {
  1670. error (1, errno, "Can't open %s", optarg);
  1671. }
  1672. read_tonemaps (&map, fp);
  1673. fclose (fp);
  1674. break;
  1675. case 'l':
  1676. lower = (unsigned)(uintspec (optarg, 0, CARRIERS-1));
  1677. break;
  1678. case 'u':
  1679. upper = (unsigned)(uintspec (optarg, 0, CARRIERS-1));
  1680. break;
  1681. case 'L':
  1682. LOWER = (unsigned)(uintspec (optarg, 0, CARRIERS-1));
  1683. break;
  1684. case 'U':
  1685. UPPER = (unsigned)(uintspec (optarg, 0, CARRIERS-1));
  1686. break;
  1687. case 't':
  1688. limit = (signed)(uintspec (optarg, 0, 49));
  1689. break;
  1690. case 'q':
  1691. _setbits (flags, PSNOTCH_SILENCE);
  1692. break;
  1693. case 'v':
  1694. _setbits (flags, PSNOTCH_VERBOSE);
  1695. break;
  1696. default:
  1697. break;
  1698. }
  1699. }
  1700. argv += optind;
  1701. argc -= optind;
  1702. read_scalers (&map);
  1703. align_tones (&map);
  1704. if (_anyset (flags, PSNOTCH_COMMA))
  1705. {
  1706. watch_tone2 (&map, LOWER, UPPER);
  1707. }
  1708. else if (_anyset (flags, PSNOTCH_VERBOSE))
  1709. {
  1710. watch_tones (&map, LOWER, UPPER);
  1711. }
  1712. if (fp)
  1713. {
  1714. status = notch_tones (&map, lower, upper, limit);
  1715. }
  1716. write_scalers (&map);
  1717. return (status);
  1718. }