Ejemplo n.º 1
0
bool cSmartCardDataVideoGuard2::Parse(const char *line)
{
  line=skipspace(line);
  if(!strncasecmp(line,"BOXID",5))     { type=dtBoxId; line+=5; }
  else if(!strncasecmp(line,"SEED",4)) { type=dtSeed; line+=4; }
  else {
    PRINTF(L_CORE_LOAD,"smartcarddatavideoguard2: format error: datatype");
    return false;
    }
  line=skipspace(line);
  switch(type) {
    case dtBoxId:
      if(GetHex(line,boxid,sizeof(boxid))!=sizeof(boxid)) {
        PRINTF(L_CORE_LOAD,"smartcarddatavideoguard2: format error: boxid");
        return false;
        }
      break;
    case dtSeed:
      if(GetHex(line,seed0,sizeof(seed0))!=sizeof(seed0)) {
        PRINTF(L_CORE_LOAD,"smartcarddatacryptoworks: format error: seed0");
        return false;
        }
      line=skipspace(line);
      if(GetHex(line,seed1,sizeof(seed1))!=sizeof(seed1)) {
        PRINTF(L_CORE_LOAD,"smartcarddatacryptoworks: format error: seed1");
        return false;
        }
      break;
    }
  return true;
}
Ejemplo n.º 2
0
///////////////////////////////////////////////////////////////////////////////
///@author      Costin Grigorescu
///@brief       Forward DAO to EntryPoint
///@param       [in] p_nDataFieldDescriptor - Data field descriptor
///@param       [in] p_pPayload - DAO message
///@param       [in] p_nPayloadLength - DAO message len
///@retval		0 - failed to send
///@retval		1 - success
///////////////////////////////////////////////////////////////////////////////
void CRplRootApp::AddDAORelayEncap(MgmtProtocol::CMgmtPMessage::MsgDAORelayData::DataFieldDescriptorType p_nDataFieldDescriptor,
	const uint8_t* p_pPayload,
	uint16_t p_nPayloadLength){

    MgmtProtocol::CMgmtPMessage::Ptr pMsg(new MgmtProtocol::CMgmtPMessage);

    //init header
    pMsg->m_Header.SetMsgType(MgmtProtocol::CMgmtPMessage::DAO_RELAY);
    pMsg->m_Header.m_u32SeqNo = m_pMgmtClientLink->m_oSeqNoGenerator.GetNextMsgId ( );

	MgmtProtocol::CMgmtPMessage::MsgDAORelayData oMsgDAORelayData;
	// set far id
	oMsgDAORelayData.m_pu8_FAR_ID = GetFarId();
	// set data field descriptor
	oMsgDAORelayData.m_u8_DataFieldDescriptor = p_nDataFieldDescriptor;
	// set DIO MOP
    oMsgDAORelayData.m_u8_DIO_MOP = GET_MOP( &g_oRplInstance.m_oRplConfig );
	// set lifetime_unit
	oMsgDAORelayData.m_u16_DIOLifetimeUnit =  m_stCfg.m_oMapConfig.m_oRplProfile.m_nDefRouteLifetimeUnit;
	// set DAO message
	oMsgDAORelayData.m_pu8_DAOData = p_pPayload;
	oMsgDAORelayData.m_u32_DAODataLen = p_nPayloadLength;

	NLOG_INFO( "Encap+ DAO_RELAY: far=%s, dfd=%d, dao_len=%d",
			 GetHex( oMsgDAORelayData.m_pu8_FAR_ID, oMsgDAORelayData.m_st_u8_FAR_ID_Len ),
			 oMsgDAORelayData.m_u8_DataFieldDescriptor,
			 oMsgDAORelayData.m_u32_DAODataLen );

	NLOG_DBG( "\tdao=%s", GetHex( oMsgDAORelayData.m_pu8_DAOData, oMsgDAORelayData.m_u32_DAODataLen ) );

    pMsg->SetData(&oMsgDAORelayData);

	m_shpoCnsDaoMsg->OptionAddEncap(pMsg.get());
 }
Ejemplo n.º 3
0
bool cViaccessCardInfo::Parse(const char *line)
{
  return GetHex(line,ident,sizeof(ident)) && 
         GetHex(line,ua,sizeof(ua)) &&
         GetHex(line,sa,sizeof(sa)) &&
         GetHex(line,&keyno,1) && 
         GetHex(line,key,sizeof(key));
}
Ejemplo n.º 4
0
bool cPlainKeyConax::Parse(const char *line)
{
  unsigned char sid, skey[PLAINLEN_CONAX];
  if(GetChar(line,&type,1) && GetHex(line,&sid,1) &&
     GetChar(line,&keynr,1) && GetHex(line,skey,PLAINLEN_CONAX)) {
    type=toupper(type); keynr=toupper(keynr); id=sid;
    SetBinKey(skey,PLAINLEN_CONAX);
    return true;
    }
  return false;
}
Ejemplo n.º 5
0
static inline unsigned short GetHEX2(const char *foo,const char **endptr)
{
	MiU32 ret = 0;

	ret = (GetHex((MiU8)foo[0])<<12) | (GetHex((MiU8)foo[1])<<8) | (GetHex((MiU8)foo[2])<<4) | GetHex((MiU8)foo[3]);

	if ( endptr )
	{
		*endptr = foo+4;
	}

	return (unsigned short) ret;
}
static inline unsigned char GetHEX1(const char *foo,const char **endptr)
{
	unsigned int ret = 0;

	ret = (GetHex(foo[0])<<4) | GetHex(foo[1]);

	if ( endptr )
	{
		*endptr = foo+2;
	}

	return (unsigned char) ret;
}
Ejemplo n.º 7
0
NxU16 GetHEX2(const char *foo,const char **endptr)
{
	NxU32 ret = 0;

	ret = (GetHex(foo[0])<<12) | (GetHex(foo[1])<<8) | (GetHex(foo[2])<<4) | GetHex(foo[3]);

	if ( endptr )
	{
		*endptr = foo+4;
	}

	return (NxU16) ret;
}
Ejemplo n.º 8
0
NxU8 GetHEX1(const char *foo,const char **endptr)
{
	NxU32 ret = 0;

	ret = (GetHex(foo[0])<<4) | GetHex(foo[1]);

	if ( endptr )
	{
		*endptr = foo+2;
	}

	return (NxU8) ret;
}
Ejemplo n.º 9
0
static inline MiU8 GetHEX1(const char *foo,const char **endptr)
{
	MiU32 ret = 0;

	ret = (GetHex((MiU8)foo[0])<<4) | GetHex((MiU8)foo[1]);

	if ( endptr )
	{
		*endptr = foo+2;
	}

	return (MiU8) ret;
}
Ejemplo n.º 10
0
internal rectangle2
DEBUGTextOp(debug_state *DebugState, debug_text_op Op, v2 P, char *String, v4 Color = V4(1, 1, 1, 1)) {
    rectangle2 Result = InvertedInfinityRectangle2();
    if (DebugState && DebugState->DebugFont) {
        render_group *RenderGroup = DebugState->RenderGroup;
        loaded_font *Font = DebugState->DebugFont;
        hha_font *Info = DebugState->DebugFontInfo;

        u32 PrevCodePoint = 0;

        for (char *At = String; *At; ++At) {
            u32 CodePoint = *At;

            if (At[0] == '\\' && IsHex(At[1]) && IsHex(At[2]) && IsHex(At[3]) && IsHex(At[4])) {
                CodePoint = (GetHex(At[1]) << 12 |
                             GetHex(At[2]) <<  8 |
                             GetHex(At[3]) <<  4 |
                             GetHex(At[4]) <<  0);
                At += 4;
            }

            r32 AdvanceX = DebugState->FontScale * GetHorizontalAdvanceForPair(Info, Font, PrevCodePoint, CodePoint);
            P.x += AdvanceX;

            if (CodePoint != ' ') {
                bitmap_id BitmapID = GetBitmapForGlyph(RenderGroup->Assets, Info, Font, CodePoint);
                hha_bitmap *BitmapInfo = GetBitmapInfo(RenderGroup->Assets, BitmapID);

                r32 BitmapScale = DebugState->FontScale * (r32)BitmapInfo->Dim[1];
                v3 BitmapOffset = V3(P.x, P.y, 0);
                if (Op == DEBUGTextOp_DrawText) {
                    PushBitmap(RenderGroup, BitmapID, BitmapScale, BitmapOffset, Color);
                } else {
                    Assert(Op == DEBUGTextOp_SizeText);

                    loaded_bitmap *Bitmap = GetBitmap(RenderGroup->Assets, BitmapID, RenderGroup->GenerationID);
                    if (Bitmap) {
                        used_bitmap_dim Dim = GetBitmapDim(RenderGroup, Bitmap, BitmapScale, BitmapOffset, 1.0f);
                        rectangle2 GlyphDim = RectMinDim(Dim.P.xy, Dim.Size);
                        Result = Union(Result, GlyphDim);
                    }
                }
            }

            PrevCodePoint = CodePoint;
        }
    }

    return Result;
}
Ejemplo n.º 11
0
bool cSmartCardDataNagra::Parse(const char *line)
{
  bool isSK=false;
  int dlen=64;
  BN_set_word(exp,3);
  line=skipspace(line);
  unsigned char id[4];
  if(GetHex(line,id,sizeof(id))!=sizeof(id)) {
    PRINTF(L_CORE_LOAD,"smartcarddatanagra: format error: card id");
    return false;
    }
  cardid=UINT32_BE(id);
  line=skipspace(line);
  if(!strncasecmp(line,"SK",2)) { isSK=true; dlen=96; line+=2; }
  else {
    if(GetHex(line,bk,sizeof(bk))!=sizeof(bk)) {
      PRINTF(L_CORE_LOAD,"smartcarddatanagra: format error: boxkey");
      return false;
      }
    line=skipspace(line);
    if(!strncasecmp(line,"IRDMOD",6)) { isIrdMod=true; line+=6; }
    else if(!strncasecmp(line,"CARDMOD",7)) { isIrdMod=false; line+=7; }
    else {
      PRINTF(L_CORE_LOAD,"smartcarddatanagra: format error: IRDMOD/CARDMOD");
      return false;
      }
    }
  line=skipspace(line);

  unsigned char *buff=AUTOMEM(dlen);
  if(GetHex(line,buff,dlen)!=dlen) {
    PRINTF(L_CORE_LOAD,"smartcarddatanagra: format error: data block");
    return false;
    }
  if(!isSK) {
    mod.Get(buff,64);
    }
  else {
    struct SecondaryKey *sk=(struct SecondaryKey *)buff;
    if(UINT16_BE(sk->cs)!=CRC16(buff,sizeof(*sk)-sizeof(sk->cs),false)) {
      PRINTF(L_CORE_LOAD,"smartcarddatanagra: secondary key CRC failed");
      return false;
      }
    unsigned short e=UINT16_BE(sk->exp);
    if(e!=0x0003 && e!=CRC16(buff,12,false)) BN_set_word(exp,e);
    xxor(bk,sizeof(bk),sk->y1,sk->y2);
    mod.Get(sk->mod,sizeof(sk->mod));
    }
  return true;
}
Ejemplo n.º 12
0
UString ConvertMethodIdToString(UInt64 id)
{
  wchar_t s[32];
  int len = 32;
  s[--len] = 0;
  do
  {
    s[--len] = GetHex((Byte)id & 0xF);
    id >>= 4;
    s[--len] = GetHex((Byte)id & 0xF);
    id >>= 4;
  }
  while (id != 0);
  return s + len;
}
Ejemplo n.º 13
0
static inline	unsigned short GetHEX2(const char	*foo,	const	char **endptr)
{
	unsigned int ret = 0;

	if ( foo )
	{
		ret	=	(GetHex(foo[0])	<< 12) | (GetHex(foo[1]) <<	8) | (GetHex(foo[2]) <<	4) | GetHex(foo[3]);

		if (endptr)
		{
			*endptr	=	foo	+	4;
		}
	}

	return (unsigned short)ret;
}
bool LogicalExpression::GetNumber(const wchar_t **p, long long *n)
{
  if (!IsDigit(**p))
    return false;

  *n=0;

  if (**p == L'0' && ((*(*p+1))|0x20) == L'x')
  {
    (*p)+=2;

    if (!IsHexDigit(**p))
      return false;

    while (IsHexDigit(**p))
    {
      *n=*n*16ll + GetHex(**p);
      (*p)++;
    }
  }
  else if (!GetIPv4(p,n))
  {
    *n=0;
    while (IsDigit(**p))
    {
      *n=*n*10ll+**p-L'0';
      (*p)++;
    }
  }

  return true;
}
Ejemplo n.º 15
0
int CFileParser::GetInt()
{
	GetToken();

	if( GetTokenType() == HEX )	
	{ 
		m_wszBuff += 2; 
		wchar_t* pPos = m_wszBuff; 
		
		while(!IsWhiteSpace(*pPos) && *pPos ) 
			pPos++; 
		
			m_wszToken = wstring( m_wszBuff, pPos - m_wszBuff); 
			m_wszBuff = pPos; 
			return (int)GetHex(); 
	} 
	else 
	{
		wchar_t* pPos = m_wszBuff;

		while(!IsWhiteSpace(*pPos) && *pPos )
			pPos++;



		m_wszToken = wstring( m_wszBuff, pPos - m_wszBuff );

		m_wszBuff = pPos;

		if( m_wszToken[0] ) 
			READ_TABLE( _wtoi ); 
	}

	return 0;
}
Ejemplo n.º 16
0
bool CCmdLine::getNumber(int &value)
{
	int i, x;
	int base;
	int cnt;

	bool neg = false;
	if (par[0] == '-') { neg = true; par++; }
	else if (par[0] == '+') par++;

	switch (par[0])
	{
		case 'b':
		case 'B': base =  2; cnt = 31; par++; break;
		case '$': base = 16; cnt =  7; par++; break;
		default:  base = 10; cnt =  9;
	}

	value = GetHex(par[0]);
	if (value < 0 || base <= value) return false;
	par++;

	for (i=0; i<cnt; i++)
	{
		while (par[0] == '_') par++;
		x = GetHex(par[0]);
		if (0 <= x && x < base) value = value*base + x;
		else break;
		par++;
	}

	if (neg) value = -value;

	x = GetHex(par[0]);
	if (0 <= x && x < base) return false;

	return true;
}
Ejemplo n.º 17
0
static inline MiU32 GetHEX4(const char *foo,const char **endptr)
{
	MiU32 ret = 0;

	for (MiI32 i=0; i<8; i++)
	{
		ret = (ret<<4) | GetHex((MiU8)foo[i]);
	}

	if ( endptr )
	{
		*endptr = foo+8;
	}

	return ret;
}
Ejemplo n.º 18
0
NxU32 GetHEX4(const char *foo,const char **endptr)
{
	NxU32 ret = 0;

	for (NxI32 i=0; i<8; i++)
	{
		ret = (ret<<4) | GetHex(foo[i]);
	}

	if ( endptr )
	{
		*endptr = foo+8;
	}

	return ret;
}
static inline unsigned int GetHEX4(const char *foo,const char **endptr)
{
	unsigned int ret = 0;

	for (int i=0; i<8; i++)
	{
		ret = (ret<<4) | GetHex(foo[i]);
	}

	if ( endptr )
	{
		*endptr = foo+8;
	}

	return ret;
}
Ejemplo n.º 20
0
bool cPlainKeyVia::Parse(const char *line)
{
  unsigned char sid[3], skeynr, skey[VIA2_KEYLEN];
  int len;
  if(GetChar(line,&type,1) && (len=GetHex(line,sid,3,false))) {
     type=toupper(type); id=Bin2Int(sid,len);
     line=skipspace(line);
     bool ok=false;
     if(!strncasecmp(line,"TPSMK",5) && line[5]>='0' && line[5]<='9') {
       keynr=MBC3('M','K',line[5]-'0');
       line+=6;
       ok=(len=GetHex(line,skey,VIATPS_KEYLEN));
       }
     else if(!strncasecmp(line,"TPS ",4)) {
       line+=4;
       keynr=MBC3('T','P','S');
       ok=(len=GetHex(line,skey,VIATPS_KEYLEN));
       }
     else if(*line == 'D' || *line == 'P' || *line == 'X' || *line == 'C' || *line == 'E') {
       if(isxdigit(line[1])) {
         bool e_line=(*line=='E');
         keynr=MBC3(*line,line[1]>='A' ? toupper(line[1])-'A' : line[1]-'0', 0);
         line+=2;
         ok=((len=GetHex(line,skey,VIA2_KEYLEN,false)) && (len==e_line ? VIA2_KEYLEN : VIA1_KEYLEN));
         }
       }
     else if(*line == 'T') {
       unsigned char tkey[256];
       if(isxdigit(line[1])) {
         keynr=MBC3(*line,line[1]>='A' ? toupper(line[1])-'A' : line[1]-'0', 0);
         line+=2;
         if((len=GetHex(line,tkey,256,false)) && (len==256)) {
           SetBinKey(tkey,len);
           return true;
           }
         }
       }
     else if(GetHex(line,&skeynr,1)) {
       keynr=skeynr;
       ok=((len=GetHex(line,skey,VIA2_KEYLEN,false)) && (len==VIA1_KEYLEN || len==VIA2_KEYLEN));
       }
     if(ok) {
       SetBinKey(skey,len);
       return true;
       }
    }
  return false;
}
Ejemplo n.º 21
0
bool CSumiNodeTesterApp::SendUdpData()
{
	static unsigned int s_unUdpMsgId = 0;
    //msg header
    uint8_t u8CurrSerialMsgId = g_u8SerialMsgId;
	API_MSG_HDR *pUDPSendDatagramHdr = (API_MSG_HDR*)g_pucSendBuf;
	SET_API_HDR(pUDPSendDatagramHdr, UDP_SPECIFIC, API_MSG_REQ, UDP_SEND_DATAGRAM, g_u8SerialMsgId, sizeof(UDP_SEND_DATAGRAM_PYLD) + m_stCfg.GetUdpPyldSize());
	++g_u8SerialMsgId;
	//msg payload
    UDP_SEND_DATAGRAM_PYLD *pUDPSendDatagramPyld = (UDP_SEND_DATAGRAM_PYLD*)(g_pucSendBuf + sizeof(API_MSG_HDR));
    UDP_SEND_DATAGRAM_SET_SRC_PORT(pUDPSendDatagramPyld, m_stCfg.GetUdpLocalPort());
    UDP_SEND_DATAGRAM_SET_DST_PORT(pUDPSendDatagramPyld, m_stCfg.GetCoordIpv6()->GetPort());
    memcpy(pUDPSendDatagramPyld->m_au8DstIpv6, m_stCfg.GetCoordIpv6()->GetIPv6(), 16);
    //msg udp payload
    UDP_PYLD_ID *pUDPPyldId = (UDP_PYLD_ID*)(g_pucSendBuf + sizeof(API_MSG_HDR) + sizeof(UDP_SEND_DATAGRAM_PYLD));
    unsigned int unUdpMsgId = s_unUdpMsgId;
    SET_UDP_PYLD_ID(pUDPPyldId, unUdpMsgId);
    s_unUdpMsgId++;
    memcpy(g_pucSendBuf + sizeof(API_MSG_HDR) + sizeof( UDP_SEND_DATAGRAM_PYLD ) +  sizeof(s_unUdpMsgId), 
    			m_pu8UdpPyld, m_stCfg.GetUdpPyldSize() - sizeof(s_unUdpMsgId) );
    int nBytesToSend = sizeof(API_MSG_HDR) + sizeof(UDP_SEND_DATAGRAM_PYLD) + m_stCfg.GetUdpPyldSize();
    
    //Send over serial device
    int nSentData = m_poBufferedSerialLink->Write(g_pucSendBuf, nBytesToSend);
    if(nSentData <= 0)
    {   NLOG_ERR("FAILED TO SEND UDP_SEND_DATAGRAM ON SERIAL LINK!");
        return false;
    }

	//log msg
	NLOG_INFO("Sent data: addr=%s:%d, len=%d, UDP_ID=%d", 
			GetHex(m_stCfg.GetCoordIpv6()->GetIPv6(),16), 
            m_stCfg.GetCoordIpv6()->GetPort(), 
			m_stCfg.GetUdpPyldSize(),
			unUdpMsgId);
    memset(g_aucLogBuf,0,sizeof(g_aucLogBuf));
    Bin2Hex((char*)g_aucLogBuf, sizeof(g_aucLogBuf), (char*)g_pucSendBuf + sizeof(API_MSG_HDR) + sizeof(UDP_SEND_DATAGRAM_PYLD),
            m_stCfg.GetUdpPyldSize());
    NLOG_INFO("Datagram payload: %s", g_aucLogBuf);

	//
    g_oSumiStats.AddSentNewUdpMsg(u8CurrSerialMsgId, unUdpMsgId, m_stCfg.GetUDPRespTimedoutSec());
    return true;
}
Ejemplo n.º 22
0
void mc::Terrain::OnEnter( )
{
	SetHumanPlayer( mc::Allocator::New< mc::Core::Player >( "Gracz 1", CL_Orange ) );


	mc::Core::Object* obj = Factory.CreateObject( "Vehicle" );//Factory.RandomObject( );

	for(int i = 0 ; i < 1000; )
	{
		if( Place( obj, GetHex( ds::Math::RandomInt( 0, Count ) ) ) )
		{
			obj->SetPlayer( Human );

			obj = Factory.RandomObject( );

			i++;
		}
	}

	Err << Hex[Count-1].GetCenter().X << ", " << Hex[Count-1].GetCenter().Y << Br;
}
Ejemplo n.º 23
0
CString Util::String::PHP_URLEncode( const CStringA& src )
{
	CString encodeURL;

	for(int i = 0; i < src.GetLength(); i++)
	{
		unsigned char c = src.GetAt(i);
		if (c == ' ')
		{
			encodeURL += L'+';
		}
		else if ((c < '0' && c != '-' && c != '.') ||
			(c < 'A' && c > '9') ||
			(c > 'Z' && c < 'a' && c != '_') ||
			(c > 'z'))
		{
			encodeURL += '%';
			encodeURL += GetHex((c & 0xf0) >> 4);
			encodeURL += GetHex(c & 0x0f);
		}
		else
		{
Ejemplo n.º 24
0
bool mc::Terrain::Create( ds::Size Size )
{
	Objects = mc::Allocator::NewArray< mc::Core::Object* >( OBJECT_MAX );
	ZeroMemory( Objects, sizeof( mc::Core::Object* ) * OBJECT_MAX );

	Hex = mc::Allocator::NewArray< mc::Hex >( Size.X * Size.Y );

	if( !Hex )
		return false;

	Count = Size.X * Size.Y;
	this->Size = Size;

	ds::VertexArray Verts( Count );

	for(int x = 0; x < Count; x++)
	{
		Hex[ x ].Terrain = this;
		Hex[ x ].Number = x;
		Hex[ x ].Z = ( float )ROW_TO_VEC( x ).Y / ( float )Size.Y + x / ( ( float )Size.X * 100.0f );

		Hex[ x ].Friend[ mc::FriendRightTop ] = GetHex( GetFriend( x, mc::FriendRightTop ) );
		Hex[ x ].Friend[ mc::FriendRight ] = GetHex( GetFriend( x, mc::FriendRight ) );
		Hex[ x ].Friend[ mc::FriendRightBottom ] = GetHex( GetFriend( x, mc::FriendRightBottom ) );
		Hex[ x ].Friend[ mc::FriendLeftBottom ] = GetHex( GetFriend( x, mc::FriendLeftBottom ) );
		Hex[ x ].Friend[ mc::FriendLeft ] = GetHex( GetFriend( x, mc::FriendLeft ) );
		Hex[ x ].Friend[ mc::FriendLeftTop ] = GetHex( GetFriend( x, mc::FriendLeftTop ) );

		Hex[ x ].Center = GetCenterByNumber( x );

		Verts[ x ] = ds::Vertex( Hex[ x ].Center, CL_Green );

		Hex[ x ].Center.Y *= ( float )sin( ConvertDegToRad( ISO_PROJ ) );
	}

	Dot.Create( Verts );

	//LoadHeightMap( "" );

	return true;
}
Ejemplo n.º 25
0
bool
wxPdfTokenizer::NextToken()
{
  static wxString buffer;
  buffer = wxEmptyString;
  m_stringValue = wxEmptyString;
  int ch = 0;
  do
  {
    ch = ReadChar();
  }
  while (ch != -1 && IsWhitespace(ch));

  if (ch == -1)
    return false;

  switch (ch)
  {
    case '[':
      m_type = TOKEN_START_ARRAY;
      break;
    case ']':
      m_type = TOKEN_END_ARRAY;
      break;
    case '/':
    {
      m_type = TOKEN_NAME;
      buffer += ch;
      while (true)
      {
        ch = ReadChar();
        if (IsDelimiterOrWhitespace(ch))
          break;
        buffer += ch;
      }
      BackOnePosition(ch);
      break;
    }
    case '>':
      ch = ReadChar();
      if (ch != '>')
      {
        wxLogError(_("wxPdfTokenizer::NextToken: '>' not expected."));
        return false;
      }
      m_type = TOKEN_END_DICTIONARY;
      break;
    case '<':
    {
      int v1 = ReadChar();
      if (v1 == '<')
      {
        m_type = TOKEN_START_DICTIONARY;
        break;
      }
      m_type = TOKEN_STRING;
      m_hexString = true;
      int v2 = 0;
      while (true)
      {
        while (IsWhitespace(v1))
        {
          v1 = ReadChar();
        }
        if (v1 == '>')
          break;
        v1 = GetHex(v1);
        if (v1 < 0)
          break;
        v2 = ReadChar();
        while (IsWhitespace(v2))
        {
          v2 = ReadChar();
        }
        if (v2 == '>')
        {
          ch = v1 << 4;
          buffer += ch;
          break;
        }
        v2 = GetHex(v2);
        if (v2 < 0)
          break;
        ch = (v1 << 4) + v2;
        buffer += ch;
        v1 = ReadChar();
      }
      if (v1 < 0 || v2 < 0)
      {
        wxLogError(_("wxPdfTokenizer::NextToken: Error reading string."));
        return false;
      }
      break;
    }
    case '%':
      m_type = TOKEN_COMMENT;
      do
      {
        ch = ReadChar();
      }
      while (ch != -1 && ch != '\r' && ch != '\n');
      break;
    case '(':
    {
      m_type = TOKEN_STRING;
      m_hexString = false;
      int nesting = 0;
      while (true)
      {
        ch = ReadChar();
        if (ch == -1)
          break;
        if (ch == '(')
        {
          ++nesting;
        }
        else if (ch == ')')
        {
          --nesting;
        }
        else if (ch == '\\')
        {
          bool lineBreak = false;
          ch = ReadChar();
          switch (ch)
          {
            case 'n':
              ch = '\n';
              break;
            case 'r':
              ch = '\r';
              break;
            case 't':
              ch = '\t';
              break;
            case 'b':
              ch = '\b';
              break;
            case 'f':
              ch = '\f';
              break;
            case '(':
            case ')':
            case '\\':
              break;
            case '\r':
              lineBreak = true;
              ch = ReadChar();
              if (ch != '\n')
                BackOnePosition(ch);
              break;
            case '\n':
              lineBreak = true;
              break;
            default:
            {
              if (ch < '0' || ch > '7')
              {
                break;
              }
              int octal = ch - '0';
              ch = ReadChar();
              if (ch < '0' || ch > '7')
              {
                BackOnePosition(ch);
                ch = octal;
                break;
              }
              octal = (octal << 3) + ch - '0';
              ch = ReadChar();
              if (ch < '0' || ch > '7')
              {
                BackOnePosition(ch);
                ch = octal;
                break;
              }
              octal = (octal << 3) + ch - '0';
              ch = octal & 0xff;
              break;
            }
          }
          if (lineBreak)
            continue;
          if (ch < 0)
            break;
        }
        else if (ch == '\r')
        {
          ch = ReadChar();
          if (ch < 0)
            break;
          if (ch != '\n')
          {
            BackOnePosition(ch);
            ch = '\n';
          }
        }
        if (nesting == -1)
          break;
        buffer += ch;
      }
      if (ch == -1)
      {
        wxLogError(_("wxPdfTokenizer::NextToken: Error reading string."));
        return false;
      }
      break;
    }
    default:
    {
      if (ch == '-' || ch == '+' || ch == '.' || (ch >= '0' && ch <= '9'))
      {
        m_type = TOKEN_NUMBER;
        do
        {
          buffer += ch;
          ch = ReadChar();
        }
        while (ch != -1 && ((ch >= '0' && ch <= '9') || ch == '.'));
      }
      else
      {
        m_type = TOKEN_OTHER;
        do
        {
          buffer += ch;
          ch = ReadChar();
        }
        while (!IsDelimiterOrWhitespace(ch));
      }
      BackOnePosition(ch);
      break;
    }
  }
  if (buffer != wxEmptyString)
  {
    m_stringValue.Append(buffer);
    if (m_type == TOKEN_OTHER && (m_stringValue == _T("true") || m_stringValue == _T("false")))
    {
      m_type = TOKEN_BOOLEAN;
    }
  }
  return true;
}
Ejemplo n.º 26
0
//PROCESS 
bool CSumiNodeTesterApp::ProcessRcv()
{
	//input data
	if( !m_poBufferedSerialLink->IsLinkOpen() || !m_poBufferedSerialLink->HaveData( WAITUS ) )
        return false;
		
    //check
    int nRecvLen = m_poBufferedSerialLink->Read( g_pucRcvBuf, BUFSIZE );
    if (nRecvLen <= 0)
        return false;
    if (nRecvLen < (int)sizeof(API_MSG_HDR))
    {	NLOG_ERR("FAILED TO READ MSG HEADER ON SERIAL LINK!");
        return false;
    }

    //process rsp
    API_MSG_HDR *pHdr = (API_MSG_HDR*)g_pucRcvBuf;
    if (API_GET_IS_RSP_FLAG(pHdr))
    {   switch(API_GET_MSG_CLASS(pHdr))
        {
            case API_ACK:
                NLOG_INFO("RECV ACK msg_id = %u", API_GET_MESSAGE_ID(pHdr));
                g_oSumiStats.MarkSentUdpMsgAsAcked(API_GET_MESSAGE_ID(pHdr));
                return true;

            case API_NACK:
                switch(API_GET_TYPE(pHdr))
                {
                    case API_INVALID_SIZE:
                        NLOG_ERR("RECV NACK(API_INVALID_SIZE) for msg_id = %u", API_GET_MESSAGE_ID(pHdr));
                        break;
                        
                    case API_UDP_ERR_INTERNAL:
						NLOG_INFO("RECV NACK(API_UDP_ERR_INTERNAL) for msg_id = %u", API_GET_MESSAGE_ID(pHdr));
						break;

                    case API_UDP_ERR_DEV_NOT_JOINED:
						NLOG_INFO("RECV NACK(API_UDP_ERR_DEV_NOT_JOINED) for msg_id = %u", API_GET_MESSAGE_ID(pHdr));
						break;

                    case API_UDP_ERR_INVALID_SOCKET:
						NLOG_INFO("RECV NACK(API_UDP_ERR_INVALID_SOCKET) for msg_id = %u", API_GET_MESSAGE_ID(pHdr));
						break;

                    case API_UDP_ERR_NO_MEMORY:
						NLOG_INFO("RECV NACK(API_UDP_ERR_NO_MEMORY) for msg_id = %u", API_GET_MESSAGE_ID(pHdr));
						break;

                    case API_UDP_ERR_ND_NOT_READY:
						NLOG_INFO("RECV NACK(API_UDP_ERR_ND_NOT_READY) for msg_id = %u", API_GET_MESSAGE_ID(pHdr));
						break;

                    default:
						NLOG_INFO("RECV NACK(UNKNOWN) for msg_id = %u", API_GET_MESSAGE_ID(pHdr));
						break;
                }
                g_oSumiStats.RemoveSentUdpMsg(API_GET_MESSAGE_ID(pHdr));
                return false;

            default:
                NLOG_ERR("RECV OTHER RESPONSE, MSG CLASS= %d!", API_GET_MSG_CLASS(pHdr));
                return false;
        }
    }
    
    //process request from RM
    switch(API_GET_MSG_CLASS(pHdr))
    {
        case UDP_SPECIFIC:
        {
            if (API_GET_TYPE(pHdr) != UDP_RECEIVE_DATAGRAM)
                break;

            //check for serial duplicates    
            if( g_bIsFirstDatagramRecv )
            {   g_u8RecvSerialMsgId = API_GET_MESSAGE_ID(pHdr);
                g_bIsFirstDatagramRecv = false;
            }
            else if(  API_GET_MESSAGE_ID(pHdr) == g_u8RecvSerialMsgId )
            {   NLOG_WARN("UDP_RECEIVE_DATAGRAM already read! Ignoring it...");
                return false;
            }
            else
            {   g_u8RecvSerialMsgId = API_GET_MESSAGE_ID(pHdr);
            }

            //
            UDP_RECV_DATAGRAM_PYLD* pRcvUdpDatagram = (UDP_RECV_DATAGRAM_PYLD*)((unsigned char*)pHdr + sizeof(API_MSG_HDR));
            UDP_PYLD_ID *pUDPPyldId = (UDP_PYLD_ID*)((unsigned char*)pHdr + sizeof(API_MSG_HDR) + sizeof(UDP_RECV_DATAGRAM_PYLD));
            unsigned int unUdpId = GET_UDP_PYLD_ID(pUDPPyldId);

            //log msg
            NLOG_INFO("Received data: addr=%s:%d, len=%d, UDP_ID=%d", 
                    GetHex(pRcvUdpDatagram->m_au8SrcIpv6, 16),
                    UDP_RECV_DATAGRAM_GET_SRC_PORT(pRcvUdpDatagram), 
                    nRecvLen - sizeof(API_MSG_HDR) - sizeof(UDP_RECV_DATAGRAM_PYLD),
                    unUdpId);
            memset(g_aucLogBuf,0,sizeof(g_aucLogBuf));
            Bin2Hex((char*)g_aucLogBuf, sizeof(g_aucLogBuf), (char*)pRcvUdpDatagram + sizeof(UDP_RECV_DATAGRAM_PYLD),
                    nRecvLen - sizeof(API_MSG_HDR)- sizeof(UDP_RECV_DATAGRAM_PYLD));
            NLOG_INFO("Datagram payload: %s", g_aucLogBuf);

            //
            g_oSumiStats.MarkSentUdpMsgAsResponded( unUdpId );

            //send ack
            if (!g_oUtils.SendACK(API_GET_MESSAGE_ID(pHdr), m_poBufferedSerialLink))
				return false;
        }
        break;
        
        case API_DEBUG:
        {
            if (API_GET_TYPE(pHdr) != API_PRINT_LOG)
                break;
            if( API_GET_DATA_SIZE(pHdr) >= sizeof(g_aucLogBuf) )
            {
                NLOG_ERR("LOG BUFFER TOO SMALL! Log buff=%d, API DATA SIZE=%d",
                        sizeof(g_aucLogBuf), API_GET_DATA_SIZE(pHdr));
                return false;
            }
            memcpy(g_aucLogBuf, g_pucRcvBuf + sizeof(API_MSG_HDR), API_GET_DATA_SIZE(pHdr));
            g_aucLogBuf[API_GET_DATA_SIZE(pHdr)]='\0';
            LOG("Log on dev: %s",g_aucLogBuf);
        }
        break;
        
        case STACK_SPECIFIC:
        {
            switch(API_GET_TYPE(pHdr))
            {
                case NOTIFY_JOIN:
                {
                    STACK_NOTIFY_JOIN *pNotifyJoin = (STACK_NOTIFY_JOIN*)((unsigned char*)pHdr + sizeof(API_MSG_HDR));
                    switch(pNotifyJoin->m_u8Status)
                    {
                        case MAC_IDLE_STATE:
                            NLOG_INFO("Recv NOTIFY_JOIN, status= MAC_IDLE_STATE");
                            break;
                            
                        case ENERGY_DETECT_SCANNING_STATE:
                            NLOG_INFO("Recv NOTIFY_JOIN, status= ENERGY_DETECT_SCANNING_STATE");
                            break;
                            
                        case ACTIVE_SCANNING_STATE:
                            NLOG_INFO("Recv NOTIFY_JOIN, status= ACTIVE_SCANNING_STATE");
                            break;
                            
                        case SECURITY_STATE:
                            NLOG_INFO("Recv NOTIFY_JOIN, status= SECURITY_STATE");
                            break;
                            
                        case ASSOCIATING_STATE:
                            NLOG_INFO("Recv NOTIFY_JOIN, status= ASSOCIATING_STATE");
                            break;
                            
                        case ASSOCIATED_STATE:
                            NLOG_INFO("Recv NOTIFY_JOIN, status= ASSOCIATED_STATE");
                            break;
                            
                        case ORPHAN_STATE:
                            NLOG_INFO("Recv NOTIFY_JOIN, status= ORPHAN_STATE");
                            break;
                            
                        default:
                            NLOG_WARN("Recv NOTIFY_JOIN, status = %u, UNKNOWN msg_id=%u!",
                                    pNotifyJoin->m_u8Status, API_GET_MESSAGE_ID(pHdr));
                            break;
                    }
                    //send ack
                    if (!g_oUtils.SendACK(API_GET_MESSAGE_ID(pHdr), m_poBufferedSerialLink))
						return false;
				}
                break;
                
                default:
                    NLOG_ERR("UNKNOWN STACK_SPECIFIC TYPE!");
                    break;
            }  
        }
        break;
        
        default:
            NLOG_WARN("RECV OTHER REQUEST MSG CLASS = %d", API_GET_MSG_CLASS(pHdr));
            return false;
        }
    return true;
}
Ejemplo n.º 27
0
// read from gw_ini_cmds.ini file
// initialising for target = all and when = dev_init
bool GatewayConfig::InitGwCmds()
{
    WHartUniqueID devUniqueID;
    m_oDeviceInitCmds.clear();
    m_oDeviceTargetedCmds.clear();
    CIniParser gw_commands_parser;

    if (!gw_commands_parser.Load(FILE_PATH))
    {
        return 0;
    }

    for (int i = 0; gw_commands_parser.FindGroup("command", i); i++)
    {
        char target[255];
        char when[255];
        int target_len;
        int cmd_id;
        unsigned char cmd_data[256];
        int cmd_len;
        uint8_t output[5];

        if (gw_commands_parser.GetVar(NULL, "when", when, sizeof(when)) <= 0)
            continue;

        if (strcmp(when, "dev_init") != 0)
        {
            continue;
        }

        if (gw_commands_parser.GetVar(NULL, "target", target, sizeof(target)) <= 0)
            continue;

        if (!gw_commands_parser.GetVar(NULL, "cmd_id", &cmd_id))
            continue;

        if ((cmd_len = gw_commands_parser.GetVar(NULL, "cmd_data", cmd_data, sizeof(cmd_data))) < 0)
            continue;

        if (strcmp(target, "all") == 0)
        {
            // new element in Cmds List
            CHartCmdWrapper::Ptr new_element(new CHartCmdWrapper);

            new_element->LoadRaw((uint16_t) cmd_id, cmd_len, cmd_data);
            m_oDeviceInitCmds.push_back(new_element);
        }
        else
        {
            target_len = Hex2Bin(target, (char *) output);

            if (target_len != sizeof(devUniqueID.bytes))
            {
                LOG_INFO("target=" << target << " inavlid len=" << target_len);
                continue;
            }

            memcpy(devUniqueID.bytes, output, target_len);

            CHartCmdWrapper::Ptr new_element(new CHartCmdWrapper);
            new_element->LoadRaw((uint16_t) cmd_id, cmd_len, cmd_data);

            m_oDeviceTargetedCmds[devUniqueID].push_back(new_element);
        }
        LOG(" target=%s cmdId=%d  data=%s", target, cmd_id, GetHex(cmd_data, cmd_len, ' '));

    }

    return true;
}
Ejemplo n.º 28
0
	const std::string Color::GetHexString() const
	{
		std::stringstream stream;
		stream << std::hex << GetHex();
		return stream.str();
	}
Ejemplo n.º 29
0
/**
  Function for 'mm' command.

  @param[in] ImageHandle  Handle to the Image (NULL if Internal).
  @param[in] SystemTable  Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunMm (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
  EFI_STATUS                      Status;
  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *IoDev;
  UINT64                          Address;
  UINT64                          PciEAddress;
  UINT64                          Value;
  UINT32                          SegmentNumber;
  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH                    Width;
  EFI_ACCESS_TYPE                 AccessType;
  UINT64                          Buffer;
  UINTN                           Index;
  UINTN                           Size;
//  CHAR16                          *ValueStr;
  BOOLEAN                         Complete;
  CHAR16                          *InputStr;
  BOOLEAN                         Interactive;
  EFI_HANDLE                      *HandleBuffer;
  UINTN                           BufferSize;
  UINTN                           ItemValue;
  LIST_ENTRY                      *Package;
  CHAR16                          *ProblemParam;
  SHELL_STATUS                    ShellStatus;
  CONST CHAR16                    *Temp;

  Value         = 0;
  Address       = 0;
  PciEAddress   = 0;
  IoDev         = NULL;
  HandleBuffer  = NULL;
  BufferSize    = 0;
  SegmentNumber = 0;
  ShellStatus   = SHELL_SUCCESS;
  InputStr      = NULL;

  //
  // Parse arguments
  //
  Width       = EfiPciWidthUint8;
  Size        = 1;
  AccessType  = EfiMemory;
//  ValueStr    = NULL;
  Interactive = TRUE;
  Package     = NULL;

  Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
  if (EFI_ERROR(Status)) {
    if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, ProblemParam);
      FreePool(ProblemParam);
      ShellStatus = SHELL_INVALID_PARAMETER;
      goto Done;
    } else {
      ASSERT(FALSE);
    }
  } else {
    if (ShellCommandLineGetCount(Package) < 2) {
      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle);
      ShellStatus = SHELL_INVALID_PARAMETER;
      goto Done;
    } else if (ShellCommandLineGetCount(Package) > 3) {
      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);
      ShellStatus = SHELL_INVALID_PARAMETER;
      goto Done;
    } else if (ShellCommandLineGetFlag(Package, L"-w") && ShellCommandLineGetValue(Package, L"-w") == NULL) {
      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"-w");
      ShellStatus = SHELL_INVALID_PARAMETER;
      goto Done;
    } else {
      if (ShellCommandLineGetFlag(Package, L"-mmio")) {
        AccessType = EFIMemoryMappedIo;
        if (ShellCommandLineGetFlag(Package, L"-mem")
          ||ShellCommandLineGetFlag(Package, L"-io")
          ||ShellCommandLineGetFlag(Package, L"-pci")
          ||ShellCommandLineGetFlag(Package, L"-pcie")
        ){
          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);
          ShellStatus = SHELL_INVALID_PARAMETER;
          goto Done;
        }
      } else if (ShellCommandLineGetFlag(Package, L"-mem")) {
        AccessType = EfiMemory;
        if (ShellCommandLineGetFlag(Package, L"-io")
          ||ShellCommandLineGetFlag(Package, L"-pci")
          ||ShellCommandLineGetFlag(Package, L"-pcie")
        ){
          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);
          ShellStatus = SHELL_INVALID_PARAMETER;
          goto Done;
        }
      } else if (ShellCommandLineGetFlag(Package, L"-io")) {
        AccessType = EfiIo;
        if (ShellCommandLineGetFlag(Package, L"-pci")
          ||ShellCommandLineGetFlag(Package, L"-pcie")
        ){
          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);
          ShellStatus = SHELL_INVALID_PARAMETER;
          goto Done;
        }
      } else if (ShellCommandLineGetFlag(Package, L"-pci")) {
        AccessType = EfiPciConfig;
        if (ShellCommandLineGetFlag(Package, L"-pcie")
        ){
          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);
          ShellStatus = SHELL_INVALID_PARAMETER;
          goto Done;
        }
      } else if (ShellCommandLineGetFlag(Package, L"-pcie")) {
        AccessType = EfiPciEConfig;
      }
    }

    //
    // Non interactive for a script file or for the specific parameter
    //
    if (gEfiShellProtocol->BatchIsActive() || ShellCommandLineGetFlag (Package, L"-n")) {
      Interactive = FALSE;
    }

    Temp = ShellCommandLineGetValue(Package, L"-w");
    if (Temp != NULL) {
      ItemValue = ShellStrToUintn (Temp);

      switch (ItemValue) {
      case 1:
        Width = EfiPciWidthUint8;
        Size  = 1;
        break;

      case 2:
        Width = EfiPciWidthUint16;
        Size  = 2;
        break;

      case 4:
        Width = EfiPciWidthUint32;
        Size  = 4;
        break;

      case 8:
        Width = EfiPciWidthUint64;
        Size  = 8;
        break;

      default:
        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellDebug1HiiHandle, L"-w");
        ShellStatus = SHELL_INVALID_PARAMETER;
        goto Done;
      }
    }

    Temp = ShellCommandLineGetRawValue(Package, 1);
    if (!ShellIsHexOrDecimalNumber(Temp, TRUE, FALSE) || EFI_ERROR(ShellConvertStringToUint64(Temp, (UINT64*)&Address, TRUE, FALSE))) {
      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Temp);
      ShellStatus = SHELL_INVALID_PARAMETER;
      goto Done;
    }

    Temp = ShellCommandLineGetRawValue(Package, 2);
    if (Temp != NULL) {
      //
      // Per spec if value is specified, then -n is assumed.
      //
      Interactive = FALSE;

      if (!ShellIsHexOrDecimalNumber(Temp, TRUE, FALSE) || EFI_ERROR(ShellConvertStringToUint64(Temp, &Value, TRUE, FALSE))) {
        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Temp);
        ShellStatus = SHELL_INVALID_PARAMETER;
        goto Done;
      }
      switch (Size) {
      case 1:
        if (Value > 0xFF) {
          ShellStatus = SHELL_INVALID_PARAMETER;
        }
        break;

      case 2:
        if (Value > 0xFFFF) {
          ShellStatus = SHELL_INVALID_PARAMETER;
        }
        break;

      case 4:
        if (Value > 0xFFFFFFFF) {
          ShellStatus = SHELL_INVALID_PARAMETER;
        }
        break;

      default:
        break;
      }

      if (ShellStatus != SHELL_SUCCESS) {
        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Temp);
        ShellStatus = SHELL_INVALID_PARAMETER;
        goto Done;
      }
    }

    if ((Address & (Size - 1)) != 0) {
      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_NOT_ALIGNED), gShellDebug1HiiHandle, Address);
      ShellStatus = SHELL_INVALID_PARAMETER;
      goto Done;
    }
    //
    // locate DeviceIO protocol interface
    //
    if (AccessType != EfiMemory) {
      Status = gBS->LocateHandleBuffer (
                 ByProtocol,
                 &gEfiPciRootBridgeIoProtocolGuid,
                 NULL,
                 &BufferSize,
                 &HandleBuffer
                );
      if (EFI_ERROR (Status)) {
        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PCIRBIO_NF), gShellDebug1HiiHandle);
        ShellStatus = SHELL_NOT_FOUND;
        goto Done;
      }
      //
      // In the case of PCI or PCIE
      // Get segment number and mask the segment bits in Address
      //
      if (AccessType == EfiPciEConfig) {
        SegmentNumber = (UINT32) RShiftU64 (Address, 36) & 0xff;
        Address      &= 0xfffffffffULL;
      } else {
        if (AccessType == EfiPciConfig) {
          SegmentNumber = (UINT32) RShiftU64 (Address, 32) & 0xff;
          Address      &= 0xffffffff;
        }
      }
      //
      // Find the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL of the specified segment number
      //
      for (Index = 0; Index < BufferSize; Index++) {
        Status = gBS->HandleProtocol (
                       HandleBuffer[Index],
                       &gEfiPciRootBridgeIoProtocolGuid,
                       (VOID *) &IoDev
                      );
        if (EFI_ERROR (Status)) {
          continue;
        }
        if (IoDev->SegmentNumber != SegmentNumber) {
          IoDev = NULL;
        }
      }
      if (IoDev == NULL) {
        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_SEGMENT_NOT_FOUND), gShellDebug1HiiHandle, SegmentNumber);
        ShellStatus = SHELL_INVALID_PARAMETER;
        goto Done;
      }
    }

    if (AccessType == EfiIo && Address + Size > 0x10000) {
      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_ADDRESS_RANGE), gShellDebug1HiiHandle);
      ShellStatus = SHELL_INVALID_PARAMETER;
      goto Done;
    }

    if (AccessType == EfiPciEConfig) {
      GetPciEAddressFromInputAddress (Address, &PciEAddress);
    }

    //
    // Set value
    //
    if (ShellCommandLineGetRawValue(Package, 2) != NULL) {
      if (AccessType == EFIMemoryMappedIo) {
        IoDev->Mem.Write (IoDev, Width, Address, 1, &Value);
      } else if (AccessType == EfiIo) {
        IoDev->Io.Write (IoDev, Width, Address, 1, &Value);
      } else if (AccessType == EfiPciConfig) {
        IoDev->Pci.Write (IoDev, Width, Address, 1, &Value);
      } else if (AccessType == EfiPciEConfig) {
        IoDev->Pci.Write (IoDev, Width, PciEAddress, 1, &Value);
      } else {
        WriteMem (Width, Address, 1, &Value);
      }

      ASSERT(ShellStatus == SHELL_SUCCESS);
      goto Done;
    }


    //
    // non-interactive mode
    //
    if (!Interactive) {
      Buffer = 0;
      if (AccessType == EFIMemoryMappedIo) {
        if (!gEfiShellProtocol->BatchIsActive()) {
          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_MMIO), gShellDebug1HiiHandle);
        }
        IoDev->Mem.Read (IoDev, Width, Address, 1, &Buffer);
      } else if (AccessType == EfiIo) {
        if (!gEfiShellProtocol->BatchIsActive()) {
          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_IO), gShellDebug1HiiHandle);
        }
        IoDev->Io.Read (IoDev, Width, Address, 1, &Buffer);
      } else if (AccessType == EfiPciConfig) {
        if (!gEfiShellProtocol->BatchIsActive()) {
          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_PCI), gShellDebug1HiiHandle);
        }
        IoDev->Pci.Read (IoDev, Width, Address, 1, &Buffer);
      } else if (AccessType == EfiPciEConfig) {
        if (!gEfiShellProtocol->BatchIsActive()) {
          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_PCIE), gShellDebug1HiiHandle);
        }
        IoDev->Pci.Read (IoDev, Width, PciEAddress, 1, &Buffer);
      } else {
        if (!gEfiShellProtocol->BatchIsActive()) {
          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_MEM), gShellDebug1HiiHandle);
        }
        ReadMem (Width, Address, 1, &Buffer);
      }
      if (!gEfiShellProtocol->BatchIsActive()) {
        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_ADDRESS), gShellDebug1HiiHandle, Address);
      }
      if (Size == 1) {
        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF2), gShellDebug1HiiHandle, (UINTN)Buffer);
      } else if (Size == 2) {
        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF4), gShellDebug1HiiHandle, (UINTN)Buffer);
      } else if (Size == 4) {
        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF8), gShellDebug1HiiHandle, (UINTN)Buffer);
      } else if (Size == 8) {
        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF16), gShellDebug1HiiHandle, Buffer);
      }

      ShellPrintEx(-1, -1, L"\r\n");

      ASSERT(ShellStatus == SHELL_SUCCESS);
      goto Done;
    }
    //
    // interactive mode
    //
    Complete = FALSE;
    do {
      if (AccessType == EfiIo && Address + Size > 0x10000) {
        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_ADDRESS_RANGE2), gShellDebug1HiiHandle);
        break;
      }

      Buffer = 0;
      if (AccessType == EFIMemoryMappedIo) {
        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_MMIO), gShellDebug1HiiHandle);
        IoDev->Mem.Read (IoDev, Width, Address, 1, &Buffer);
      } else if (AccessType == EfiIo) {
        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_IO), gShellDebug1HiiHandle);
        IoDev->Io.Read (IoDev, Width, Address, 1, &Buffer);
      } else if (AccessType == EfiPciConfig) {
        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_PCI), gShellDebug1HiiHandle);
        IoDev->Pci.Read (IoDev, Width, Address, 1, &Buffer);
      } else if (AccessType == EfiPciEConfig) {
        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_PCIE), gShellDebug1HiiHandle);
        IoDev->Pci.Read (IoDev, Width, PciEAddress, 1, &Buffer);
      } else {
        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_MEM), gShellDebug1HiiHandle);
        ReadMem (Width, Address, 1, &Buffer);
      }

      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_ADDRESS), gShellDebug1HiiHandle, Address);

      if (Size == 1) {
        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF2), gShellDebug1HiiHandle, (UINTN)Buffer);
      } else if (Size == 2) {
        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF4), gShellDebug1HiiHandle, (UINTN)Buffer);
      } else if (Size == 4) {
        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF8), gShellDebug1HiiHandle, (UINTN)Buffer);
      } else if (Size == 8) {
        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF16), gShellDebug1HiiHandle, Buffer);
      }
      ShellPrintEx(-1, -1, L" > ");
      //
      // wait user input to modify
      //
      if (InputStr != NULL) {
        FreePool(InputStr);
        InputStr = NULL;
      }
      ShellPromptForResponse(ShellPromptResponseTypeFreeform, NULL, (VOID**)&InputStr);

      //
      // skip space characters
      //
      for (Index = 0; InputStr != NULL && InputStr[Index] == ' '; Index++);

      //
      // parse input string
      //
      if (InputStr != NULL && (InputStr[Index] == '.' || InputStr[Index] == 'q' || InputStr[Index] == 'Q')) {
        Complete = TRUE;
      } else if (InputStr == NULL || InputStr[Index] == CHAR_NULL) {
        //
        // Continue to next address
        //
      } else if (GetHex (InputStr + Index, &Buffer) && Buffer <= MaxNum[Width]) {
        if (AccessType == EFIMemoryMappedIo) {
          IoDev->Mem.Write (IoDev, Width, Address, 1, &Buffer);
        } else if (AccessType == EfiIo) {
          IoDev->Io.Write (IoDev, Width, Address, 1, &Buffer);
        } else if (AccessType == EfiPciConfig) {
          IoDev->Pci.Write (IoDev, Width, Address, 1, &Buffer);
        } else if (AccessType == EfiPciEConfig) {
          IoDev->Pci.Write (IoDev, Width, PciEAddress, 1, &Buffer);
        } else {
          WriteMem (Width, Address, 1, &Buffer);
        }
      } else {
        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_ERROR), gShellDebug1HiiHandle);
        continue;
  //      PrintToken (STRING_TOKEN (STR_IOMOD_ERROR), HiiHandle);
      }

      Address += Size;
      if (AccessType == EfiPciEConfig) {
        GetPciEAddressFromInputAddress (Address, &PciEAddress);
      }
      ShellPrintEx(-1, -1, L"\r\n");
  //    Print (L"\n");
    } while (!Complete);
  }
  ASSERT(ShellStatus == SHELL_SUCCESS);
Done:

  if (InputStr != NULL) {
    FreePool(InputStr);
  }
  if (HandleBuffer != NULL) {
    FreePool (HandleBuffer);
  }
  if (Package != NULL) {
    ShellCommandLineFreeVarList (Package);
  }
  return ShellStatus;
}
Ejemplo n.º 30
0
std::string base_blob<BITS>::ToString() const
{
    return (GetHex());
}