// 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);
    }

}
Beispiel #2
0
static void
getdata(void)
{
	char *p, buf[1000], buf1[100];
	int ln;

	curfile->lineno = 0;
	printlf(1, curfile->fname);
	while (fgets(buf, sizeof buf, curfile->fin) != NULL) {
		curfile->lineno++;
		if (*buf == '.' && *(buf+1) == 'P' && *(buf+2) == 'S') {
			for (p = &buf[3]; *p == ' '; p++)
				;
			if (*p++ == '<') {
				Infile svfile;
				svfile = *curfile;
				sscanf(p, "%s", buf1);
				if ((curfile->fin=fopen(buf1, "r")) == NULL)
					ERROR "can't open %s", buf1 FATAL;
				curfile->fname = tostring(buf1);
				getdata();
				fclose(curfile->fin);
				free(curfile->fname);
				*curfile = svfile;
				printlf(curfile->lineno, curfile->fname);
				continue;
			}
			reset();
			yyparse();
			anyerr += synerr;
			/* yylval.i now contains 'E' or 'F' from .PE or .PF */

			deltx = (xmax - xmin) / getfval("scale");
			delty = (ymax - ymin) / getfval("scale");
			if (buf[3] == ' ') {	/* next things are wid & ht */
				if (sscanf(&buf[4],"%lf %lf", &deltx, &delty) < 2)
					delty = deltx * (ymax-ymin) / (xmax-xmin);
#if 0
				/* else {
				 *	double xfac, yfac; */
				 *	xfac = deltx / (xmax-xmin);
				 *	yfac = delty / (ymax-ymin);
				 *	if (xfac <= yfac)
				 *		delty = xfac * (ymax-ymin);
				 *	else
				 *		deltx = yfac * (xmax-xmin);
				 *}
				 */
#endif
			}
			dprintf("deltx = %g, delty = %g\n", deltx, delty);
			if (codegen && !synerr) {
				openpl(&buf[3]);	/* puts out .PS, with ht & wid stuck in */
				printlf(curfile->lineno+1, NULL);
				print();	/* assumes \n at end */
				closepl(yylval.i);	/* does the .PE/F */
			}
			printlf(curfile->lineno+1, NULL);
			fflush(stdout);
		} else if (buf[0] == '.' && buf[1] == 'l' && buf[2] == 'f') {
void putDone (void)
{
#if 0
	size_t i;

	ASSERT (paout != NULL);
	ASSERT (pacurrent == paout[0]);

	paout[0] = pacurrent;

	printlf ("->");
	for (i = 0; i < paout[0]; ++i)
	{
		printlf (" 0x%lx", (ul) paout[i]);
	}
	printlf ("\n");
#else
	ASSERT (paout != NULL);
	ASSERT (pacurrent == paout[0]);

	sendCmd (paout);

	free (paout);
	paout = NULL;
#endif
}
void DecodeCallBack::onHCIEvent(const PDU &pdu) 
{
    HCIEventPDU eventPdu(pdu);
    BadPDUReason failCode;
    uint32 length = HCIPDUFactory::decomposeEventPDU(pdu, 0, failCode);
    
    if ( length == 0 )
    {
        printBadPDU (failCode, pdu.data(), pdu.size() );
        return;
    }

    if (eventPdu.get_event_code() == HCI_EV_NUMBER_COMPLETED_PKTS)
    {
        aclEngine->nocp(pdu);
    }
    else if (eventPdu.get_event_code() == HCI_EV_COMMAND_COMPLETE)
    {
        HCICommandCompletePDU cc_pdu(pdu);
        if (cc_pdu.get_op_code() == HCI_READ_BUFFER_SIZE)
        {
            HCI_READ_BUFFER_SIZE_RET_T_PDU rbs_pdu(cc_pdu);
            aclEngine->setBufferSizes(rbs_pdu);
            scoEngine->setBufferSizes(rbs_pdu);
        }
    }

    if (length != 0)
    {
        uint32 *pa = new uint32 [length];

        if (pa == 0)
        {
            return;
        }

        pa [0] = length;
        length = HCIPDUFactory::decomposeEventPDU(pdu, pa, failCode);

#ifdef THREADING_WORKAROUND
        CriticalSection::Lock cs_lock (cs);
#endif
#if 0
        unsigned i;

        ASSERT (pa[0] >= 2);
        ASSERT (ec == pa[1]);

        printlf ("App: received event, code 0x%02x, pa[] =", ec);
        for (i = 2; i < pa[0]; ++i)
        {
            printlf (" 0x%lx", (ul) pa[i]);
        }
        printlf (" [%u args]\n", pa[0] - 2);
#else
        decodeEvt (pa);
#endif
    }
}
void DecodeCallBack::onHCIACLData(const PDU &pdu) 
{
    HCIACLPDU aclpdu(pdu);
#if 0
    uint16 ch = pdu.get_handle ();
    bool pb = pdu.get_pbf () == HCIACLPDU::start;
    BROADCAST_TYPE bf = conv (pdu.get_bct ());
    const uint8 *data = pdu.get_dataPtr ();
    uint16 length = pdu.get_length ();
    unsigned u;

    ASSERT (bf <= 2);

    printlf ("App: received data [%s%s], data =", pb ? "start" : "contin", bf == 0 ? "" : bf == 1 ? "; active broadcast" : "; piconet broadcast");
    for (u = 0; u < length; ++u)
    {
        printlf (" %02x", data[u]);
    }
    printlf (" [len %lu]\n", (ul) length);

    pdd->sendHCIData (ch, pb, bf, data, length);
#else
    {
        
        btcli_enter_critical_section();
        if (fastpipeEngineIsConnected(aclpdu.get_handle()))
        {
            fastpipeEngineReceive(aclpdu);
            btcli_leave_critical_section();
        }
        else
        {
            // Leave critical section before entering aclEngine.
            // AclEngine isn't very hygeinic about its threads, so printlf 
            // (which needs locking) is called from various different threads.
            // CriticalSection::Lock on Linux can't be obtained recursively, so
            // just drop the lock now to make life easier.
            btcli_leave_critical_section();
            aclEngine->receive(aclpdu);
        }
    }
#endif
}
void DecodeCallBack::onLMPdebug(const PDU &pdu)
{
    const uint8 *buf = pdu.data ();
    size_t len = pdu.size ();

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

    printlf ("lmp");
    for (; len != 0; --len)
    {
        printlf (" 0x%02x", *buf++);
    }
    printlf ("\n");
#else
    decodeLMPdebug (buf, len, NULL);
#endif
}
void DecodeCallBack::onDebug ( const PDU& pdu) 
{
    const uint8 *buf = pdu.data ();
    size_t len = pdu.size ();

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

    if (buf[len - 1] == NUL)
    {
        printlf ("debug");
        printlf (" \"");
        while (len--)
        {
            printChar (*buf++);
        }
        printlf ("\"\n");
    }
    else
    {
        printlf ("debug");
        for (; len != 0; --len)
        {
            printlf (" 0x%02x", *buf++);
        }
        printlf ("\n");
    }
#else   
    decodeDebug(buf, len);
#endif
}
void DecodeCallBack::onHQRequest(const PDU &pdu) 
{
    BadPDUReason failCode;

    uint32 length = HCIPDUFactory::decomposeHQ_PDU (pdu, 0, failCode);

    if (length == 0)
    {
        printBadPDU (failCode, pdu.data(), pdu.size() );
    }
    else
    {
        uint32 *pa = new uint32 [length];

        if (pa == 0)
        {
            return;
        }

        pa [0] = length;
        length = HCIPDUFactory::decomposeHQ_PDU(pdu, pa, failCode);
    
#ifdef THREADING_WORKAROUND
        CriticalSection::Lock cs_lock (cs);
#endif
#if 0
        size_t i;
        ASSERT (pa[0] >= 4);

        printlf ("App: received hq indication; cmd 0x%lx with seqno 0x%lx, status %lu, pa[] =", (ul) pa[1], (ul) pa[2], (ul) pa[3]);
        for (i = 4; i < pa[0]; ++i)
        {
            printlf (" 0x%lx", (ul) pa[i]);
        }
        printlf (" [%u args]\n", pa[0] - 4);
#else
        decodeHQ (pa);
#endif
    }
}
Beispiel #9
0
void copy(void)	/* begin input from file, etc. */
{
	FILE *fin;

	if (newfile) {
		if ((fin = fopen(newfile, "r")) == NULL)
			ERROR "can't open file %s", newfile FATAL;
		curfile++;
		curfile->fin = fin;
		curfile->fname = newfile;
		curfile->lineno = 0;
		printlf(1, curfile->fname);
		pushsrc(File, curfile->fname);
		newfile = 0;
	}
	if (thrudef) {
		thru = 1;
		begin = 1;	/* wrong place */
	}
}
bool printMatchByName (const Dictionary dictionary, const char *name)
{
	bool found = false;
	size_t i;
	const char *dictname;

	for (i = 0; ; ++i)
	{
		dictname = dictionary[i].name;
		if (dictname == NULL)
		{
			break;
		}
		if (strstr (dictname, name) != NULL)
		{
			found = true;
			printlf ("%s (0x%04lx)\n", dictname, (ul) dictionary[i].value);
		}
	}

	return found;
}
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

}
Beispiel #12
0
int main(){
	printlf("ok");
	}
Beispiel #13
0
int main(int argc, char **argv) {
  printlf("%s", "hello,world");
  return 0;
}
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 */
}
Beispiel #15
0
nextchar(void)
{
	register int c;

	c = 0;
  loop:
	switch (srcp->type) {
	case Free:	/* free string */
		free(srcp->sp);
		popsrc();
		goto loop;
	case Thru:	/* end of pushed back line */
		begin = 1;
		popsrc();
		c = '\n';
		break;
	case Char:
		if (pb >= pbuf) {
			c = *pb--;
			popsrc();
			break;
		} else {	/* can't happen? */
			popsrc();
			goto loop;
		}
	case String:
		c = *srcp->sp++;
		if (c == '\0') {
			popsrc();
			goto loop;
		} else {
			if (*srcp->sp == '\0')	/* empty, so pop */
				popsrc();
			break;
		}
	case Macro:
		c = *srcp->sp++;
		if (c == '\0') {
			if (--argfp < args)
				ERROR "argfp underflow" FATAL;
			popsrc();
			goto loop;
		} else if (c == '$' && isdigit(*srcp->sp)) {
			int n = 0;
			while (isdigit(*srcp->sp))
				n = 10 * n + *srcp->sp++ - '0';
			if (n > 0 && n <= MAXARGS)
				pushsrc(String, argfp->argstk[n-1]);
			goto loop;
		}
		break;
	case File:
		c = getc(curfile->fin);
		if (c == EOF) {
			if (curfile == infile)
				ERROR "end of file inside .PS/.PE" FATAL;
			if (curfile->fin != stdin) {
				fclose(curfile->fin);
				free(curfile->fname);	/* assumes allocated */
			}
			curfile--;
			printlf(curfile->lineno, curfile->fname);
			popsrc();
			thru = 0;	/* chicken out */
			thrudef = 0;
			if (untilstr) {
				free(untilstr);
				untilstr = 0;
			}
			goto loop;
		}
		if (c == '\n')
			curfile->lineno++;
		break;
	}
	return c;
}
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");
	}

}