Exemplo n.º 1
0
int
uart_send(serial_port sp, const uint8_t *pbtTx, const size_t szTx, int timeout)
{
  DWORD   dwTxLen = 0;

  COMMTIMEOUTS timeouts;
  timeouts.ReadIntervalTimeout = 0;
  timeouts.ReadTotalTimeoutMultiplier = 0;
  timeouts.ReadTotalTimeoutConstant = timeout;
  timeouts.WriteTotalTimeoutMultiplier = 0;
  timeouts.WriteTotalTimeoutConstant = timeout;

  if (!SetCommTimeouts(((struct serial_port_windows *) sp)->hPort, &timeouts)) {
    log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to apply new timeout settings.");
    return NFC_EIO;
  }

  LOG_HEX(LOG_GROUP, "TX", pbtTx, szTx);
  if (!WriteFile(((struct serial_port_windows *) sp)->hPort, pbtTx, szTx, &dwTxLen, NULL)) {
    return NFC_EIO;
  }
  if (!dwTxLen)
    return NFC_EIO;
  return 0;
}
Exemplo n.º 2
0
/**
 * @brief Send \a pbtTx content to UART
 *
 * @return 0 on success, otherwise a driver error is returned
 */
int
uart_send(serial_port sp, const uint8_t *pbtTx, const size_t szTx, int timeout)
{
  (void) timeout;
  LOG_HEX(LOG_GROUP, "TX", pbtTx, szTx);
  if ((int) szTx == write(UART_DATA(sp)->fd, pbtTx, szTx))
    return NFC_SUCCESS;
  else
    return NFC_EIO;
}
Exemplo n.º 3
0
int
uart_receive(serial_port sp, uint8_t *pbtRx, const size_t szRx, void *abort_p, int timeout)
{
  DWORD dwBytesToGet = (DWORD)szRx;
  DWORD dwBytesReceived = 0;
  DWORD dwTotalBytesReceived = 0;
  BOOL res;

  // XXX Put this part into uart_win32_timeouts () ?
  DWORD timeout_ms = timeout;
  COMMTIMEOUTS timeouts;
  timeouts.ReadIntervalTimeout = 0;
  timeouts.ReadTotalTimeoutMultiplier = 0;
  timeouts.ReadTotalTimeoutConstant = timeout_ms;
  timeouts.WriteTotalTimeoutMultiplier = 0;
  timeouts.WriteTotalTimeoutConstant = timeout_ms;

  if (!SetCommTimeouts(((struct serial_port_windows *) sp)->hPort, &timeouts)) {
    log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to apply new timeout settings.");
    return NFC_EIO;
  }
  log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Timeouts are set to %lu ms", timeout_ms);

  // TODO Enhance the reception method
  // - According to MSDN, it could be better to implement nfc_abort_command() mecanism using Cancello()
  volatile bool *abort_flag_p = (volatile bool *)abort_p;
  do {
    log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "ReadFile");
    res = ReadFile(((struct serial_port_windows *) sp)->hPort, pbtRx + dwTotalBytesReceived,
                   dwBytesToGet,
                   &dwBytesReceived, NULL);

    dwTotalBytesReceived += dwBytesReceived;

    if (!res) {
      DWORD err = GetLastError();
      log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "ReadFile error: %lu", err);
      return NFC_EIO;
    } else if (dwBytesReceived == 0) {
      return NFC_ETIMEOUT;
    }

    if (((DWORD)szRx) > dwTotalBytesReceived) {
      dwBytesToGet -= dwBytesReceived;
    }

    if (abort_flag_p != NULL && (*abort_flag_p) && dwTotalBytesReceived == 0) {
      return NFC_EOPABORTED;
    }
  } while (((DWORD)szRx) > dwTotalBytesReceived);
  LOG_HEX(LOG_GROUP, "RX", pbtRx, szRx);

  return (dwTotalBytesReceived == (DWORD) szRx) ? 0 : NFC_EIO;
}
Exemplo n.º 4
0
void CDiscoveryApp::print_DiscoveryResponse( void )
{
	LOG("DISCOVERY_REPLY Version %u, Type %u, ANID %u (x%X)", m_stDiscoveryResponse.m_uchMessageVersion, 
		m_stDiscoveryResponse.m_uchMessageType, ntohl(m_stDiscoveryResponse.m_unAnId), ntohl(m_stDiscoveryResponse.m_unAnId));
	
	LOG_HEX( "MAC_Address", m_stDiscoveryResponse.m_uchMAC_Address, sizeof(m_stDiscoveryResponse.m_uchMAC_Address));
	print_ipmask( m_szEthInterf, m_stDiscoveryResponse.m_unIP_ethInterf, m_stDiscoveryResponse.m_unMask_ethInterf );
	print_ipmask( m_szEthInterf_0, m_stDiscoveryResponse.m_unIP_ethInterf_0, m_stDiscoveryResponse.m_unMask_ethInterf_0 );
	print_ipmask( m_szEthInterf_1, m_stDiscoveryResponse.m_unIP_ethInterf_1, m_stDiscoveryResponse.m_unMask_ethInterf_1 );
	print_ipmask( "DefaultGW", m_stDiscoveryResponse.m_unDefaultGateway, 0);
}
Exemplo n.º 5
0
int
pn53x_usb_bulk_read (struct pn53x_usb_data *data, uint8_t abtRx[], const size_t szRx, const int timeout)
{
  int res = usb_bulk_read (data->pudh, data->uiEndPointIn, (char *) abtRx, szRx, timeout);
  if (res > 0) {
    LOG_HEX ("RX", abtRx, res);
  } else if (res < 0) {
    if (res != -USB_TIMEDOUT)
      log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to read from USB (%s)", _usb_strerror (res));
  }
  return res;
}
Exemplo n.º 6
0
int
pn53x_usb_bulk_write (struct pn53x_usb_data *data, uint8_t abtTx[], const size_t szTx, const int timeout)
{
  LOG_HEX ("TX", abtTx, szTx);
  int res = usb_bulk_write (data->pudh, data->uiEndPointOut, (char *) abtTx, szTx, timeout);
  if (res > 0) {
    // HACK This little hack is a well know problem of USB, see http://www.libusb.org/ticket/6 for more details
    if ((res % data->uiMaxPacketSize) == 0) {
      usb_bulk_write (data->pudh, data->uiEndPointOut, "\0", 0, timeout);
    }
  } else {
    log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to write to USB (%s)", _usb_strerror (res));
  }
  return res;
}
Exemplo n.º 7
0
static int
acr122_usb_bulk_read(struct acr122_usb_data *data, uint8_t abtRx[], const size_t szRx, const int timeout)
{
  int res = usb_bulk_read(data->pudh, data->uiEndPointIn, (char *) abtRx, szRx, timeout);
  if (res > 0) {
    LOG_HEX(NFC_LOG_GROUP_COM, "RX", abtRx, res);
  } else if (res < 0) {
    if (res != -USB_TIMEDOUT) {
      res = NFC_EIO;
      log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to read from USB (%s)", _usb_strerror(res));
    } else {
      res = NFC_ETIMEOUT;
    }
  }
  return res;
}
Exemplo n.º 8
0
/**
 * @brief Write a frame to I2C device containing \a pbtTx content
 *
 * @param id I2C device.
 * @param pbtTx pointer on buffer containing data
 * @param szTx length of the buffer
 * @return NFC_SUCCESS on success, otherwise driver error code
 */
int
i2c_write(i2c_device id, const uint8_t *pbtTx, const size_t szTx)
{
  LOG_HEX(LOG_GROUP, "TX", pbtTx, szTx);

  ssize_t writeCount;
  writeCount = write(I2C_DATA(id) ->fd, pbtTx, szTx);

  if ((const ssize_t) szTx == writeCount) {
    log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG,
            "wrote %d bytes successfully.", (int)szTx);
    return NFC_SUCCESS;
  } else {
    log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR,
            "Error: wrote only %d bytes (%d expected) (%s).", (int)writeCount, (int) szTx, strerror(errno));
    return NFC_EIO;
  }
}
Exemplo n.º 9
0
int fcopy_s(FILE* dest, int src, size_t size, int&contentLength )
{
	char rdBuf[8*1024];
	int rb = read( src, rdBuf, size );
	if ( rb <= 0 )
	{
		LOG_ERR("smth went wrong again2");
		return -1 ;
	}
	for ( int wb=0; wb < rb; )
	{
		wb += fwrite( rdBuf+wb, sizeof(char), rb-wb, dest);
	}
	contentLength -= rb ;
	if ( contentLength <= 0 )
	{
		LOG_HEX("BUFFER", (const unsigned char*)rdBuf, rb );
	}
	return rb ;
}
Exemplo n.º 10
0
int
acr122_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szData, int timeout)
{
  // FIXME: timeout is not handled
  (void) timeout;

  int len;
  uint8_t  abtRxCmd[5] = { 0xFF, 0xC0, 0x00, 0x00 };

  if (DRIVER_DATA (pnd)->ioCard.dwProtocol == SCARD_PROTOCOL_T0) {
    /*
     * Retrieve the PN532 response.
     */
    DWORD dwRxLen = sizeof (DRIVER_DATA (pnd)->abtRx);
    abtRxCmd[4] = DRIVER_DATA (pnd)->abtRx[1];
    if (SCardTransmit (DRIVER_DATA (pnd)->hCard, &(DRIVER_DATA (pnd)->ioCard), abtRxCmd, sizeof (abtRxCmd), NULL, DRIVER_DATA (pnd)->abtRx, &dwRxLen) != SCARD_S_SUCCESS) {
      pnd->last_error = NFC_EIO;
      return pnd->last_error;
    }
    DRIVER_DATA (pnd)->szRx = dwRxLen;
  } else {
    /*
     * We already have the PN532 answer, it was saved by acr122_send().
     */
  }
  LOG_HEX ("RX", DRIVER_DATA (pnd)->abtRx, DRIVER_DATA (pnd)->szRx);

  // Make sure we have an emulated answer that fits the return buffer
  if (DRIVER_DATA (pnd)->szRx < 4 || (DRIVER_DATA (pnd)->szRx - 4) > szData) {
    pnd->last_error = NFC_EIO;
    return pnd->last_error;
  }
  // Wipe out the 4 APDU emulation bytes: D5 4B .. .. .. 90 00
  len = DRIVER_DATA (pnd)->szRx - 4;
  memcpy (pbtData, DRIVER_DATA (pnd)->abtRx + 2, len);

  return len;
}
Exemplo n.º 11
0
int socket_sendData(void* data, s32 len)
{
    s32 rc;

    LOG_HEX((const char*)data, len);

    rc = eat_soc_send(socket_id, data, len);
    if (rc >= 0)
    {
        LOG_DEBUG("socket send data successful.");
    }
    else
    {
        if (rc == SOC_PIPE || rc == SOC_NOTCONN)
        {
            fsm_run(EVT_SOCKET_DISCONNECTED);       //这个地方仅为保护作用,正常的socket断链应该会通过soc_notify_cb来通知
        }
        LOG_ERROR("sokcet send data failed:%d!", rc);
    }


    return rc;
}
Exemplo n.º 12
0
/*============================================================================*/
e_derdRet_t sslDerd_getOctStr(s_derdCtx_t *ps_derdCtx,
                              uint8_t*     pc_encSign, size_t* pi_encSignLen)
{
    e_derdRet_t e_res = E_SSL_DER_OK;

    assert(ps_derdCtx != NULL);
    assert(ps_derdCtx->s_octVal.pc_data != NULL);

    if ((ps_derdCtx->c_tag == SSL_DER_ASN1_OCTET_STRING) &&
        (ps_derdCtx->s_octVal.cwt_len > 1) &&
        (pc_encSign != NULL)) {
        *pi_encSignLen = ps_derdCtx->s_octVal.cwt_len;
        memmove(pc_encSign,ps_derdCtx->s_octVal.pc_data,*pi_encSignLen);
        LOG_INFO("signature");
        LOG_HEX(pc_encSign,*pi_encSignLen);
    }
    else
    {
        e_res = E_SSL_DER_ERR_NO_OCTETSTR;
    }

    return (e_res);
} /* sslDerd_getOctStr */
Exemplo n.º 13
0
int
acr122_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout)
{
  // FIXME: timeout is not handled
  (void) timeout;

  // Make sure the command does not overflow the send buffer
  if (szData > ACR122_COMMAND_LEN) {
    pnd->last_error = NFC_EINVARG;
    return pnd->last_error;
  }

  // Prepare and transmit the send buffer
  const size_t szTxBuf = szData + 6;
  uint8_t  abtTxBuf[ACR122_WRAP_LEN + ACR122_COMMAND_LEN] = { 0xFF, 0x00, 0x00, 0x00, szData + 1, 0xD4 };
  memcpy (abtTxBuf + 6, pbtData, szData);
  LOG_HEX ("TX", abtTxBuf, szTxBuf);

  DRIVER_DATA (pnd)->szRx = 0;

  DWORD dwRxLen = sizeof (DRIVER_DATA (pnd)->abtRx);

  if (DRIVER_DATA (pnd)->ioCard.dwProtocol == SCARD_PROTOCOL_UNDEFINED) {
    /*
     * In this communication mode, we directly have the response from the
     * PN532.  Save it in the driver data structure so that it can be retrieved
     * in ac122_receive().
     *
     * Some devices will never enter this state (e.g. Touchatag) but are still
     * supported through SCardTransmit calls (see bellow).
     *
     * This state is generaly reached when the ACR122 has no target in it's
     * field.
     */
    if (SCardControl (DRIVER_DATA (pnd)->hCard, IOCTL_CCID_ESCAPE_SCARD_CTL_CODE, abtTxBuf, szTxBuf, DRIVER_DATA (pnd)->abtRx, ACR122_RESPONSE_LEN, &dwRxLen) != SCARD_S_SUCCESS) {
      pnd->last_error = NFC_EIO;
      return pnd->last_error;
    }
  } else {
    /*
     * In T=0 mode, we receive an acknoledge from the MCU, in T=1 mode, we
     * receive the response from the PN532.
     */
    if (SCardTransmit (DRIVER_DATA (pnd)->hCard, &(DRIVER_DATA (pnd)->ioCard), abtTxBuf, szTxBuf, NULL, DRIVER_DATA (pnd)->abtRx, &dwRxLen) != SCARD_S_SUCCESS) {
      pnd->last_error = NFC_EIO;
      return pnd->last_error;
    }
  }

  if (DRIVER_DATA (pnd)->ioCard.dwProtocol == SCARD_PROTOCOL_T0) {
   /*
    * Check the MCU response
    */

    // Make sure we received the byte-count we expected
    if (dwRxLen != 2) {
      pnd->last_error = NFC_EIO;
      return pnd->last_error;
    }
    // Check if the operation was successful, so an answer is available
    if (DRIVER_DATA (pnd)->abtRx[0] == SCARD_OPERATION_ERROR) {
      pnd->last_error = NFC_EIO;
      return pnd->last_error;
    }
  } else {
    DRIVER_DATA (pnd)->szRx = dwRxLen;
  }

  return NFC_SUCCESS;
}
Exemplo n.º 14
0
/**
 * @brief Receive data from UART and copy data to \a pbtRx
 *
 * @return 0 on success, otherwise driver error code
 */
int
uart_receive(serial_port sp, uint8_t *pbtRx, const size_t szRx, void *abort_p, int timeout)
{
  int iAbortFd = abort_p ? *((int *)abort_p) : 0;
  int received_bytes_count = 0;
  int available_bytes_count = 0;
  const int expected_bytes_count = (int)szRx;
  int res;
  fd_set rfds;
  do {
select:
    // Reset file descriptor
    FD_ZERO(&rfds);
    FD_SET(UART_DATA(sp)->fd, &rfds);

    if (iAbortFd) {
      FD_SET(iAbortFd, &rfds);
    }

    struct timeval timeout_tv;
    if (timeout > 0) {
      timeout_tv.tv_sec = (timeout / 1000);
      timeout_tv.tv_usec = ((timeout % 1000) * 1000);
    }

    res = select(MAX(UART_DATA(sp)->fd, iAbortFd) + 1, &rfds, NULL, NULL, timeout ? &timeout_tv : NULL);

    if ((res < 0) && (EINTR == errno)) {
      // The system call was interupted by a signal and a signal handler was
      // run.  Restart the interupted system call.
      goto select;
    }

    // Read error
    if (res < 0) {
      log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Error: %s", strerror(errno));
      return NFC_EIO;
    }
    // Read time-out
    if (res == 0) {
      log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "Timeout!");
      return NFC_ETIMEOUT;
    }

    if (FD_ISSET(iAbortFd, &rfds)) {
      // Abort requested
      log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "Abort!");
      close(iAbortFd);
      return NFC_EOPABORTED;
    }

    // Retrieve the count of the incoming bytes
    res = ioctl(UART_DATA(sp)->fd, FIONREAD, &available_bytes_count);
    if (res != 0) {
      return NFC_EIO;
    }
    // There is something available, read the data
    res = read(UART_DATA(sp)->fd, pbtRx + received_bytes_count, MIN(available_bytes_count, (expected_bytes_count - received_bytes_count)));
    // Stop if the OS has some troubles reading the data
    if (res <= 0) {
      return NFC_EIO;
    }
    received_bytes_count += res;

  } while (expected_bytes_count > received_bytes_count);
  LOG_HEX(LOG_GROUP, "RX", pbtRx, szRx);
  return NFC_SUCCESS;
}
Exemplo n.º 15
0
//retcode: true if DISCOVERY_REPLY must be sent back
//retcode false if no reply is necessary either because the incomming 
//message is wrong or because it must be ignored
bool CDiscoveryApp::processData(unsigned char *p, const struct sockaddr_in& p_stClientAddr)
{
	if (p==NULL)
	{
		LOG("ERROR processData: parameter NULL");
		return false;	
	}
	if (*(unsigned char *)p!=1)
	{
		LOG("ERROR processData: incorrect MessageVersion %d", *(unsigned char *)p);
		return false;
	}
	
	unsigned char *uchMesssageType=p+sizeof(unsigned char);
	
	switch (*uchMesssageType)
	{
		case DISCOVERY_QRY:
		{
			LOG("DISCOVERY_QRY");
			return  fillDiscoveryResponse(); // instruct caller to send the reply back
		}			
			
		case DISCOVERY_SET:
		{
			IPSet_Msg * pIPSet = (IPSet_Msg*)p;
			LOG("DISCOVERY_SET version %u ANID %u (x%X)", pIPSet->m_uchMessageVersion, ntohl(pIPSet->m_unAnId), ntohl(pIPSet->m_unAnId) );
			
			unsigned short crc=computeCRC((uint8_t *)pIPSet, (uint16_t)(sizeof(IPSet_Msg)-sizeof(pIPSet->m_ushCRC)));
			
			if (crc!=pIPSet->m_ushCRC)
			{
				LOG("ERROR processData: Wrong CRC in ipSet");
				return false;
			}
			
			if(		( pIPSet->m_unIP_ethInterf==0x0 )
				||	( pIPSet->m_unDefaultGateway==0x0)
				||	((pIPSet->m_unMask_ethInterf & pIPSet->m_unDefaultGateway) != ( pIPSet->m_unMask_ethInterf & pIPSet->m_unIP_ethInterf)) )
			{
				LOG("ERROR processData: invalid DISCOVERY_SET (IP/GW are zero or IP&mask != GW&mask)");
				log2flash( "ERR DISCOVERY: Invalid SET %s [IP %s/Mask %s/GW %s] from %s", m_szEthInterf, pIPSet->m_unIP_ethInterf, pIPSet->m_unMask_ethInterf, pIPSet->m_unDefaultGateway, inet_ntoa( p_stClientAddr.sin_addr ));
				
				return false;
			}
			
			IP_array ip_array;
			//read ip/mask/gw to match with packet
			if (GetNetworkConfiguration(ip_array) < 0)
			{
				return false;
			}
			MatchIP_dev( ip_array );

			//both ANID/MAC should either match or mismatch. 
			if( matchMAC( pIPSet ) && (!matchANID( pIPSet )) )
			{
				LOG("ERROR processData: MAC match while ANID mismatch (in %u own %u)", ntohl(pIPSet->m_unAnId), ntohl(getANId()) );
			}
			if( (!matchMAC( pIPSet )) && matchANID( pIPSet ) ) 
			{
				LOG_HEX( "ERROR processData: MAC mismatch while ANID match. In: ", pIPSet->m_uchMAC_Address, sizeof(pIPSet->m_uchMAC_Address) );
				LOG_HEX( "ERROR processData: MAC mismatch while ANID match. Own:", m_ucEthInterfMAC, sizeof(m_ucEthInterfMAC) );
			}
			
			// Compare own MAC and ANID with the ones from the incoming packet
			if(	!( matchMAC( pIPSet ) && matchANID( pIPSet ) ) )
			{
				char szTmp[128];
				snprintf(szTmp, sizeof(szTmp), "Ignore DISCOVERY_SET for AN %u MAC", ntohl(pIPSet->m_unAnId) );
				szTmp[ sizeof(szTmp) - 1 ] = 0;
				
				LOG_HEX( szTmp, pIPSet->m_uchMAC_Address, sizeof(pIPSet->m_uchMAC_Address) );
				return false;
			}
			
			ConfigureNetwork(*pIPSet);
			update_rcnetinfo(RC_NET_INFO, pIPSet->m_unIP_ethInterf, pIPSet->m_unMask_ethInterf, pIPSet->m_unDefaultGateway, p_stClientAddr);
			
			//memset(p, 0, BUFLEN);
			fillDiscoveryResponse();
			
			return true;	// instruct caller to send the reply back
		}
		case DISCOVERY_REPLY:
		{
			LOG("Ignore DISCOVERY_REPLY");
			return false;
		}
			
		default:
		{
			LOG("ERROR processData() unknown MessageType %u", *uchMesssageType);
			return false;
		}
	}
}
Exemplo n.º 16
0
/// Load the config.ini file and parse it to extract various configurations out of it
/// @retval 1 success
/// @retval 0 failure
/// @note DO NOT read same variable in Init() and Reload(). Init calls Reload.
int CISAConfig::Init()
{
	if(!CConfig::Init("GATEWAY"))
	{
		return 0;
	}

	READ_DEFAULT_VARIABLE_INT ("TCP_YGSAP_PORT",  m_nYGSAP_TCPPort, 0);
	READ_DEFAULT_VARIABLE_INT ("TCP_SERVER_PORT", m_nGSAP_TCPPort, 4900);

	READ_DEFAULT_VARIABLE_INT ("TCP_SERVER_PORT_SSL", m_nGSAP_TCPPort_SSL, 0);
	READ_DEFAULT_VARIABLE_INT ("TCP_YGSAP_PORT_SSL", m_nYGSAP_TCPPort_SSL, 0);
	
	READ_DEFAULT_VARIABLE_INT ("SM_LINK_TIMEOUT", m_nPingTimeout, 50);
	READ_DEFAULT_VARIABLE_STRING("GATEWAY_TAG", m_szGWTag, "Nivis Gateway" );

	if ( m_nGSAP_TCPPort_SSL != 0 ||  m_nYGSAP_TCPPort_SSL != 0)
	{
		READ_DEFAULT_VARIABLE_STRING("SSL_SERVER_CERTIF_FILE", m_szSslServerCertif, "/access_node/activity_files/ssl_resources/servercert.pem" );
		READ_DEFAULT_VARIABLE_STRING("SSL_SERVER_KEY_FILE", m_szSslServerKey, "/access_node/activity_files/ssl_resources/serverkey.pem" );
		READ_DEFAULT_VARIABLE_STRING("SSL_CA_CERTIF_FILE", m_szSslCaCertif, "/access_node/activity_files/ssl_resources/cakey.pem" );
	}
	

	if(GetVar("HOST_APP", &m_HostAddr )){
		LOG_HEX( "m_HostAddr(hexdump):", (uint8*)&m_HostAddr, sizeof(net_address));
	}

	READ_MANDATORY_VARIABLE("GATEWAY_IPv6", m_oGWIPv6 );

	char szIPv4[16];
	READ_MANDATORY_VARIABLE_STRING("GATEWAY_IPv4", szIPv4);
	READ_MANDATORY_VARIABLE("GATEWAY_UDPPort", m_nGW_UDPPort)

	if (!AdjustIPv6(&m_oGWIPv6,szIPv4, m_nGW_UDPPort))
	{
		return 0;
	}

	LOG("GW IPv6=%s IPv4=%s UDPPort=%d", m_oGWIPv6.GetPrintIPv6(), szIPv4, m_nGW_UDPPort);

	if(!GetVar("GATEWAY_EUI64", (uint8_t*)m_pu8GWEUI64, sizeof(m_pu8GWEUI64)))
	{
		return 0;
	}

	READ_MANDATORY_VARIABLE("SubnetID", m_nSubnetID);
	LOG("SubnetID %u (0x%X)", m_nSubnetID, m_nSubnetID);
	READ_MANDATORY_VARIABLE_STRING("AppJoinKey", m_u8AppJoinKey);
	
	READ_DEFAULT_VARIABLE_INT ("TLDE_HLIST_SIZE",  m_nTldeHListSize, 100);
	READ_DEFAULT_VARIABLE_INT ("TLDE_HLIST_TIME_WINDOW",  m_nTldeHListTimeWindow, 60);

	Reload();

	if(!CIniParser::GetVar("SYSTEM_MANAGER", "SYSTEM_MANAGER_IPv6", &m_oSMIPv6 ))
	{	return 0;
	}
	if(!CIniParser::GetVar("SYSTEM_MANAGER", "SYSTEM_MANAGER_IPv4", szIPv4, sizeof(szIPv4)))
	{	return 0;
	}
	if(!CIniParser::GetVar("SYSTEM_MANAGER", "SYSTEM_MANAGER_Port", &m_nSMPort))
	{	return 0;
	}
	if(!CIniParser::GetVar("SYSTEM_MANAGER", "CURRENT_UTC_ADJUSTMENT", &m_nCrtUTCAdj))
	{	return 0;
	}
	if (!AdjustIPv6(&m_oSMIPv6,szIPv4, m_nSMPort))
	{	return 0;
	}
	LOG("SM IPv6=%s IPv4=%s Port=%d", m_oSMIPv6.GetPrintIPv6(), szIPv4, m_nSMPort);

	if(!CIniParser::GetVar("SYSTEM_MANAGER", "SECURITY_MANAGER_EUI64", m_u8SecurityManager, sizeof(m_u8SecurityManager)))
	{	return 0;
	}

	LOG("Config loaded");
	//--------------
	return 1;
}