fuzzer.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. Manages what to fuzz when.
  3. */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <stdint.h>
  7. #include <string.h>
  8. #include "frameDefinitions.h"
  9. #include "fuzzRates.h"
  10. #include "fuzzEXTRATES.h"
  11. #include "fuzzHTCAPAB.h"
  12. #include "fuzzHTINFO.h"
  13. #include "fuzzEXTCAPAB.h"
  14. #include "fuzzEDCA.h"
  15. #include "fuzzAssResponse.h"
  16. //CHANGE WHEN NEW SUBFUZZER
  17. //CHANGE WHEN NEW SUBFUZZER
  18. //Number of subfuzzers
  19. #define SUBFUZZERS (6)
  20. //CHANGE WHEN NEW SUBFUZZER
  21. //Array of pointers to subfuzzers update functions
  22. int (*p[SUBFUZZERS]) (int i) = {
  23. ratesFuzzUpdate, extratesFuzzUpdate, htcapabFuzzUpdate, htinfoFuzzUpdate, extcapabFuzzUpdate, edcaFuzzUpdate};
  24. //State of sub-fuzzer
  25. //-1 = Done
  26. //0 = In progress
  27. int subFuzzState = -1;
  28. //State of generic fuzzer
  29. //-1 = Done
  30. //0 = In progress
  31. int genFuzzState = -1;
  32. //Current sub-fuzzer
  33. //Starts with -1 to prevent skipping the first sub-fuzzer
  34. int subFuzzerIdx = -1;
  35. //int subFuzzerIdx = 99; //to test generic fuzzing part
  36. //Flag to indicate if the done with all subfuzzers notification has been sent
  37. int notifyDone = 0;
  38. int getNotifyDone()
  39. {
  40. return notifyDone;
  41. }
  42. //Number of different sent frames (-1 because we start with increaseFuzzer)
  43. int frameCounter = -1;
  44. //Controls state of fuzzer, and therefore what to fuzz next
  45. void increaseFuzzer()
  46. {
  47. frameCounter = frameCounter + 1;
  48. //while we still have sub-fuzzers to go
  49. if (subFuzzerIdx < SUBFUZZERS)
  50. {
  51. if (subFuzzState == -1)
  52. {
  53. subFuzzerIdx = subFuzzerIdx + 1;
  54. if (subFuzzerIdx < SUBFUZZERS)
  55. {
  56. subFuzzState = (*p[subFuzzerIdx]) (0);
  57. }
  58. }
  59. else
  60. {
  61. subFuzzState = (*p[subFuzzerIdx]) (1);
  62. }
  63. }
  64. //Done with all sub-fuzzers
  65. else
  66. {
  67. //Only do first time
  68. if (notifyDone == 0)
  69. {
  70. notifyDone = 1;
  71. printf("Done with all subfuzzers\n");
  72. printf("Sent %d different frames in total\n", frameCounter);
  73. printf("Moving on to generic fuzzing\n");
  74. genFuzzState = AssRespFuzzUpdate(0);
  75. }
  76. else
  77. {
  78. if (genFuzzState != -1)
  79. {
  80. genFuzzState = AssRespFuzzUpdate(1);
  81. if (genFuzzState == -1)
  82. {
  83. printf("Done with generic fuzzing\n");
  84. printf("Done with all Association response fuzzing\n");
  85. printf("Fuzzer will now exit\n");
  86. exit(0);
  87. }
  88. }
  89. else
  90. {
  91. printf("Fuzzer is done, but code should not get here\n");
  92. printf("Fuzzer will now exit\n");
  93. exit(0);
  94. }
  95. }
  96. }
  97. }