Failure.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. * void Failure (struct plc * plc, char const *format, ...)
  44. *
  45. * error.h
  46. *
  47. * Inform the user that an operation failed; print the channel name,
  48. * source device, error message and user defined message on stderr
  49. * unless the PLC_SILENCE flags is set;
  50. *
  51. * This function is similar to Confirm () except that the message
  52. * status or result code and description is output when the code
  53. * is non-zero; overtime, result codes have replaced status codes
  54. * and so we look in different places for codes in some MMEs;
  55. *
  56. * the status and result code fields appear at different offsets
  57. * in different messages; consequently, check the MMTYPE to find
  58. * field;
  59. *
  60. *
  61. * Contributor(s);
  62. * Charles Maier
  63. *
  64. *--------------------------------------------------------------------*/
  65. #ifndef FAILURE_SOURCE
  66. #define FAILURE_SOURCE
  67. #include <stdio.h>
  68. #include <stdarg.h>
  69. #include <stdlib.h>
  70. #include "../plc/plc.h"
  71. #include "../tools/error.h"
  72. #include "../tools/flags.h"
  73. #include "../tools/memory.h"
  74. #include "../mme/mme.h"
  75. #ifdef __GNUC__
  76. __attribute__ ((format (printf, 2, 3)))
  77. #endif
  78. void Failure (struct plc * plc, char const *format, ...)
  79. {
  80. if (_allclr (plc->flags, PLC_SILENCE))
  81. {
  82. char address [ETHER_ADDR_LEN * 3];
  83. struct channel * channel = (struct channel *)(plc->channel);
  84. struct message * message = (struct message *)(plc->message);
  85. struct __packed header_confirm
  86. {
  87. ethernet_hdr ethernet;
  88. qualcomm_hdr qualcomm;
  89. uint8_t MSTATUS;
  90. }
  91. * header = (struct header_confirm *)(message);
  92. hexdecode (header->ethernet.OSA, sizeof (header->ethernet.OSA), address, sizeof (address));
  93. fprintf (stderr, "%s %s ", channel->ifname, address);
  94. switch (LE16TOH (header->qualcomm.MMTYPE))
  95. {
  96. case VS_CONN_ADD | MMTYPE_CNF:
  97. case VS_CONN_MOD | MMTYPE_CNF:
  98. case VS_CONN_REL | MMTYPE_CNF:
  99. case VS_CONN_INFO | MMTYPE_CNF:
  100. {
  101. struct __packed header_confirm
  102. {
  103. struct ethernet_hdr ethernet;
  104. struct qualcomm_hdr qualcomm;
  105. uint32_t REQUEST;
  106. uint8_t MSTATUS;
  107. }
  108. * header = (struct header_confirm *)(message);
  109. if (header->MSTATUS)
  110. {
  111. fprintf (stderr, "%s (0x%02X): ", MMECode (header->qualcomm.MMTYPE, header->MSTATUS), header->MSTATUS);
  112. }
  113. }
  114. break;
  115. case VS_SELFTEST_RESULTS | MMTYPE_CNF:
  116. case VS_FORWARD_CONFIG | MMTYPE_CNF:
  117. {
  118. struct __packed header_confirm
  119. {
  120. struct ethernet_hdr ethernet;
  121. struct qualcomm_hdr qualcomm;
  122. uint8_t MVERSION;
  123. uint8_t RESULTCODE;
  124. }
  125. * header = (struct header_confirm *)(message);
  126. if (header->RESULTCODE)
  127. {
  128. fprintf (stderr, "%s (0x%02X): ", MMECode (header->qualcomm.MMTYPE, header->RESULTCODE), header->RESULTCODE);
  129. }
  130. }
  131. break;
  132. default:
  133. if (header->MSTATUS)
  134. {
  135. fprintf (stderr, "%s (0x%02X): ", MMECode (header->qualcomm.MMTYPE, header->MSTATUS), header->MSTATUS);
  136. }
  137. break;
  138. }
  139. if ((format) && (*format))
  140. {
  141. va_list arglist;
  142. va_start (arglist, format);
  143. vfprintf (stderr, format, arglist);
  144. va_end (arglist);
  145. }
  146. fprintf (stderr, "\n");
  147. }
  148. if (_anyset (plc->flags, PLC_BAILOUT))
  149. {
  150. if (_allclr (plc->flags, PLC_SILENCE))
  151. {
  152. error (1, 0, "Bailing Out!");
  153. }
  154. exit (1);
  155. }
  156. return;
  157. }
  158. #endif