Exemple #1
0
UCHAR _FillIPAddr(PCHAR pBuf, PCHAR pIPAddr, UCHAR iOpCode)
{
	pBuf[0] = iOpCode;
	pBuf[1] = IP_ALEN;
	memcpy4((PCHAR)(pBuf + 2), pIPAddr);
	return (UCHAR)(2 + IP_ALEN);
}
Exemple #2
0
void RtpSendVoice(SIP_LCB_HANDLE pLcb, UCHAR iFrame1, PCHAR pBuf1, UCHAR iFrame2, PCHAR pBuf2)
{
	PCHAR pDst;
	USHORT sLen;

	if (!iFrame1 && !iFrame2)
	{
		// Send 0 length UDP packet to keep RTP NAT alive, do NOT work with Asterisk and TPLINK router!
//		UdpSendTo(pLcb->pRtpSocket, 0, pLcb->pRtpDstIP, pLcb->sRtpDstPort);
//		UdpDebugString("send empty udp packet");
		return;
	}

	pLcb->lRtpTimeStamp = rl_32x8((Sys_lTicker - pLcb->lRtpOffset), 3);

	pDst = Adapter_pUdpBuf;
	pDst[RTP_VERSION] = 0x80;
	memcpy4((PCHAR)(pDst+RTP_SSRC), pLcb->pRtpSSRC);
	USHORT2PCHAR(pLcb->sRtpSeq, (PCHAR)(pDst+RTP_SEQ));
	ULONG2PCHAR(pLcb->lRtpTimeStamp, (PCHAR)(pDst+RTP_TIMESTAMP));
	pDst[RTP_PAYLOAD] = RtpGetPayload(pLcb->iVoiceCoder, pLcb);
	if (pLcb->bVoiceStart)
	{
		pDst[RTP_PAYLOAD] |= 0x80;
		pLcb->bVoiceStart = FALSE;
	}

	sLen = rtp_add_voice(Rtp_pData, iFrame1, pBuf1);
	sLen += rtp_add_voice((PCHAR)(Rtp_pData + sLen), iFrame2, pBuf2);
	if (sLen)
	{
#ifdef OEM_IP20
#ifdef __ADSL
		if (pLcb->brtpIpPrivate == FALSE && pLcb->brtpSession == 1)
		{
			pLcb->brtpSession = 2;
		}
		if (pLcb->brtpIpPrivate == FALSE)
		{
			if (Sip_pCurLcb->brtpSession)//rtp packet received from destination
			{
				UdpSendTo(pLcb->pRtpSocket, sLen + RTP_DATA, pLcb->pRtpDstIP, pLcb->sRtpDstPort);
			}
		}
		else
		{
			UdpSendTo(pLcb->pRtpSocket, sLen + RTP_DATA, pLcb->pRtpDstIP, pLcb->sRtpDstPort);
		}
#else		
		UdpSendTo(pLcb->pRtpSocket, sLen + RTP_DATA, pLcb->pRtpDstIP, pLcb->sRtpDstPort);
#endif

#else
		UdpSendTo(pLcb->pRtpSocket, sLen + RTP_DATA, pLcb->pRtpDstIP, pLcb->sRtpDstPort);
#endif
		pLcb->sRtpSeq ++;
	}
}
Exemple #3
0
static inline void stm32_otg_tx(EXO* exo, int num)
{
    EP* ep = exo->usb.in[USB_EP_NUM(num)];

    int size = ep->io->data_size - ep->size;
    if (size > ep->mps)
        size = ep->mps;
    OTG_FS_DEVICE->INEP[USB_EP_NUM(num)].TSIZ = (1 << OTG_FS_DEVICE_ENDPOINT_TSIZ_PKTCNT_POS) | (size << OTG_FS_DEVICE_ENDPOINT_TSIZ_XFRSIZ_POS);
    OTG_FS_DEVICE->INEP[USB_EP_NUM(num)].CTL |= OTG_FS_DEVICE_ENDPOINT_CTL_EPENA | OTG_FS_DEVICE_ENDPOINT_CTL_CNAK;

    memcpy4((void*)(OTG_FS_FIFO_BASE + USB_EP_NUM(num) * 0x1000), io_data(ep->io) +  ep->size, size);
    ep->size += size;
}
Exemple #4
0
void init_arm()
{
    int i;

    *(volatile unsigned int *)(0xa05f6934) = 0x00000002;

    //TODO: Providing your own ARM code as an argument might be nice.
    *((volatile unsigned long *)(void *)0xa0702c00) |= 1;
    memset4((void*)0xa0800000, 0, 2*1024*1024);
    memcpy4((void*)0xa0800000, arm_sound_code, sizeof(arm_sound_code));
    *((volatile unsigned long *)(void *)0xa0702c00) &= ~1;
    //FIXME: Some sort of sleep here would be cleaner...
    for(i=0; i<0x200000; i++);
}
Exemple #5
0
void _SendPacket(UCHAR iOptionsLen)
{
	USHORT sLength;
	PCHAR pBuf;

	pBuf = Adapter_pUdpBuf;

	memcpy4(pBuf, _cPacketHead);
	memcpy4((PCHAR)(pBuf+DHCP_XID), _pDhcpXID);
	memset((PCHAR)(pBuf+DHCP_SECS), 0, DHCP_SECS_LEN);
	memset((PCHAR)(pBuf+DHCP_YIADDR), 0, DHCP_OPTIONS - DHCP_YIADDR);
	memcpy((PCHAR)(pBuf+DHCP_CHADDR), Sys_pMacAddress, HW_ALEN);
	memcpy4((PCHAR)(pBuf+DHCP_OPTIONS), _cMagicCookie);

	sLength = iOptionsLen;
	sLength += DHCP_OPLIST;
	if (sLength < DHCP_MIN_PACKET_SIZE)
	{
		memset((PCHAR)(pBuf + sLength), 0, (UCHAR)(DHCP_MIN_PACKET_SIZE - sLength));
		sLength = DHCP_MIN_PACKET_SIZE;
	}

	UdpSendTo(_pDhcpSocket, sLength, (_iDhcpState == DHCP_STATE_RENEWING) ? _pDhcpServerIP : (PCHAR)_pBroadcastIP, DHCP_SERVER_PORT);
}
Exemple #6
0
void _DhcpReqRenew()
{
	UCHAR iLen;
	PCHAR pOptions;
	PCHAR pBuf;

	pBuf = Adapter_pUdpBuf;
	pOptions = (PCHAR)(pBuf + DHCP_OPLIST);
	iLen = _FillMsgType(pOptions, DHCP_MTYPE_REQUEST);
	iLen += _FillClientId((PCHAR)(pOptions + iLen));
	iLen += _FillParamList((PCHAR)(pOptions + iLen));
	iLen += _FillMaxSize((PCHAR)(pOptions + iLen));
	pOptions[iLen] = DHCP_OPCODE_END;
	iLen ++;
	// set flags and ciaddr
//	pBuf[DHCP_FLAGS] = 0;
//	pBuf[DHCP_FLAGS+1] = 0;
	USHORT2PCHAR(0, (PCHAR)(pBuf + DHCP_FLAGS));
	memcpy4((PCHAR)(pBuf + DHCP_CIADDR), Sys_pIpAddress);

	_SendPacket(iLen);
}
Exemple #7
0
bool ronin_init()
{
    memset(dc_screen, 0, sizeof(dc_screen));
    
    vram = (uint16_t *)dc_screen;
    
    *(volatile unsigned int*)(0xa05f80e4) = SCREEN_WIDTH >> 5; //for stride
    
    for (int i=0; i<SCREEN_BUFFER_SIZE; i++)
	    screen_tx[i] = ta_txalloc(VRAM_SIZE);

#ifdef USE_ARM
	memcpy4((void*)0xa0800000+EXPANSION_BASE_ADDR, arm_pxt_code, sizeof(arm_pxt_code));
#endif


#ifdef __SDCARD__
	sd_init();
#endif

    return 0;
}
Exemple #8
0
//------------------------------------------------------------------------
static inline void stm32_otg_on_isr_rx(EXO* exo)
{
    IPC ipc;
    unsigned int sta = OTG_FS_GENERAL->RXSTSP;
    unsigned int pktsts = sta & OTG_FS_GENERAL_RXSTSR_PKTSTS;
    int bcnt = (sta & OTG_FS_GENERAL_RXSTSR_BCNT) >> OTG_FS_GENERAL_RXSTSR_BCNT_POS;
    unsigned int ep_num = (sta & OTG_FS_GENERAL_RXSTSR_EPNUM) >> OTG_FS_GENERAL_RXSTSR_EPNUM_POS;
    EP* ep = exo->usb.out[ep_num];
    if (pktsts == OTG_FS_GENERAL_RXSTSR_PKTSTS_SETUP_RX)
    {
//ignore all data on setup packet
        exo->usb.setup_lo = ((uint32_t*)(OTG_FS_FIFO_BASE + ep_num * 0x1000))[0];
        exo->usb.setup_hi = ((uint32_t*)(OTG_FS_FIFO_BASE + ep_num * 0x1000))[1];
    }
    else  if ((pktsts == OTG_FS_GENERAL_RXSTSR_PKTSTS_SETUP_DONE))
    {
        ipc.process = exo->usb.device;
        ipc.cmd = HAL_CMD(HAL_USB, USB_SETUP);
        ipc.param1 = USB_HANDLE(USB_0, 0);
        ipc.param2 = exo->usb.setup_lo;
        ipc.param3 = exo->usb.setup_hi;
        ipc_ipost(&ipc);
    }
    else  if ((pktsts == OTG_FS_GENERAL_RXSTSR_PKTSTS_OUT_RX) && bcnt)
    {
        memcpy4(io_data(ep->io) + ep->io->data_size, (void*)(OTG_FS_FIFO_BASE + ep_num * 0x1000), bcnt);
        ep->io->data_size += bcnt;

        if (ep->io->data_size >= ep->size || bcnt < ep->mps )
        {
          iio_complete(exo->usb.device, HAL_IO_CMD(HAL_USB, IPC_READ), ep_num, ep->io);
            ep->io_active = false;
            ep->io = NULL;
        }
        else
            stm32_otg_rx_prepare(exo, ep_num);
    }
    OTG_FS_GENERAL->INTMSK |= OTG_FS_GENERAL_INTMSK_RXFLVLM;
}
Exemple #9
0
void RtpSendKeyPacket(SIP_LCB_HANDLE pLcb, BOOLEAN bHead, BOOLEAN bEnd)
{
	PCHAR pDst;

	pDst = Adapter_pUdpBuf;

	pDst[RTP_VERSION] = 0x80;
	memcpy4((PCHAR)(pDst+RTP_SSRC), pLcb->pRtpSSRC);
	USHORT2PCHAR(pLcb->sRtpSeq, (PCHAR)(pDst+RTP_SEQ));
	pLcb->sRtpSeq ++;
	ULONG2PCHAR(pLcb->lRtpTimeStamp, (PCHAR)(pDst+RTP_TIMESTAMP));
	pDst[RTP_PAYLOAD] = Sys_iDtmfPayload;
	if (bHead)
	{
		pDst[RTP_PAYLOAD] |= 0x80;
	}

	Rtp_pData[0] = pLcb->iSendKey;
	Rtp_pData[1] = bEnd ? 0x80 : 0x00;
	USHORT2PCHAR(pLcb->sSendKeyLen, (PCHAR)(Rtp_pData + 2));

	UdpSendTo(pLcb->pRtpSocket, (USHORT)(RTP_DATA + 4), pLcb->pRtpDstIP, pLcb->sRtpDstPort);
}	
Exemple #10
0
void _DhcpDone()
{
	memcpy4(Sys_pIpAddress, _pAssignedIP); 
	_DhcpAck();
	TaskUIHandler(UI_NET_CONNECTED, 0);
}
Exemple #11
0
UCHAR _FillMaxSize(PCHAR pBuf)
{
	memcpy4(pBuf, _cMaxSize);
	return (UCHAR)MAX_SIZE_LEN;
}
Exemple #12
0
static void
write_decimal (st_parameter_dt *dtp, const fnode *f, const char *source,
	       int len,
               const char *(*conv) (GFC_INTEGER_LARGEST, char *, size_t))
{
  GFC_INTEGER_LARGEST n = 0;
  int w, m, digits, nsign, nzero, nblank;
  char *p;
  const char *q;
  sign_t sign;
  char itoa_buf[GFC_BTOA_BUF_SIZE];

  w = f->u.integer.w;
  m = f->format == FMT_G ? -1 : f->u.integer.m;

  n = extract_int (source, len);

  /* Special case:  */
  if (m == 0 && n == 0)
    {
      if (w == 0)
        w = 1;

      p = write_block (dtp, w);
      if (p == NULL)
        return;
      if (unlikely (is_char4_unit (dtp)))
	{
	  gfc_char4_t *p4 = (gfc_char4_t *) p;
	  memset4 (p4, ' ', w);
	}
      else
	memset (p, ' ', w);
      goto done;
    }

  sign = calculate_sign (dtp, n < 0);
  if (n < 0)
    n = -n;
  nsign = sign == S_NONE ? 0 : 1;
  
  /* conv calls itoa which sets the negative sign needed
     by write_integer. The sign '+' or '-' is set below based on sign
     calculated above, so we just point past the sign in the string
     before proceeding to avoid double signs in corner cases.
     (see PR38504)  */
  q = conv (n, itoa_buf, sizeof (itoa_buf));
  if (*q == '-')
    q++;

  digits = strlen (q);

  /* Select a width if none was specified.  The idea here is to always
     print something.  */

  if (w == 0)
    w = ((digits < m) ? m : digits) + nsign;

  p = write_block (dtp, w);
  if (p == NULL)
    return;

  nzero = 0;
  if (digits < m)
    nzero = m - digits;

  /* See if things will work.  */

  nblank = w - (nsign + nzero + digits);

  if (unlikely (is_char4_unit (dtp)))
    {
      gfc_char4_t * p4 = (gfc_char4_t *) p;
      if (nblank < 0)
	{
	  memset4 (p4, '*', w);
	  goto done;
	}

      memset4 (p4, ' ', nblank);
      p4 += nblank;

      switch (sign)
	{
	case S_PLUS:
	  *p4++ = '+';
	  break;
	case S_MINUS:
	  *p4++ = '-';
	  break;
	case S_NONE:
	  break;
	}

      memset4 (p4, '0', nzero);
      p4 += nzero;

      memcpy4 (p4, q, digits);
      return;
    }

  if (nblank < 0)
    {
      star_fill (p, w);
      goto done;
    }

  memset (p, ' ', nblank);
  p += nblank;

  switch (sign)
    {
    case S_PLUS:
      *p++ = '+';
      break;
    case S_MINUS:
      *p++ = '-';
      break;
    case S_NONE:
      break;
    }

  memset (p, '0', nzero);
  p += nzero;

  memcpy (p, q, digits);

 done:
  return;
}
Exemple #13
0
void
write_a (st_parameter_dt *dtp, const fnode *f, const char *source, int len)
{
  int wlen;
  char *p;

  wlen = f->u.string.length < 0
	 || (f->format == FMT_G && f->u.string.length == 0)
	 ? len : f->u.string.length;

#ifdef HAVE_CRLF
  /* If this is formatted STREAM IO convert any embedded line feed characters
     to CR_LF on systems that use that sequence for newlines.  See F2003
     Standard sections 10.6.3 and 9.9 for further information.  */
  if (is_stream_io (dtp))
    {
      const char crlf[] = "\r\n";
      int i, q, bytes;
      q = bytes = 0;

      /* Write out any padding if needed.  */
      if (len < wlen)
	{
	  p = write_block (dtp, wlen - len);
	  if (p == NULL)
	    return;
	  memset (p, ' ', wlen - len);
	}

      /* Scan the source string looking for '\n' and convert it if found.  */
      for (i = 0; i < wlen; i++)
	{
	  if (source[i] == '\n')
	    {
	      /* Write out the previously scanned characters in the string.  */
	      if (bytes > 0)
		{
		  p = write_block (dtp, bytes);
		  if (p == NULL)
		    return;
		  memcpy (p, &source[q], bytes);
		  q += bytes;
		  bytes = 0;
		}

	      /* Write out the CR_LF sequence.  */ 
	      q++;
	      p = write_block (dtp, 2);
              if (p == NULL)
                return;
	      memcpy (p, crlf, 2);
	    }
	  else
	    bytes++;
	}

      /*  Write out any remaining bytes if no LF was found.  */
      if (bytes > 0)
	{
	  p = write_block (dtp, bytes);
	  if (p == NULL)
	    return;
	  memcpy (p, &source[q], bytes);
	}
    }
  else
    {
#endif
      p = write_block (dtp, wlen);
      if (p == NULL)
	return;

      if (unlikely (is_char4_unit (dtp)))
	{
	  gfc_char4_t *p4 = (gfc_char4_t *) p;
	  if (wlen < len)
	    memcpy4 (p4, source, wlen);
	  else
	    {
	      memset4 (p4, ' ', wlen - len);
	      memcpy4 (p4 + wlen - len, source, len);
	    }
	  return;
	}

      if (wlen < len)
	memcpy (p, source, wlen);
      else
	{
	  memset (p, ' ', wlen - len);
	  memcpy (p + wlen - len, source, len);
	}
#ifdef HAVE_CRLF
    }
#endif
}
Exemple #14
0
void DnsRun(UDP_SOCKET pUcb)
{
	UCHAR i, iBankOffset;
	USHORT sAnCount, sQdCount, sLength, sAnswerType, sAddr;
	UCHAR pSrvDomain[MAX_DNS_LEN];
	DNS_HANDLE pDcb;
	DNS_HANDLE pTempDcb;
	PCHAR pDnsIp;
	PCHAR pBuf;
	PT_DNSSRV_ANS ptAns;

	if (pUcb != _pDnsSocket)	return;

	pBuf = Adapter_pUdpBuf;

	pDcb = NULL;
	pTempDcb = _pDcbData;
	for (i = 0; i < DNS_CB_TSIZE; i ++)
	{
		if (!memcmp(pTempDcb->pID, pBuf, DNS_ID_LEN))
		{
			pDcb = pTempDcb;
			break;
		}
		pTempDcb ++;
	}
	if (pDcb == NULL)
	{
		// transaction id mismatch, this response is not what we need
		return;
	}
	if (pDcb->iState == DS_RESOLVED)
	{
		// this is a retransmission which has already been handled, ignore it
		return;
	}

	iBankOffset = pDcb->iBankOffset;
	sAddr = pDcb->sCallBack;
	if (!sAddr)		return;

	pDnsIp = UdpGetDstIP(pUcb);
	sAnCount = PCHAR2USHORT((PCHAR)(pBuf + DNS_HEADER_ANCOUNT));
	if ((pBuf[DNS_HEADER_FALG1] & DNS_MASK_RCODE) != DNS_RCODE_NOERROR || sAnCount == 0)
	{
		_DnsCheckSeconday(pDcb, pDnsIp);
		return;
	}

	/* pass the question section */
	sLength = DNS_HEADER_DATA;
	sQdCount = PCHAR2USHORT((PCHAR)(pBuf + DNS_HEADER_QDCOUNT));
	for (i = 0; i < sQdCount; i ++)
	{
		sLength += _GetNameLength((PCHAR)(pBuf + sLength));
		sLength += 4;
	}
	if (sLength > pUcb->sLen)	
	{
		_DnsCheckSeconday(pDcb, pDnsIp);
		return;
	}

	/* handle the answer section */
	if (!_DnsAllocAns(pDcb, sAnCount))
	{
		dns_failed(pDcb->sCallBack, pDcb->iBankOffset);
		dns_dealloc(pDcb);
		return;
	}
	for (i = 0; i < sAnCount, sLength < pUcb->sLen; i ++)
	{
		sLength += _GetNameLength((PCHAR)(pBuf + sLength));
		sAnswerType = PCHAR2USHORT((PCHAR)(pBuf + sLength + DNS_RR_TYPE));
		if (sAnswerType == pDcb->iType)
		{
			// set the cache time out
			if (PCHAR2USHORT((PCHAR)(pBuf+sLength+DNS_RR_TTL)))
			{
				pDcb->iTimer = 255;
				pDcb->iRetry = 255;
			}
			else
			{
				pDcb->iTimer = pBuf[sLength+DNS_RR_TTL+3];
				pDcb->iRetry = pBuf[sLength+DNS_RR_TTL+2];
			}
			if (sAnswerType == DNS_TYPE_A)
			{
				pDcb->iState = DS_RESOLVED;
				memcpy4(pDcb->pAnswer, (PCHAR)(pBuf + sLength + DNS_RR_RDATA));
				break;
			}
			else if (sAnswerType == DNS_TYPE_SRV)
			{
				_GetDomainName(pSrvDomain, (PCHAR)(pBuf + sLength + DNS_RR_RDATA + 6), pBuf);
				if (strcmp(pSrvDomain, "."))
				{
					pDcb->iState = DS_RESOLVED;
					ptAns = (PT_DNSSRV_ANS)(pDcb->pAnswer + 1);
					ptAns += pDcb->pAnswer[0];
					strcpy(ptAns->pcTarget, pSrvDomain);
					ptAns->sPort = PCHAR2USHORT((PCHAR)(pBuf + sLength + DNS_RR_RDATA + 4));
					ptAns->sPriority = PCHAR2USHORT((PCHAR)(pBuf + sLength + DNS_RR_RDATA + 0));
			//		UdpDebugVal(PCHAR2USHORT((PCHAR)(pBuf + sLength + DNS_RR_RDATA + 0)),10);	//fv show Priority
			//		UdpDebugVal(PCHAR2USHORT((PCHAR)(pBuf + sLength + DNS_RR_RDATA + 2)),10);	//fv show weight
					pDcb->pAnswer[0] ++;
				}
			}
		}
		sLength += DNS_RR_RDATA + PCHAR2USHORT((PCHAR)(pBuf + sLength + DNS_RR_RDLENGTH));
	}

	if (pDcb->iState == DS_RESOLVED)
	{
		TaskDnsDone(pDcb->pAnswer, pDcb->sCallBack, pDcb->iBankOffset);
	}
	else
	{
		_DnsDeleteAns(pDcb);
		_DnsCheckSeconday(pDcb, pDnsIp);
	}
}
Exemple #15
0
void DhcpRun(UDP_SOCKET pUcb)
{
	UCHAR iLength, iType, iMsgType;
	PCHAR pOption;
	PCHAR pBuf;
	USHORT sIndex;
	UCHAR pServerID[IP_ALEN];
	UCHAR pSubnetMask[IP_ALEN];
	UCHAR pRouteIP[IP_ALEN];
	UCHAR pDnsIP[IP_ALEN];
	UCHAR pDnsIP2[IP_ALEN];
	BOOLEAN bDns2;
	ULONG lLeaseTime, lT1, lT2;
#ifdef OEM_INNOMEDIA
	BOOLEAN bHasProvUrl;
#endif

	if (pUcb != _pDhcpSocket)	return;

	pBuf = Adapter_pUdpBuf;

	if (_iDhcpState == DHCP_STATE_CHECKING || 
		pBuf[DHCP_OP] != DHCP_OP_REPLY || 
		memcmp((PCHAR)(pBuf + DHCP_XID), _pDhcpXID, DHCP_XID_LEN) ||
		memcmp((PCHAR)(pBuf + DHCP_CHADDR), Sys_pMacAddress, HW_ALEN))
	{
		return;
	}

	if (_iDhcpState == DHCP_STATE_REQUESTING || _iDhcpState == DHCP_STATE_RENEWING)
	{
//		if (memcmp(_pDhcpServerIP, (IsValidIP((PCHAR)(pBuf + DHCP_GIADDR))) ? (PCHAR)(pBuf + DHCP_GIADDR) : UdpGetDstIP(pUcb), IP_ALEN))
		if (memcmp(_pDhcpServerIP, UdpGetDstIP(pUcb), IP_ALEN))
		{
			return;
		}
	}

#ifdef OEM_INNOMEDIA
	bHasProvUrl = FALSE;
#endif
	sIndex = DHCP_OPLIST;
	lT1 = 0;
	lT2 = 0;
	bDns2 = FALSE;
	iMsgType = DHCP_MTYPE_NONE;
	lLeaseTime = 0;
	while (sIndex < pUcb->sLen)
	{
		iType = pBuf[sIndex];
		if (iType == DHCP_OPCODE_END)
		{
			break;
		}
		if (iType == DHCP_OPCODE_PADDING)
		{
			sIndex ++;
			continue;
		}
		else
		{
			iLength = pBuf[sIndex+1];
		}
		sIndex += 2;
		pOption = (PCHAR)(pBuf + sIndex);
		switch (iType)
		{
		case DHCP_OPCODE_MESSAGE_TYPE:
			iMsgType = pOption[0];
			break;
/*		sometimes server ID is not the same as the server IP address */
		case DHCP_OPCODE_SERVER_ID:
			memcpy4(pServerID, pOption);
			break;

		case DHCP_OPCODE_SUBNET_MASK:
			memcpy4(pSubnetMask, pOption);
			break;

		case DHCP_OPCODE_ROUTER_IP:
			memcpy4(pRouteIP, pOption);
			break;

		case DHCP_OPCODE_DNS_IP:
			memcpy4(pDnsIP, pOption);
			if (iLength > IP_ALEN)
			{
				memcpy4(pDnsIP2, (PCHAR)(pOption+IP_ALEN));
				bDns2 = TRUE;
			}
			break;

		case DHCP_OPCODE_LEASE_TIME:
			lLeaseTime = PCHAR2ULONG(pOption);
			if (!lT1)	lT1 = rr_32x8(lLeaseTime, 1);
			if (!lT2)	lT2 = lLeaseTime - rr_32x8(lLeaseTime, 3);
			break;

		case DHCP_OPCODE_MESSAGE:
			break;

		case DHCP_OPCODE_RENEWAL_TIME:
			lT1 = PCHAR2ULONG(pOption);
			break;

		case DHCP_OPCODE_REBIND_TIME:
			lT2 = PCHAR2ULONG(pOption);
			break;
#ifdef OEM_INNOMEDIA
		case DHCP_OPCODE_TFTP_SERVER:
			if (iLength > 7 && !memcmp_str(pOption, "http://"))
			{
				iLength -= 7;
				pOption += 7;
				if (Sys_pProvUrl)
				{
					free(Sys_pProvUrl);
				}
				Sys_pProvUrl = (PCHAR)malloc(iLength + 1);
				memcpy(Sys_pProvUrl, pOption, iLength);
				Sys_pProvUrl[iLength] = 0;
				bHasProvUrl = TRUE;
			}
			break;
#endif
		default:
			// other reserved options are in pOption, iType, sLen
			break;
		}
		sIndex += iLength;
	}

	// Respond message
	switch (_iDhcpState)
	{
	case DHCP_STATE_SELECTING:
		if (iMsgType == DHCP_MTYPE_OFFER)
		{
#ifdef OEM_INNOMEDIA
			if (bHasProvUrl)
#endif
			{
				_iDhcpState = DHCP_STATE_REQUESTING;
				_iDhcpRetry = 0;
				memcpy4(_pAssignedIP, (PCHAR)(pBuf + DHCP_YIADDR));
				memcpy4(_pDhcpServerID, pServerID);
				memcpy4(_pDhcpServerIP, UdpGetDstIP(pUcb));
				_DhcpRequest();
			}
		}
		break;

	case DHCP_STATE_REQUESTING:
		if (iMsgType == DHCP_MTYPE_ACK)
		{
			memcpy4(_pAssignedIP, (PCHAR)(pBuf + DHCP_YIADDR));
			memcpy4(Sys_pSubnetMask, pSubnetMask);
			memcpy4(Sys_pRouterIp, pRouteIP);
			if (OptionsGetByte(OPT_DNS_TYPE))
			{
				memcpy4(Sys_pDnsIp, pDnsIP);
				if (bDns2)
				{
					memcpy4(Sys_pDnsIp2, pDnsIP2);
				}
				else
				{
					memset(Sys_pDnsIp2, 0, IP_ALEN);
				}
			}
			_lLeaseTime = lLeaseTime;
			_lT1 = lT1;
			_lT2 = lT2;

			// for now, escape IP checking first
			_DhcpDone();
		}
		else if (iMsgType == DHCP_MTYPE_NACK)
		{
			_DhcpNack();
		}
		break;

	case DHCP_STATE_RENEWING:
	case DHCP_STATE_REBINDING:
		if (iMsgType == DHCP_MTYPE_ACK)
		{
			_lLeaseTime = lLeaseTime;
			_lT1 = lT1;
			_lT2 = lT2;
			_DhcpAck();
		}
		else if (iMsgType == DHCP_MTYPE_NACK)
		{
			_DhcpNack();
		}
		break;
	}
}
Exemple #16
0
static void
write_boz (st_parameter_dt *dtp, const fnode *f, const char *q, int n)
{
  int w, m, digits, nzero, nblank;
  char *p;

  w = f->u.integer.w;
  m = f->u.integer.m;

  /* Special case:  */

  if (m == 0 && n == 0)
    {
      if (w == 0)
        w = 1;

      p = write_block (dtp, w);
      if (p == NULL)
        return;
      if (unlikely (is_char4_unit (dtp)))
	{
	  gfc_char4_t *p4 = (gfc_char4_t *) p;
	  memset4 (p4, ' ', w);
	}
      else
	memset (p, ' ', w);
      goto done;
    }

  digits = strlen (q);

  /* Select a width if none was specified.  The idea here is to always
     print something.  */

  if (w == 0)
    w = ((digits < m) ? m : digits);

  p = write_block (dtp, w);
  if (p == NULL)
    return;

  nzero = 0;
  if (digits < m)
    nzero = m - digits;

  /* See if things will work.  */

  nblank = w - (nzero + digits);

  if (unlikely (is_char4_unit (dtp)))
    {
      gfc_char4_t *p4 = (gfc_char4_t *) p;
      if (nblank < 0)
	{
	  memset4 (p4, '*', w);
	  return;
	}

      if (!dtp->u.p.no_leading_blank)
	{
	  memset4 (p4, ' ', nblank);
	  q += nblank;
	  memset4 (p4, '0', nzero);
	  q += nzero;
	  memcpy4 (p4, q, digits);
	}
      else
	{
	  memset4 (p4, '0', nzero);
	  q += nzero;
	  memcpy4 (p4, q, digits);
	  q += digits;
	  memset4 (p4, ' ', nblank);
	  dtp->u.p.no_leading_blank = 0;
	}
      return;
    }

  if (nblank < 0)
    {
      star_fill (p, w);
      goto done;
    }

  if (!dtp->u.p.no_leading_blank)
    {
      memset (p, ' ', nblank);
      p += nblank;
      memset (p, '0', nzero);
      p += nzero;
      memcpy (p, q, digits);
    }
  else
    {
      memset (p, '0', nzero);
      p += nzero;
      memcpy (p, q, digits);
      p += digits;
      memset (p, ' ', nblank);
      dtp->u.p.no_leading_blank = 0;
    }

 done:
  return;
}
Exemple #17
0
void DhcpdRun(UDP_SOCKET pUcb)
{
	PCHAR pSendBuf;
	PCHAR pBuf;
	PCHAR pOptions;
	UCHAR iMsgType, iType, iLen;
	USHORT sIndex;

	if (pUcb != Dhcpd_pSocket)
	{
		return;
	}

	pBuf = Adapter_pUdpBuf;

	if (pBuf[DHCP_OP] != DHCP_OP_REQUEST)
	{
		return;
	}
	sIndex = DHCP_OPLIST;
	iMsgType = DHCP_MTYPE_NONE;
	while (sIndex < pUcb->sLen)
	{
		iType = pBuf[sIndex];
		if (iType == DHCP_OPCODE_END)
		{
			break;
		}
		if (iType == DHCP_OPCODE_PADDING)
		{
			sIndex ++;
			continue;
		}
		else
		{
			iLen = pBuf[sIndex+1];
		}
		sIndex += 2;
		pOptions = (PCHAR)(pBuf + sIndex);
		if (iType == DHCP_OPCODE_MESSAGE_TYPE)
		{
			iMsgType = pOptions[0];
			break;
		}
		sIndex += iLen;
	}
	
	if (iMsgType == DHCP_MTYPE_NONE)
	{
		return;
	}

	pSendBuf = pBuf;
	pOptions = (PCHAR)(pSendBuf + DHCP_OPLIST);
	iLen = _FillMsgType(pOptions, (iMsgType == DHCP_MTYPE_DISCOVER) ? DHCP_MTYPE_OFFER : DHCP_MTYPE_ACK);
	iLen += _FillLeaseTime((PCHAR)(pOptions + iLen), 86400);
	iLen += _FillIPAddr((PCHAR)(pOptions + iLen), Sys_pSubnetMask, DHCP_OPCODE_SUBNET_MASK);
	iLen += _FillIPAddr((PCHAR)(pOptions + iLen), Sys_pDnsIp, DHCP_OPCODE_DNS_IP);
	iLen += _FillIPAddr((PCHAR)(pOptions + iLen), Sys_pRouterIp, DHCP_OPCODE_ROUTER_IP);
	iLen += _FillIPAddr((PCHAR)(pOptions + iLen), Sys_pIpAddress, DHCP_OPCODE_SERVER_ID);
	pOptions[iLen] = DHCP_OPCODE_END;
	iLen ++;

	memcpy4(pSendBuf, _cPacketReplyHead);
//	memcpy4((PCHAR)(pSendBuf+DHCP_XID), (PCHAR)(pBuf+DHCP_XID));
	memset((PCHAR)(pSendBuf+DHCP_SECS), 0, DHCP_SECS_LEN);
	pSendBuf[DHCP_FLAGS] = DHCP_FLAG_BROADCAST;
	pSendBuf[DHCP_FLAGS+1] = 0;
	memset((PCHAR)(pSendBuf+DHCP_CIADDR), 0, IP_ALEN);
	memcpy4((PCHAR)(pSendBuf+DHCP_YIADDR), _cClientIP);
	memset((PCHAR)(pSendBuf+DHCP_SIADDR), 0, IP_ALEN);
	memset((PCHAR)(pSendBuf+DHCP_GIADDR), 0, IP_ALEN);
//	memcpy((PCHAR)(pSendBuf+DHCP_CHADDR), (PCHAR)(pBuf+DHCP_CHADDR), HW_ALEN);
	memset((PCHAR)(pSendBuf+DHCP_SNAME), 0, DHCP_OPTIONS - DHCP_SNAME);
	memcpy4((PCHAR)(pSendBuf+DHCP_OPTIONS), _cMagicCookie);

	sIndex = iLen;
	sIndex += DHCP_OPLIST;
	if (sIndex < DHCP_MIN_PACKET_SIZE)
	{
		memset((PCHAR)(pSendBuf + sIndex), 0, (UCHAR)(DHCP_MIN_PACKET_SIZE - sIndex));
		sIndex = DHCP_MIN_PACKET_SIZE;
	}
	UdpSendTo(Dhcpd_pSocket, sIndex, _pBroadcastIP, DHCP_CLIENT_PORT);
}
Exemple #18
0
void RtpRun(UDP_SOCKET pUcb)
{
	UCHAR iType, iLen, iState;
//	USHORT sCurSeq;
//	ULONG lTimeStamp;
	PCHAR pCur;
	PCHAR pData;
	SIP_LCB_HANDLE pLcb;

	if (TaskStunRun(pUcb))		return;

	pData = Adapter_pUdpBuf;
#ifdef OEM_IP20
	pLcb = RtpGetLcb(pUcb);
	if (pLcb->brtpSession == 0)
	{
		pLcb->brtpSession = 1;
	}
	if (!pLcb)	
	{
		pLcb = Sip_pActiveLcb;
		memcpy4(pLcb->pRtpDstSSRC, (PCHAR)(pData + RTP_SSRC));
#ifdef __ADSL
		if (pLcb->brtpSession == 0)
		{
			pLcb->brtpSession = 1;
		}
#endif
	}
	else
	{
		if (pLcb != Sip_pActiveLcb)	return;
	}
#else
	pLcb = RtpGetLcb(pUcb);
	if (!pLcb)	return;
	memcpy4(pLcb->pRtpDstSSRC, (PCHAR)(pData + RTP_SSRC));
	if (pLcb != Sip_pActiveLcb)	return;
#endif
	iState = pLcb->iState;
	if (iState != CALL_STATE_CALLING2 && iState != CALL_STATE_TALKING)
	{
		return;
	}
	if (pLcb->bHolding)
	{
		return;
	}
	if (!(pLcb->iLocalMode & AUDIO_MODE_RECVONLY))
	{
		return;
	}
	if (pLcb->iVoiceCoder == VOICE_CODER_NONE || pLcb->iVoiceCoder > VOICE_CODER_NUM)
	{
		return;
	}

	if (iState == CALL_STATE_CALLING2)
	{
		if (pLcb->iRemoteRb != RINGBACK_REMOTE)
		{
			pLcb->iRemoteRb = RINGBACK_REMOTE;
			TaskUIHandler(UI_CALL_RINGBACK_REMOTE, pLcb->iVoiceCoder);
		}
	}

	iType = pData[RTP_PAYLOAD] & 0x7f;
	// Some device will add RTP padding, we handle it here
	if (pData[RTP_VERSION] & 0x20)
	{
		iLen = pData[pUcb->sLen-1];
		pUcb->sLen -= iLen;
	}

//	sCurSeq = PCHAR2USHORT((PCHAR)(pData+RTP_SEQ));
//	lTimeStamp = PCHAR2ULONG((PCHAR)(pData+RTP_TIMESTAMP));

	// handle packet loss or packet misorder here
	pUcb->sLen -= RTP_DATA;
	pCur = pData;
	pCur += RTP_DATA;
	if (iType == pLcb->iCoderPayload)
	{
		TaskIncomingData(pUcb->sLen, pCur);
	}
	else
	{
		if (iType != pLcb->iDtmfPayload || Sys_iDtmfType != DTMF_TYPE_RFC2833)
		{
			return;
		}
		if (pLcb->bKeyRecved)
		{
			if ((pCur[1] & 0x80) == 0x80)
			{
				// DTMF key end
				pLcb->bKeyRecved = FALSE;
				return;
			}
			if (memcmp(pLcb->pKeyTimeStamp, (PCHAR)(pData+RTP_TIMESTAMP), 4))
			{
				pLcb->bKeyRecved = FALSE;
			}
		}
		if (!pLcb->bKeyRecved)
		{
			memcpy4(pLcb->pKeyTimeStamp, (PCHAR)(pData+RTP_TIMESTAMP));
			pLcb->bKeyRecved = TRUE;
			TaskUIHandler(UI_CALL_INCOMING_DTMF, (USHORT)keyid2ascii(pCur[0]));
		}

	}
}