static void
printResult(UA_DataValue * value)
{
    if (value->status != UA_STATUSCODE_GOOD)
        fprintf(stderr, "%s:", UA_StatusCode_name(value->status));
    printTimestamp(value->sourceTimestamp);
}
// handle the "BadPDU" responses from HCIPDUFactory decoding
void printBadPDU (BadPDUReason r, const uint8 *pdu, uint32 len)
{
    if (r == BP_HCI_DATA_RESERVED_PBF || r == BP_HCI_DATA_RESERVED_BCF)
    {
        /*
         * hci_data_wrong_size takes precedence over
         * hci_data_reserved_pbf/bcf, so if we get this
         * far we know the length is OK.
         */
        //decodeAcl ((pdu[0] | (pdu[1] << 8)) & 0x0fff, (pdu[1] >> 4) & 3, pdu[1] >> 6, pdu + 4, len - 4);
    }
    else
    {
        size_t i;

#ifdef THREADING_WORKAROUND
    CriticalSection::Lock cs_lock (cs);
#endif
        printTimestamp ();
        printlf ("bad_pdu ");
        printByValue (badPDUreason_d, (uint32) r, 8, "r");
        printlf (":");
        for (i = 0; i < len; ++i)
        {
            printlf (" 0x%02x", pdu[i]);
        }
        printlf (" [len %lu]\n", (ul) len);
    }

}
Exemplo n.º 3
0
/**
* @brief	Prints the given kernel log-row in a user-row format.
*
* @param	kernelRow - the kernel row to print.
*
* @return	TRUE for success, FALSE for failure.
*/
Bool printKernelLogRow(const char * kernelRow)
{
	log_row_t logRow = { 0 };
	char reasonStr[30] = "";
	struct in_addr srcIp = {0};
	struct in_addr dstIp = {0};
	int sscanfResult = 0;

	/* Using unsigned short variables for the log_row_t's fields that are unsigned char, 
	   so they could be scanned as a number */
	unsigned short protocol = 0;
	unsigned short action = 0;
	unsigned short hooknum = 0;

	/* The kernel format is in the order of the log_row_t definition */
	sscanfResult = sscanf(kernelRow, "%lu %hu %hu %hu %u %u %hu %hu %d %u",
		&logRow.timestamp,
		&protocol,
		&action,
		&hooknum,
		&logRow.src_ip,
		&logRow.dst_ip,
		&logRow.src_port,
		&logRow.dst_port,
		&logRow.reason,
		&logRow.count);

	if (sscanfResult != 10)
	{
		printf("Failed scanning the log row from the string which was read from the device.\n");
		return FALSE;
	}

	srcIp.s_addr = logRow.src_ip;
	dstIp.s_addr = logRow.dst_ip;

	setReasonString(reasonStr, logRow.reason);
	
	if (!printTimestamp(&logRow.timestamp))
	{
		return FALSE;
	}

	/* Splitting the printing of the IP's because inet_ntoa returns a static buffer which changes */
	printf("%-20s ", inet_ntoa(srcIp));
	printf("%-20s ", inet_ntoa(dstIp));
	printf("%-10hu %-10hu %-10s %-10u %-10s %-30s %u\n",
		ntohs(logRow.src_port),
		ntohs(logRow.dst_port),
		getProtocolString(protocol),
		hooknum,
		getActionString(action),
		reasonStr, 
		logRow.count);

	return TRUE;
}
void DecodeCallBack::onTransportFailure (FailureMode f) 
{
    {
#ifdef THREADING_WORKAROUND
        CriticalSection::Lock cs_lock (cs);
#endif
        printTimestamp ();
        iprintlf(II("*** HCI TRANSPORT FAILED ***  (failureMode: "));
        printByValue(transportErrors_d, f, 16, "Unknown transport error");
        iprintlf(II(")"));
#ifdef DONT_COMPLETELY_SCREW_UP_ANYONE_EXPECTING_NORMAL_END_OF_LINE_TERMINATORS
        printlf("\n");
#else
        printf ("\r"); printlfOnly ("\n");
        fflush (stdout);
    }
    if (auto_rawlog)
    {
        parseCmd("rawlog", true);
    }
#endif

}
static UA_UInt32
testHistoricalDataBackend(size_t maxResponseSize)
{
    const UA_HistorizingNodeIdSettings* setting = gathering->getHistorizingSetting(server, gathering->context, &outNodeId);
    UA_HistorizingNodeIdSettings newSetting = *setting;
    newSetting.maxHistoryDataResponseSize = maxResponseSize;
    gathering->updateNodeIdSetting(server, gathering->context, &outNodeId, newSetting);

    UA_UInt32 retval = 0;
    size_t i = 0;
    testTuple *current = &testRequests[i];
    fprintf(stderr, "Testing with maxResponseSize of %lu\n", maxResponseSize);
    fprintf(stderr, "Start | End  | numValuesPerNode | returnBounds |ContPoint| {Expected}{Result} Result\n");
    fprintf(stderr, "------+------+------------------+--------------+---------+----------------\n");
    size_t j;
    while (current->start || current->end) {
        j = 0;
        if (current->start == TIMESTAMP_UNSPECIFIED) {
            fprintf(stderr, "UNSPEC|");
        } else {
            fprintf(stderr, "  %3lld |", current->start / UA_DATETIME_SEC);
        }
        if (current->end == TIMESTAMP_UNSPECIFIED) {
            fprintf(stderr, "UNSPEC|");
        } else {
            fprintf(stderr, "  %3lld |", current->end / UA_DATETIME_SEC);
        }
        fprintf(stderr, "               %2u |          %s |     %s | {", current->numValuesPerNode, (current->returnBounds ? "Yes" : " No"), (current->returnContinuationPoint ? "Yes" : " No"));
        while (current->result[j]) {
            printTimestamp(current->result[j]);
            ++j;
        }
        fprintf(stderr, "}");

        UA_DataValue *result = NULL;
        size_t resultSize = 0;
        UA_ByteString continuous;
        UA_ByteString_init(&continuous);
        UA_Boolean readOk = true;
        size_t reseivedValues = 0;
        fprintf(stderr, "{");
        size_t counter = 0;
        do {
            UA_HistoryReadResponse response;
            UA_HistoryReadResponse_init(&response);
            UA_UInt32 numValuesPerNode = current->numValuesPerNode;
            if (numValuesPerNode > 0 && numValuesPerNode + (UA_UInt32)reseivedValues > current->numValuesPerNode)
                numValuesPerNode = current->numValuesPerNode - (UA_UInt32)reseivedValues;

            requestHistory(current->start,
                           current->end,
                           &response,
                           numValuesPerNode,
                           current->returnBounds,
                           &continuous);
            ++counter;

            if(response.resultsSize != 1) {
                fprintf(stderr, "ResultError:Size %lu %s", response.resultsSize, UA_StatusCode_name(response.responseHeader.serviceResult));
                readOk = false;
                UA_HistoryReadResponse_deleteMembers(&response);
                break;
            }

            UA_StatusCode stat = response.results[0].statusCode;
            if (stat == UA_STATUSCODE_BADBOUNDNOTSUPPORTED && current->returnBounds) {
                fprintf(stderr, "%s", UA_StatusCode_name(stat));
                UA_HistoryReadResponse_deleteMembers(&response);
                break;
            }

            if(response.results[0].historyData.encoding != UA_EXTENSIONOBJECT_DECODED
                    || response.results[0].historyData.content.decoded.type != &UA_TYPES[UA_TYPES_HISTORYDATA]) {
                fprintf(stderr, "ResultError:HistoryData");
                readOk = false;
                UA_HistoryReadResponse_deleteMembers(&response);
                break;
            }

            UA_HistoryData * data = (UA_HistoryData *)response.results[0].historyData.content.decoded.data;
            resultSize = data->dataValuesSize;
            result = data->dataValues;

            if (resultSize == 0 && continuous.length > 0) {
                fprintf(stderr, "continuousResultEmpty");
                readOk = false;
                UA_HistoryReadResponse_deleteMembers(&response);
                break;
            }

            if (resultSize > maxResponseSize) {
                fprintf(stderr, "resultToBig");
                readOk = false;
                UA_HistoryReadResponse_deleteMembers(&response);
                break;
            }

            if (stat != UA_STATUSCODE_GOOD) {
                fprintf(stderr, "%s", UA_StatusCode_name(stat));
            } else {
                for (size_t k = 0; k < resultSize; ++k)
                    printResult(&result[k]);
            }

            if (stat == UA_STATUSCODE_GOOD && j >= resultSize + reseivedValues) {
                for (size_t l = 0; l < resultSize; ++l) {
                    /* See OPC UA Part 11, Version 1.03, Page 5-6, Table 1, Mark a for details.*/
                    if (current->result[l + reseivedValues] == TIMESTAMP_LAST && current->end == TIMESTAMP_UNSPECIFIED) {
                        // This test will work on not continous read, only
                        if (reseivedValues == 0 && !(l > 0 && result[l].sourceTimestamp == result[l-1].sourceTimestamp + UA_DATETIME_SEC))
                            readOk = false;
                    }
                    /* See OPC UA Part 11, Version 1.03, Page 5-6, Table 1, Mark b for details.*/
                    if (current->result[l + reseivedValues] == TIMESTAMP_FIRST && current->start == TIMESTAMP_UNSPECIFIED) {
                        // This test will work on not continous read, only
                        if (reseivedValues == 0 && !(l > 0 && result[l].sourceTimestamp == result[l-1].sourceTimestamp - UA_DATETIME_SEC))
                            readOk = false;
                    }
                    if (!resultIsEqual(&result[l], current, l + reseivedValues))
                        readOk = false;
                }
                if (response.results[0].continuationPoint.length > 0)
                    fprintf(stderr, "C,");
                reseivedValues += resultSize;
                if (reseivedValues == j) {
                    if (current->returnContinuationPoint && response.results[0].continuationPoint.length == 0) {
                        readOk = false;
                        fprintf(stderr, "missingContinuationPoint");
                    }
                    if (!current->returnContinuationPoint && response.results[0].continuationPoint.length > 0) {
                        readOk = false;
                        fprintf(stderr, "unexpectedContinuationPoint");
                    }
                    UA_HistoryReadResponse_deleteMembers(&response);
                    break;
                }
                UA_ByteString_deleteMembers(&continuous);
                UA_ByteString_copy(&response.results[0].continuationPoint, &continuous);
            } else {
                readOk = false;
                UA_HistoryReadResponse_deleteMembers(&response);
                break;
            }
            UA_HistoryReadResponse_deleteMembers(&response);
        } while (continuous.length > 0);

        if (j != reseivedValues) {
            readOk = false;
        }
        UA_ByteString_deleteMembers(&continuous);
        if (!readOk) {
            fprintf(stderr, "} Fail (%lu requests)\n", counter);
            ++retval;
        } else {
            fprintf(stderr, "} OK (%lu requests)\n", counter);
        }
        current = &testRequests[++i];
    }
    return retval;
}
void DecodeCallBack::onVMData(const PDU &pdu) 
{
    VM_PDU vmPdu(pdu);
    uint32 len = vmPdu.get_words();
    uint16 *data = new uint16 [len];
    vmPdu.get_packet(data);

#ifdef THREADING_WORKAROUND
    CriticalSection::Lock cs_lock (cs);
#endif
#if 1
    size_t u;
//  ASSERT (len != 0);

    if ( data[0] == 4 && data[1] == 0x80 && data[2] < 16 )
    {
        static class LineBuff : private NoCopy
        {
            size_t held, size;
            char *data;
        public:
            LineBuff()
                : held(0), size(256), data(new char[size])
            { }
            ~LineBuff()
            { delete [] data; }

            void append(char c)
            {
                if(held >= size)
                {
                    char *fresh = new char[size *= 2];
                    memcpy(fresh, data, held);
                    delete[] data;
                    data = fresh;
                }
                data[held++] = c;
            }

            const char *string()
            { append('\0'); return data; }

            void reset()
            { held = 0; }
        } line[16];

        // It's a VmPutChar packet, collect until newline
        int chan = data[2];
        ichar c = (ichar)data[3];
        if(c == '\n')
        {
            const char *s;

            printTimestamp ();
            printlf ("vm_print ");
            if (chan != 0)
            {
                printlf ("c:0x%1x ", chan);
            }
            s = line[chan].string();
            printlf ("\"");
            while ((c = *s++) != NUL)
            {
                printChar (c);
            }
            printlf ("\"\n");
            line[chan].reset();
        }
        else
            line[chan].append(c);
    }
    else
    {
        printTimestamp ();
        printlf ("vm_data");
#ifdef MMUSE8BITHOST
        /*
         * Use the old 8-bit code (deprecated)
         */
        if (len >= 1)
        {
            printlf (" ");
            printByValue (NULL, buf[0], 8, "len");
        }
        if (len >= 2)
        {
            printlf (" ");
            printByValue (NULL, buf[1], 8, "sc");
        }
        for (u = 2; u < len; ++u)
        {
            printlf (" 0x%02x", buf[u]);
        }
        if (len != 0 && len != buf[0])
        {
            printlf (" [len %lu]", (ul) len);
        }
#else/*MMUSE8BITHOST*/
        /*
         * Use the 16-bit version
         */
        uint32 len = data[0] * 2;
        if (len >= 2)
        {
            printlf (" ");
            printByValue (NULL, data[0] , 8 , "len" );
        }
        if (len >= 4)
        {
            printlf (" ");
            printByValue (NULL, data[1] , 8 , "sc" );
        }
        for (u = 4; u < len; u+=2)
        {
            printlf ( " 0x%04x", data[u/2] );
        }
        printlf (" [len %lu]", (ul) len);
#endif/*MMUSE8BITHOST*/
        printlf ("\n");
    }
#else
    decodeVMdata (buf, len);
#endif /* 1 */
}
Exemplo n.º 7
0
void decodeHQ (const PA pa)
{

	size_t i = 4;
	bool ppr;

	ASSERT (pa[0] >= 4);

	/* Test if this an FM RSSI event and we should pretty print it */
	ppr = (fmPrettyRSSI && pa[1] == HQVARID_FM_EVENT && pa[4] == 0x400);

	if (!ppr)
	{
		/* This is suppressed for pretty RSSI scan */
		printTimestamp ();
		printlf ("hq ");
		printByValue (NULL, pa[2], 16, "sn");
		printlf (" ");
		printByValue (hqVarID_d, pa[1], 16, "vi");
		printlf (" ");
		printByValue (hqStatus_d, pa[3], 16, "s");
	}

	if (pa[1] == HQVARID_FAULT && pa[0] >= 5)
	{
		printlf (" ");
		printByValue (faultID_d, pa[4], 16, "fi");
		++i;
	}
	else if (pa[1] == HQVARID_DRAIN_CALIBRATE && pa[0] >= 5)
	{
		printlf (" ");
		printByValue (NULL, pa[4], 32, "awake");
		printlf (" ");
		printByValue (NULL, pa[5], 32, "asleep");
		printlf (" ");
		printByValue (NULL, pa[6], 32, "half_slots");
		i += 3;
		if (pa[0] >= 6)
		{
		    printlf (" ");
		    printByValue (NULL, pa[7], 32, "half_slots_pa");
		    i++;
		    if (pa[0] >= 7)
		    {		    
				printlf (" ");
				printByValue (NULL, pa[8], 32, "fm_radio");
				i++;
		    }
		    if (pa[0] >= 8)
		    {		    
				printlf (" ");
				printByValue (NULL, pa[9], 32, "fm_radio_tx");
				i++;
		    }		    
		    if (pa[0] >= 9)
		    {		    
				printlf (" ");
				printByValue (NULL, pa[10], 32, "fm_lo");
				i++;
		    }		    
		}
	}
	else if (pa[1] == HQVARID_FM_EVENT && pa[0] >= 4)
	{
		/* FM Radio HQ Event */
		/* pa[4] contains a copy of the flag register */
		/* Test if this is an RSSI event or not. */
		if(!ppr)
		{
			/* Normal event decode */
			printlf("\n0x%lx FM HQ Event: flags ", (ul) pa[4]);
			if (pa[4] != 0)
			{

				int index = 0;
				while (fm_flag_vals[index].value != 0)
				{
					if (fm_flag_vals[index].value & pa[4])
						printlf(" : %s", fm_flag_vals[index].name);
					index++;
				}
			}
			else
			{
				printlf("all cleared");
			}
			
			i=5;

			/* There may be additional registers/value pairs in the message. A register value 
			of 0, or end of file, indicates no further registers */
			while(i < (pa[0] -1) && pa[i] != 0)
			{
				decodeFMReg(pa[i], pa[i+1]);
				i += 2;
			}
		}
		else
		{
			/* Pretty RSSI */
			double freq = ((pa[6] + 60000.0)/1000.0);
			signed char rssi = (signed char)pa[8];

			printlf("0x%lx FM HQ Event(RSSI):  ", (ul) pa[4]);

			if(freq < 100)
				printlf(" ");

			printlf("%.1fMHz ", freq);

			if(rssi > -100)
				printlf(" ");

			printlf(" %ddBm ", rssi);

			if ((signed char)pa[8] > -20)
				printlf("-");
			if ((signed char)pa[8] > -25)
				printlf("-");
			if ((signed char)pa[8] > -30)
				printlf("-");
			if ((signed char)pa[8] > -35)
				printlf("-");
			if ((signed char)pa[8] > -40)
				printlf("-");
			if ((signed char)pa[8] > -45)
				printlf("-");
			if ((signed char)pa[8] > -50)
				printlf("-");
			if ((signed char)pa[8] > -55)
				printlf("-");
			if ((signed char)pa[8] > -60)
				printlf("-");
			if ((signed char)pa[8] > -65)
				printlf("-");
			if ((signed char)pa[8] > -70)
				printlf("-");
			if ((signed char)pa[8] > -75)
				printlf("-");
			if ((signed char)pa[8] > -80)
				printlf("-");
			if ((signed char)pa[8] > -85)
				printlf("-");
			if ((signed char)pa[8] > -90)
				printlf("-");
			if ((signed char)pa[8] > -95)
				printlf("-");
			if ((signed char)pa[8] > -100)
				printlf("-");
			if ((signed char)pa[8] > -105)
				printlf("-");
			if ((signed char)pa[8] > -110)
				printlf("-");
			if ((signed char)pa[8] > -115)
				printlf("-");
			if ((signed char)pa[8] > -120)
				printlf("-");
			printlf("+\n");
		}
	}
	else if (pa[1] == HQVARID_FMTX_EVENT && pa[0] >= 4)
	{
		/* FMTX Radio HQ Event */
		/* pa[4] contains a copy of the flag register */

		printlf("\n0x%lx FMTX HQ Event: flags ", (ul) pa[4]);
		if (pa[4] != 0)
		{

			int index = 0;
			while (fmtx_flag_vals[index].value != 0)
			{
				if (fmtx_flag_vals[index].value & pa[4])
					printlf(" : %s", fmtx_flag_vals[index].name);
				index++;
			}
		}
		else
		{
			printlf("all cleared");
		}
		i=5;

		/* There may be additional registers/value pairs in the message. A register value 
		of 0, or end of file, indicates no further registers */
		while(i < (pa[0] -1) && pa[i] != 0)
		{
			decodeFMTXReg(pa[i], pa[i+1]);
			i += 2;
		}

	}
	else if (pa[1] == HQVARID_FM_RDS_DATA && pa[0] >= 5)
	{
		/* FM Radio RDS Data event */
		uint16 blockCount;

		printlf("\n");

		for (blockCount = 0, i = 6; blockCount < pa[4]; blockCount++, i += 2)
		{
			if (blockCount != 0 && blockCount%4 == 0)
				printlf("\n");
			decodeRDSBlock(pa[i-1], pa[i]);
		}

		i = pa[0];
	}
        else if (pa [1] == HQVARID_DSPMANAGER_DEBUG_INFO_B)
        {
                printlf (" time:0x%lx ", (ul) pa [4]);
                printByValue (baton_messages_d, pa[5], 16, "id");
                printlf (" len:0x%lx", (ul) pa [6]);
                i = 7; /* Everything after length printed by the remainder loop at the end */
        }

    /* Just print out the remainder of the payload.. should be 'nothing' */
	if (!ppr)
	{
		/* This is suppressed for pretty RSSI scan */
		for (; i < pa[0]; ++i)
		{
			printlf (" 0x%lx", (ul) pa[i]);

		}
		printlf ("\n");
	}

}