slac_connect.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * void slac_connect (struct session * session);
  11. *
  12. * slac.h
  13. *
  14. * compute the arithmetic mean of session attenuation values and
  15. * compare to the session limit; average attenuation greater than
  16. * the session limit is considered a bad connection;
  17. *
  18. *--------------------------------------------------------------------*/
  19. #ifndef SLAC_AVERAGE_SOURCE
  20. #define SLAC_AVERAGE_SOURCE
  21. #include "../tools/error.h"
  22. #include "../tools/flags.h"
  23. #include "../tools/memory.h"
  24. #include "../slac/slac.h"
  25. signed slac_connect (struct session * session)
  26. {
  27. unsigned group = 0;
  28. unsigned total = 0;
  29. if (session->NumGroups > SIZEOF (session->AAG))
  30. {
  31. return (debug (session->exit, __func__, "Too much data to analyse!"));
  32. }
  33. if (session->NumGroups > 0)
  34. {
  35. char string [512];
  36. while (group < session->NumGroups)
  37. {
  38. total += session->AAG [group];
  39. group++;
  40. }
  41. total /= group;
  42. if (total > session->limit)
  43. {
  44. char string [512];
  45. debug (0, __func__, "Average attenuation (%u) more than limit (%u) frow %d groups", total, session->limit, group);
  46. debug (0, __func__, "%s", HEXSTRING (string, session->AAG));
  47. return (- 1);
  48. }
  49. if (total > 0)
  50. {
  51. debug (0, __func__, "Average attenuation (%u) less than limit (%u) from %d groups", total, session->limit, group);
  52. debug (0, __func__, "%s", HEXSTRING (string, session->AAG));
  53. return (0);
  54. }
  55. }
  56. return (debug (session->exit, __func__, "Nothing to analyse"));
  57. }
  58. #endif