123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- #ifndef ARPCPRINT_SOURCE
- #define ARPCPRINT_SOURCE
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <stdint.h>
- #include <sys/time.h>
- #include "../tools/types.h"
- #include "../tools/endian.h"
- #include "../tools/memory.h"
- #include "../mme/mme.h"
- #if defined (WIN32)
- #define TIMEVALUE "%012ld.%06ld"
- #elif defined (__APPLE__)
- #define TIMEVALUE "%012lu.%06u"
- #elif defined (__linux__)
- #define TIMEVALUE "%012ld.%06ld"
- #elif defined (__OpenBSD__)
- #define TIMEVALUE "%012ld.%06ld"
- #else
- #error "Unknown environment"
- #endif
- void PrintArpcMessage (FILE * fp, const char * apFormat, const uint32_t * apArgumentList, uint32_t aArgumentCount)
- {
- char MessageBuffer [2049];
- uint32_t MsgIndex;
- char GPBuffer [128];
- uint32_t Len;
- uint32_t Index;
- MsgIndex = 0;
- memset (MessageBuffer, 0, sizeof (MessageBuffer));
- Len = strlen (apFormat);
- Index = 0;
- while (apFormat [Index] && Len > 0)
- {
- if (apFormat [Index] != '%')
- {
- MessageBuffer [MsgIndex] = apFormat [Index];
- MsgIndex++;
- Index++;
- Len--;
- }
- else if (apFormat [Index + 1] == '%')
- {
- MessageBuffer [MsgIndex] = apFormat [Index];
- MsgIndex++;
- Index += 2;
- Len -= 2;
- }
- else if (apFormat [Index + 1] == '\0')
- {
- MessageBuffer [MsgIndex] = apFormat [Index];
- MsgIndex++;
- Index += 2;
- Len -= 2;
- }
- else
- {
- uint32_t iArg = 0;
- char const * pArg = & apFormat [Index];
- while (pArg && * pArg)
- {
- switch (* pArg)
- {
- case 'c':
- case 'C':
- {
- GPBuffer [iArg] = 'c';
- GPBuffer [iArg + 1] = '\0';
- pArg = NULL;
- snprintf (& MessageBuffer [MsgIndex], sizeof (MessageBuffer) - (MsgIndex -1), GPBuffer, * apArgumentList);
- MsgIndex++;
- apArgumentList++;
- Index++;
- }
- break;
- case 'd':
- case 'D':
- {
- char Buf [24];
- GPBuffer [iArg] = 'd';
- GPBuffer [iArg + 1] = '\0';
- pArg = NULL;
- (void) snprintf (Buf, sizeof (Buf) -1, GPBuffer, * apArgumentList);
- strncat (& MessageBuffer [MsgIndex], Buf, sizeof (MessageBuffer) - (MsgIndex -1));
- (void) snprintf (& MessageBuffer [MsgIndex], sizeof (MessageBuffer) - (MsgIndex -1), "%s", Buf);
- MsgIndex += strlen (Buf);
- apArgumentList++;
- Index++;
- }
- break;
- case 'x':
- case 'X':
- {
- char Buf [24];
- GPBuffer [iArg] = 'x';
- GPBuffer [iArg + 1] = '\0';
- pArg = NULL;
- (void) snprintf (Buf, sizeof (Buf) -1, GPBuffer, * apArgumentList);
- strncat (& MessageBuffer [MsgIndex], Buf, sizeof (MessageBuffer) - (MsgIndex -1));
- (void) snprintf (& MessageBuffer [MsgIndex], sizeof (MessageBuffer) - (MsgIndex -1), "%s", Buf);
- MsgIndex += strlen (Buf);
- apArgumentList++;
- Index++;
- }
- break;
- default:
- GPBuffer [iArg] = * pArg;
- iArg++;
- pArg++;
- Index++;
- }
- }
- }
- }
- fprintf (fp, "%s", (char const *) (MessageBuffer));
- }
- void ARPCPrint (FILE * fp, void const * memory, size_t extent)
- {
- #ifndef __GNUC__
- #pragma pack (push,1)
- #endif
- struct __packed vs_arpc_data
- {
- uint32_t BYPASS;
- uint16_t ARPCID;
- uint16_t DATALENGTH;
- uint8_t DATAOFFSET;
- uint8_t RESERVED;
- uint16_t ARPCSEQNUM;
- }
- * data = (struct vs_arpc_data *) (memory);
- struct __packed vs_arpc_print_data
- {
- uint16_t ARGOFFSET;
- uint16_t STROFFSET;
- uint16_t ARGLENGTH;
- uint16_t STRLENGTH;
- }
- * vpArpcPrintData;
- typedef uint32_t uint32_packed_t;
- uint32_packed_t * vpWordPointer;
- uint16_t vOffsetInBytesOfArgumentList;
- uint16_t vLengthInBytesOfArgumentList;
- uint16_t vOffsetInBytesOfFormatString;
- #ifdef ENABLE_DEBUGPRINT
- uint16_t vLengthInBytesOfFormatString;
- #endif
- uint16_t argc;
- #ifndef __GNUC__
- #pragma pack (pop)
- #endif
- #ifdef ENABLE_DEBUGPRINT
- fprintf (fp, "BYPASS=%d ", LE32TOH (data->BYPASS));
- fprintf (fp, "ARPCID=%d ", LE16TOH (data->ARPCID));
- fprintf (fp, "DATALENGTH=%d ", LE16TOH (data->DATALENGTH));
- fprintf (fp, "DATAOFFSET=%d ", data->DATAOFFSET);
- fprintf (fp, "ARPCSEQNUM=%d ", LE16TOH (data->ARPCSEQNUM));
- #endif
- char * vpBytePointer = (char *) data;
- vpBytePointer += sizeof (struct vs_arpc_data);
- vpBytePointer += data->DATAOFFSET;
- vpArpcPrintData = (struct vs_arpc_print_data *) vpBytePointer;
- #ifdef ENABLE_DEBUGPRINT
- fprintf (fp, "vpArpcPrintData=%.8x ", (uint32_t) vpArpcPrintData);
- #endif
- vOffsetInBytesOfArgumentList = LE16TOH (vpArpcPrintData->ARGOFFSET);
- vOffsetInBytesOfFormatString = LE16TOH (vpArpcPrintData->STROFFSET);
- vLengthInBytesOfArgumentList = LE16TOH (vpArpcPrintData->ARGLENGTH);
- argc = (vLengthInBytesOfArgumentList >> 2);
- #ifdef ENABLE_DEBUGPRINT
- vLengthInBytesOfFormatString = LE16TOH (vpArpcPrintData->STRLENGTH);
- fprintf (fp, "ARGOFFSET=%d ", vOffsetInBytesOfArgumentList);
- fprintf (fp, "STROFFSET=%d ", vOffsetInBytesOfFormatString);
- fprintf (fp, "ARGLENGTH=%d ", vLengthInBytesOfArgumentList);
- fprintf (fp, "STRLENGTH=%d ", vLengthInBytesOfFormatString);
- #endif
- vpBytePointer = (char *) vpArpcPrintData;
- vpBytePointer += sizeof (struct vs_arpc_print_data);
- vpBytePointer += vOffsetInBytesOfArgumentList;
- vpWordPointer = (uint32_packed_t *) vpBytePointer;
- #ifdef ENABLE_DEBUGPRINT
- fprintf (fp, "vpWordPointer=%.8x ", (uint32_t) vpWordPointer);
- #endif
- vpBytePointer = (char *) vpArpcPrintData;
- vpBytePointer += sizeof (struct vs_arpc_print_data);
- vpBytePointer += vOffsetInBytesOfFormatString;
- #ifdef ENABLE_DEBUGPRINT
- fprintf (fp, "vpBytePointer=%.8x %d\n", (uint32_t) vpBytePointer, vpBytePointer [vLengthInBytesOfFormatString]);
- #endif
- if (argc == 0)
- {
- fprintf (fp, "%s", (char const *) (vpBytePointer));
- }
- else
- {
- uint32_t * argp = (uint32_t *) malloc (sizeof (uint32_t) * argc);
- if (argp == 0)
- {
- fprintf (fp, "ARPCPrint out of memory ");
- }
- else
- {
- uint16_t i;
- for (i = 0; i < argc; i++)
- {
- argp [i] = LE32TOH (* vpWordPointer);
- vpWordPointer++;
- #ifdef ENABLE_DEBUGPRINT
- fprintf (fp, "argp[i]=%.8x i=%d vpWordPointer=%.8x\n", argp [i], i, (uint32_t) vpWordPointer);
- #endif
- }
- #ifdef ENABLE_DEBUGPRINT
- fprintf (fp, "argument copy returns\n");
- #endif
- PrintArpcMessage (fp, vpBytePointer, argp, argc);
- #ifdef ENABLE_DEBUGPRINT
- fprintf (fp, "vfprintf returns\n");
- #endif
- }
- }
- fprintf (fp, "\n");
- fflush (fp);
- return;
- }
- #endif
|