static void TSCHtimeslotIE_HtoLE(uint8_t *p_pu8Buff, int p_nLen) { if (p_nLen == 1) { return; } else if (p_nLen == sizeof(TSCHtimeslotIE)) { TSCHtimeslotIE *pTSCH = (TSCHtimeslotIE *) p_pu8Buff; pTSCH->m_unCCAOffset = HtoLEs(pTSCH->m_unCCAOffset); pTSCH->m_unCCADuration = HtoLEs(pTSCH->m_unCCADuration); pTSCH->m_unTxOffset = HtoLEs(pTSCH->m_unTxOffset); pTSCH->m_unRxOffset = HtoLEs(pTSCH->m_unRxOffset); pTSCH->m_unRxAckDelay = HtoLEs(pTSCH->m_unRxAckDelay); pTSCH->m_unTxAckDelay = HtoLEs(pTSCH->m_unTxAckDelay); pTSCH->m_unRxWait = HtoLEs(pTSCH->m_unRxWait); pTSCH->m_unRxAckWait = HtoLEs(pTSCH->m_unRxAckWait); pTSCH->m_unRxToTx = HtoLEs(pTSCH->m_unRxToTx); pTSCH->m_unMaxTxAckDuration = HtoLEs(pTSCH->m_unMaxTxAckDuration); pTSCH->m_unMaxTxDPDUDuration = HtoLEs(pTSCH->m_unMaxTxDPDUDuration); pTSCH->m_unTimeslotLen = HtoLEs(pTSCH->m_unTimeslotLen); } else { NLOG_ERR("TSCHtimeslotIE LE conversion: expected %d bytes, got %d ", sizeof(TSCHtimeslotIE), p_nLen); } }
static void Slotframes_HtoLE(uint8_t *p_pu8Buff, int p_nLen) { int nSlotFrames = *p_pu8Buff++; if (p_nLen < (int) (nSlotFrames * sizeof(TMacSlotframeInfo))) { NLOG_ERR("Slotframes LE conversion: expected at least %d bytes, got %d ", nSlotFrames * sizeof(TMacSlotframeInfo), p_nLen); return; } for (int i = 0; i < nSlotFrames; i++) { TMacSlotframeInfo *pSFInfo = (TMacSlotframeInfo *) p_pu8Buff; pSFInfo->m_u16SlotframeSize = HtoLEs(pSFInfo->m_u16SlotframeSize); p_pu8Buff += sizeof(TMacSlotframeInfo); for (int j = 0; j < pSFInfo->m_u8LinksNo; j++) { TMacLinkInfo *pLinkInfo = (TMacLinkInfo *) p_pu8Buff; pLinkInfo->m_u16Timeslot = HtoLEs(pLinkInfo->m_u16Timeslot); pLinkInfo->m_u16ChannelOffset = HtoLEs(pLinkInfo->m_u16ChannelOffset); p_pu8Buff += sizeof(TMacLinkInfo); } } }
void CIPGRegUpdCmd::Execute() { NLOG_INFO("[IPGRegUpdCmd]: received msg = %s", MsgToStr(m_rMsg).c_str()); CMgmtPOption::OptionIPGatewayInfoData *pOpData1 = NULL; std::list<CMgmtPOption::OptionIPRoutesListData> rawRouteInfo; CMgmtPOption::OptionKeepAliveIntervalData *pOpData2 = NULL; if (!ProcessMsg(&pOpData1, rawRouteInfo, &pOpData2)) { if (m_rIPGList.find(CIPGInfo (m_rMsg.m_oNetAddr)) == m_rIPGList.end()) NLOG_ERR("[IPGRegUpdCmd]: MODULE=%s was not added in CACHE because of invalid register/update INFO ", AddrToStr(m_rMsg.m_oNetAddr).c_str()); return; } ///add module if it doesn't exist CIPGInfo key(m_rMsg.m_oNetAddr); std::set<CIPGInfo>::iterator i = m_rIPGList.find(key); bool isNewIPG = false; if (i == m_rIPGList.end()) { ///FIRST CTunnelKey info(pOpData1->m_IPGAddrIPv4, pOpData1->m_szIPGAddrIPv6, 128); if (m_rFARAndIPGPubInf.insert(info).second == false) { NLOG_WARN("[IPGRegUpdCmd]: MODULE=%s was not added in CACHE because of duplicated publicInfo=%s, " "skip processing msg = %s", AddrToStr(m_rMsg.m_oNetAddr).c_str(), TunnelKeyToStr(info).c_str(), MsgToStr(m_rMsg).c_str()); return; } isNewIPG = true; i = m_rIPGList.insert(CIPGInfo(m_rMsg.m_oNetAddr, CModuleInfo::MT_REGISTERED)).first; i->SetPendingTimedout(m_rApp.GetConfig().m_nPendingRelationTimedoutS); } CIPGInfo *pIPGInfo = (CIPGInfo*)&(*i); pIPGInfo->SetTimedOut(CModuleInfo::MTT_KEEP_ALIVE, pOpData2->m_IntSec, pOpData2->m_IntUSec); pIPGInfo->SetPublicIpgInfo(*pOpData1); if(pIPGInfo->GetState() != CModuleInfo::MT_REGISTERED) pIPGInfo->SetState(CModuleInfo::MT_REGISTERED); ///process std::list<CMgmtPOption::OptionIPRoutesListData> IPGAddedRoute; std::list<CMgmtPOption::OptionIPRoutesListData> IPGEraseRoute; ProcessRegIPG(i, isNewIPG, rawRouteInfo, IPGAddedRoute, IPGEraseRoute); NLOG_INFO("[IPGRegUpdCmd]: raw(routes=%d), add(routes=%d), erase(routes=%d)", rawRouteInfo.size(), IPGAddedRoute.size(), IPGEraseRoute.size()); ///send result if (IPGAddedRoute.size() > 0) //SendAddTunnOnIPG(m_rMsg.m_oNetAddr, IPGAddedTun); -- not add only the difference but all SendSetTunnOnIPG(i); if (IPGEraseRoute.size() > 0) SendDelTunnOnIPG(m_rMsg.m_oNetAddr, IPGEraseRoute, m_rApp); }
bool CTun::checkRead (unsigned int p_nTimeout) { if (m_nTunHandle == -1) return false; fd_set readfds; struct timeval tmval; tmval.tv_usec = p_nTimeout%1000000; tmval.tv_sec = p_nTimeout/1000000; FD_ZERO(&readfds); FD_SET(m_nTunHandle, &readfds); int nSelected = ::select( m_nTunHandle +1, &readfds, NULL, NULL, &tmval); if ( -1 == nSelected ) { NLOG_ERR("CTun::checkRead(fd %u)", m_nTunHandle); if (errno == EINTR ) { return false; } Close(); return false; } return FD_ISSET( m_nTunHandle, &readfds ); }
////////////////////////////////////////////////////////////////////////////// /// @brief Will try to connect using the socket that should be used /// @retval true if everything is ok, false otherwise /// @param [in] p_szHost Host where to connect (IP of hostname) /// @param [in] p_nPort Destination port to connect /// @param [in] p_nTimeout Timeout expressed in seconds for connection ////////////////////////////////////////////////////////////////////////////// bool CAbstractSocket::Connect(const char *p_szHost, unsigned short p_nPort, unsigned short p_nTimeout /*= 10*/) { // Check parameters if(p_szHost == NULL || p_szHost[0] == 0 || p_nPort == 0) { NLOG_WARN("Cannot connect to NULL host or port 0."); return false; } if(m_bSSLFlag) { bool bConnect = m_oSecureSocket.Connect(p_szHost, p_nPort, p_nTimeout); if(!bConnect) return false; if(!m_oSecureSocket.BlockUntilSSLServerHandshakeCompletes()) { NLOG_ERR("Cannot block until SSL handshake completes!"); return false; } return bConnect; } else return m_oNormalSocket.Connect(p_szHost, p_nPort, p_nTimeout); }
bool CSumiUtils::APISendDeactivateLogs(uint8_t p_u8SerialMsgId, CBufferedSerialLink *p_poBufferedSerialLink) { //msg header API_MSG_HDR *pHdr = (API_MSG_HDR*)m_pucSendBuf; SET_API_HDR(pHdr, API_DEBUG, API_MSG_REQ, API_DEACTIVATE_LOG, p_u8SerialMsgId, 0); //send msg if( !p_poBufferedSerialLink->IsLinkOpen() ) { NLOG_ERR("LINK NOT OPEN!"); return false; } int nSentLen = p_poBufferedSerialLink->Write(m_pucSendBuf, sizeof(API_MSG_HDR)); if ( nSentLen <=0 ) { NLOG_ERR("FAILED TO SEND API_DEACTIVATE_LOGS ON SERIAL LINK!"); return false; } return true; }
void CEPInfo::InsertRelatFAR(const CNetAddressExt&p_rAddr)const { if (m_relatedFARs.insert(p_rAddr).second == false) { NLOG_ERR("[InsertRelatFAR]: related far (source_addr=%s) is already in related FAR list on EP!", AddrToStr(p_rAddr).c_str()); assert(false); } }
CMutexWrapper::~CMutexWrapper() { int result; if ( ( result = pthread_mutex_destroy(&m_oMutex) ) != 0 ) { NLOG_ERR( "%s, pthread_mutex_destroy() failed with result %d.", __PRETTY_FUNCTION__, result ); } }
bool CNMS_DBMngt::GetSystemSetProp(unsigned int &val) { IDbSPHelper *pHelper = Connect(); if (pHelper == NULL) return false; // pHelper->CreateSPCommand("GetSystemSettingsProperty"); if (!pHelper->AddINParam(1, "NetworkPrefixesTimestamp")) { NLOG_ERR("NMS_DBMngt:GetSystemSetProp: failed to add param for sp -> GetSystemSettingsProperty!"); delete pHelper; return false; } char szValue[70]; if (!pHelper->AddOUTParam(2, (char*)szValue, (int)sizeof(szValue))) { NLOG_ERR("NMS_DBMngt:GetSystemSetProp: failed to add param for sp -> GetSystemSettingsProperty!"); delete pHelper; return false; } int errCode = 0; if (!pHelper->AddOUTParam(3, &errCode)) { NLOG_ERR("NMS_DBMngt:GetSystemSetProp: failed to add param for sp -> GetSystemSettingsProperty!"); delete pHelper; return false; } if (!pHelper->ExecuteQuery()) { NLOG_ERR("NMS_DBMngt:GetSystemSetProp: failed to execute query for sp -> GetSystemSettingsProperty!"); delete pHelper; return false; } if (errCode == 1) { NLOG_ERR("NMS_DBMngt:GetSystemSetProp: failed to execute query for sp -> GetSystemSettingsProperty! with err=%d", errCode); delete pHelper; return false; } sscanf(szValue, "%u", &val); NLOG_INFO("szValue=%s, and int=%d", szValue, val); delete pHelper; return true; }
////////////////////////////////////////////////////////////////////////////// /// @brief Parse the current CRadioMessage and creates a string /// @param [in] If true and message encrypted will display it decrypted /// @retval The string describing object structure information - detalied ////////////////////////////////////////////////////////////////////////////// string CRadioMessage::ToString(bool p_bDecrypt /*= false*/) { ostringstream oBuf; uint8_t *pu8DecryptedPayload = NULL; uint32_t u32DecryptedLength = 0; bool bEncryptedWithDefaultKey = false; oBuf << TypeStr() << " CRadioMessage [ ID: " << m_u32ID << " ] "; oBuf << " Time: " << m_u32ReceivedTime << " "; if(m_u1HMAC) oBuf << "<HMAC> "; if(m_u1Signed) oBuf << "<Signed> "; if(m_u1Compressed) oBuf << "<Compressed> "; if(m_u1Encrypted) oBuf << "<Encrypted> "; // All useful information oBuf << "\nRemote: " << CAdapterUtil::IntToHexStr(m_u32RemoteLANAddress) << " [" << CAdapterUtil::Int64ToHexStr(m_u64RemoteWANAddress) << "]" << ", "; oBuf << "Local: " << CAdapterUtil::IntToHexStr(m_u32LocalLANAddress) << " [" << CAdapterUtil::Int64ToHexStr(m_u64LocalWANAddress) << "]" << "\n"; oBuf << "Priority: " << (int)m_u8Priority << ", TTL: " << m_u16TimeToLive << ", Hops: " << (int)m_u8MaxHops; oBuf << ", Mood: " << (int)m_u8Mood << ", Receipt: " << (int)m_u8ReturnReceipt; // Check if it is a small/big resident DCW if(m_u32RemoteLANAddress == 0xFEFEFE7D) oBuf << " <Small DCW>"; else if(m_u32RemoteLANAddress == 0xFEFEFE7E) oBuf << " <Big DCW>"; // Display hex formatted payload oBuf << ", Payload " << ((p_bDecrypt && m_u1Encrypted) ? "<Decrypted>" : "" ) << ": \n" << "------------------------------------------------------------------------\n"; if(p_bDecrypt && m_u1Encrypted) { // Decrypt packet u32DecryptedLength = m_u32PayloadLength - ENC_HMAC_SIZE_USED + AES_BLOCK_SIZE; pu8DecryptedPayload = new uint8_t[u32DecryptedLength]; if(!CEncryption::LGDecrypt(m_pu8Payload, m_u32PayloadLength, m_u32RemoteLANAddress, m_u32ID, m_u8ReturnReceipt, m_u4MessageType, m_u1Encrypted, pu8DecryptedPayload, u32DecryptedLength, bEncryptedWithDefaultKey)) { NLOG_ERR("Cannot decrypt packet to display data!"); oBuf << CAdapterUtil::GetFormattedHex(m_pu8Payload, m_u32PayloadLength); } else { NLOG_INFO("Packet was succesfully decrypted to be displayed."); oBuf << CAdapterUtil::GetFormattedHex(pu8DecryptedPayload, u32DecryptedLength); } delete[] pu8DecryptedPayload; } else oBuf << CAdapterUtil::GetFormattedHex(m_pu8Payload, m_u32PayloadLength); return oBuf.str(); }
bool CTun::collectIp6Packet(IpPacket::IPv6* p_poPacket, ssize_t br) { if (br < (ssize_t)offsetof(IpPacket::IPv6, m_oIP_Payload)) { NLOG_WARN("CTun::collectIp6Packet, [IP] header too small: expected(0x%04x), received(0x%04x)", offsetof(IpPacket::IPv6, m_oIP_Payload), br); return false; } // verify packet length uint16_t rcvLen = ntohs(p_poPacket->m_u16_PayloadLength); if(rcvLen + (ssize_t)offsetof(IpPacket::IPv6, m_oIP_Payload) != br) { NLOG_WARN("CTun::collectIp6Packet, [IP] packet size wrong: expected(0x%04x), received(0x%04x)", rcvLen + offsetof(IpPacket::IPv6, m_oIP_Payload), br); return false; } // verify checksums Ip6PseudoHdr oPHdr(p_poPacket); uint16_t rcvChecksum; // pseudoheader checksum uint16_t expChecksum = IpPacket::Checksum((uint8_t*)&oPHdr, sizeof oPHdr); switch(p_poPacket->m_u8_NextHeader) { case IPPROTO_ICMPV6: { rcvChecksum = ntohs(p_poPacket->m_oICMP_Payload.m_u16_Checksum); p_poPacket->m_oICMP_Payload.m_u16_Checksum = 0; expChecksum = IpPacket::Checksum((const uint8_t*)(&p_poPacket->m_oICMP_Payload), rcvLen, expChecksum); if (expChecksum != rcvChecksum) { NLOG_WARN("CTun::collectIp6Packet, [ICMP] incorrect checksum: expected(0x%04x), received(0x%04x)", expChecksum, rcvChecksum); return false; } p_poPacket->m_oICMP_Payload.m_u16_Checksum = htons(rcvChecksum); break; } case IPPROTO_UDP: { rcvChecksum = ntohs(p_poPacket->m_oUDP_Payload.m_u16_Checksum); if (!rcvChecksum){ //IPv6 receivers must discard UDP packets containing a zero checksum, and should log the error. NLOG_ERR("CTun::collectIp6Packet, [UDP] incorrect zero checksum: packet discarded"); return false; }; p_poPacket->m_oUDP_Payload.m_u16_Checksum = 0; expChecksum = IpPacket::Checksum((uint8_t*)&p_poPacket->m_oUDP_Payload, rcvLen, expChecksum); if(!expChecksum ) expChecksum = 0xFFFF; if (expChecksum != rcvChecksum) { NLOG_WARN("CTun::collectIp6Packet, [UDP] incorrect checksum: expected(0x%04x), received(0x%04x)", expChecksum, rcvChecksum); return false; } p_poPacket->m_oUDP_Payload.m_u16_Checksum = htons(rcvChecksum); break; } default:; } return true; }
//read uint16_t NewBroadcastID() { uint32_t val = m_oPersistentMsgId.GetNextMsgId(); if(val < BID_MIN_ID || val > BID_MAX_ID) { NLOG_ERR("NewBroadcastID: invalid msg_id"); return 0; } return (uint16_t)val; }
void CEPInfo::InsertRelatedNS(const CNSPeerKey &p_rkey, const CNetAddressExt/*SS sourceAddres*/&p_rAddr)const { std::pair<CNSPeerKey/*NS INFO*/, CNetAddressExt/*SS sourceAddres*/> relatedNSElem(p_rkey, p_rAddr); if (m_relatedNSs.insert(relatedNSElem).second == false) { NLOG_ERR("[InsertRelateNS]: NS peerkey (ipv6=%s, port=%d) is already in related NS list on EP!", AddrToStr(p_rkey.GetIPv6Addr()).c_str(), p_rkey.GetIPv6Addr().GetPort()); assert(false); } }
/////////////////////////////////////////////////////////////////////////////// ///@author Ghervase Gabriel ///@brief Checks if a full messasge can be read from the usb ///@param [in]p_nMiliSec - How much to wait for data before abandoning the operation ///@retval false if no data or error ///@retval true if we have data /////////////////////////////////////////////////////////////////////////////// bool CFragmentedUSBLink::HaveData(unsigned int p_nMiliSec/* = 10*/) { if (m_bHaveFullPacket) { return m_bHaveFullPacket; } USBFragment ofragment; while (getFragment(ofragment, p_nMiliSec)) { //check messageId - if unexpected, drop previously read data and restart with new messageID if (m_nExpectedMessageId != ofragment.msgId) { //dump previously received data (if any) dropExistingReadData(); m_nExpectedMessageId = ofragment.msgId; } // ignore - duplicate packet received if (ofragment.pktNo < m_u8ExpectedPktNo) { continue; } // packets should arrive in order ; dump previously received data if not if (ofragment.pktNo > m_u8ExpectedPktNo) { NLOG_WARN("[CFragmentedUSBLink][HaveData] Bad pktNo received : %d > expected %d - Discard existing fragments for msgId %d ", (int)(ofragment.pktNo), (int)(m_u8ExpectedPktNo), (int)(ofragment.msgId) ); dropExistingReadData(); continue; } if (m_nBytesReceivedSoFar + FRAGMENT_DATA_SIZE > MAX_USB_PACKET_SIZE) { NLOG_ERR("[CFragmentedUSBLink][HaveData] Internal Buffer too small; is %d and we need %d - Discard existing fragments for msgId %d", (int)MAX_USB_PACKET_SIZE, (int)(m_nBytesReceivedSoFar + FRAGMENT_DATA_SIZE), (int)(ofragment.msgId)); dropExistingReadData(); continue; } memcpy(m_pu8ReadBuf + m_nBytesReceivedSoFar, ofragment.data, FRAGMENT_DATA_SIZE); m_nBytesReceivedSoFar += FRAGMENT_DATA_SIZE; m_u8ExpectedPktNo++; if (ofragment.notLastFragment) { continue; } //we have received the last fragment m_bHaveFullPacket = true; break; } return m_bHaveFullPacket; }
void CEPInfo::InsertPendRelatNS(const CNSPeerKey &p_rkey)const { if (m_pendingRelatedNSs.insert(p_rkey).second == false) { NLOG_ERR("[InsertPendRelatNS]: NS peerkey (ipv6=%s, port=%d) is already in pending related NS list on EP!", AddrToStr(p_rkey.GetIPv6Addr()).c_str(), p_rkey.GetIPv6Addr().GetPort()); assert(false); } CCommPendRelat::StartPendRelatCountDown(); }
void CEPInfo::MovePendNSToRelNS(const CNSPeerKey &p_rkey, const CNetAddressExt/*SS sourceAddres*/&p_rAddr)const { std::set<CNSPeerKey>::iterator jt = m_pendingRelatedNSs.find(p_rkey); if (jt == m_pendingRelatedNSs.end()) { NLOG_ERR("[MovePendNSToRelSS]: there is no pending NS(ipv6=%s, port=%d) on ep__module_addr=%s", AddrToStr(p_rkey.GetIPv6Addr()).c_str(), p_rkey.GetIPv6Addr().GetPort(), AddrToStr(m_addr).c_str()); assert(false); } std::pair<CNSPeerKey,CNetAddressExt> relatedNS(*jt, p_rAddr); if (m_relatedNSs.insert(relatedNS).second==false) { NLOG_ERR("[MovePendNSToRelNS]: SS peerkey (ipv6=%s, port=%d) in both SS list on EP!", AddrToStr(p_rkey.GetIPv6Addr()).c_str(), p_rkey.GetIPv6Addr().GetPort()); assert(false); } m_pendingRelatedNSs.erase(jt); }
/////////////////////////////////////////////////////////////////////////////// ///@author Ghervase Gabriel ///@brief < operator ///@retval true fragments are < ///@retval false fragments not < ///@param [in] p_rRight - fragment to compare to /////////////////////////////////////////////////////////////////////////////// bool CFragment::operator<(const CFragment& p_rRight) const { if ( (memcmp(GetSrcAddr(), p_rRight.GetSrcAddr(), p_rRight.GetAddressSize()) != 0) || GetMessageId() != p_rRight.GetMessageId() ) { NLOG_ERR ("[Fragment] - Cannot compare fragments belonging to different messages"); return false; } return GetFragmentId() < p_rRight.GetFragmentId(); }
bool CSumiUtils::SendACK(uint8_t p_u8AckMsgId, CBufferedSerialLink *p_poBufferedSerialLink) { //compose ack //uint8_t u8AckMsgId = API_GET_MESSAGE_ID(pHdr); API_MSG_HDR *pHdr = (API_MSG_HDR*)m_pucSendBuf; SET_API_HDR(pHdr, API_ACK, API_MSG_RSP, DATA_OK, p_u8AckMsgId, 0); //check link if( !p_poBufferedSerialLink->IsLinkOpen() ) { NLOG_ERR("SendACK: LINK NOT OPEN!"); return -1; } //send ack int nSentLen = p_poBufferedSerialLink->Write(m_pucSendBuf, sizeof(API_MSG_HDR)); if ( nSentLen <=0 ) { NLOG_ERR("SendACK: FAILED TO SEND ON SERIAL LINK!"); return false; } return true; }
void CFARDefaultTunnProc::DeleteIPGKey(const CTunnelKey &p_rIPGKey) { std::map<CTunnelKey, unsigned int>::iterator it = m_IPGsLoad.find(p_rIPGKey); if (it == m_IPGsLoad.end()) { NLOG_ERR("[DeleteIPGKey]: ipg_key=%s not found!", TunnelKeyToStr(p_rIPGKey).c_str()); assert(false); } m_IPGsLoad.erase(it); }
void CEPInfo::EraseRelatedNS(const CNSPeerKey &p_rkey)const { std::map<CNSPeerKey/*NS INFO*/, CNetAddressExt/*SS sourceAddres*/>::iterator jt = m_relatedNSs.find(p_rkey); if (jt == m_relatedNSs.end()) { NLOG_ERR("[EraseRelatedNS]: trying to erase NS(ipv6=%s, port=%d) from related ep list on ep_module with addr=%s", AddrToStr(p_rkey.GetIPv6Addr()).c_str(), p_rkey.GetIPv6Addr().GetPort(), AddrToStr(m_addr).c_str()); assert(false); } m_relatedNSs.erase(jt); }
/////////////////////////////////////////////////////////////////////////////////// // Name: Unlock // Author: Ghervase Gabriel // Description: release lock on mutex // Parameters: none // Return: true - lock was acquired // false - lock was not acquired, or fail ////////////////////////////////////////////////////////////////////////////////// bool CMutexWrapper::Unlock() { int result; if ( ( result = pthread_mutex_unlock(&m_oMutex) ) != 0 ) { NLOG_ERR( "%s, pthread_mutex_unlock() failed with result %d.", __PRETTY_FUNCTION__, result ); return false; } return true; }
void CEPInfo::ErasePendRelatNS(const CNSPeerKey &p_rkey)const { std::set<CNSPeerKey>::iterator jt = m_pendingRelatedNSs.find(p_rkey); if (jt == m_pendingRelatedNSs.end()) { NLOG_ERR("[ErasePendRelatNS]: trying to erase NS(ipv6=%s, port=%d) from pending ep list on ep_module with addr=%s", AddrToStr(p_rkey.GetIPv6Addr()).c_str(), p_rkey.GetIPv6Addr().GetPort(), AddrToStr(m_addr).c_str()); assert(false); } m_pendingRelatedNSs.erase(jt); }
void CEPInfo::EraseRelatedFAR(const CNetAddressExt &p_rAddr)const { std::set<CNetAddressExt>::iterator it = m_relatedFARs.find(p_rAddr); if (it == m_relatedFARs.end()) { NLOG_ERR("[EraseRelatedFAR]: related far (source_addr=%s) is not in related FAR list on EP!", AddrToStr(p_rAddr).c_str()); assert(false); } m_relatedFARs.erase(it); }
void CFARDefaultTunnProc::IncrementLoad(const CTunnelKey &p_rIPGKey) { std::map<CTunnelKey, unsigned int>::iterator it = m_IPGsLoad.find(p_rIPGKey); if (it == m_IPGsLoad.end()) { NLOG_ERR("[IncrementLoad]: ipg_key=%s not found!", TunnelKeyToStr(p_rIPGKey).c_str()); assert(false); } it->second++; }
/////////////////////////////////////////////////////////////////////////////// ///@author Nicolae Bodislav ///@brief Callback called internally when the write is done or the timeout expires. ///@param transfer - struct libusb_transfer that contains data from the transfer. ///@retval none. /////////////////////////////////////////////////////////////////////////////// void CUSBLink::Cb_TransferWrite(struct libusb_transfer *transfer) { CUSBLink* c = (CUSBLink*)transfer->user_data; NLOG_DBG("[CUSBLink][Cb_TransferWrite] Data transfer status %d\n", transfer->status); if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { c->Transfer(false, 0); NLOG_ERR("[CUSBLink][Cb_TransferWrite] Transfer not completed"); } c->Transfer(false, transfer->actual_length); }
void RegExt_LEtoH(uint8_t* p_pu8InBuff, int p_nInLen) { if (p_nInLen < (int) offsetof(TMapRegExt,m_pu8EBIEdata) ) { NLOG_ERR("RegExt_LEtoH: expected at least %d bytes, got %d ", sizeof(TMapRegExt), p_nInLen); return; } TMapRegExt *pRegExt = (TMapRegExt *) p_pu8InBuff; pRegExt->m_u16AdvIncPeriod = LEtoHs(pRegExt->m_u16AdvIncPeriod); }
////////////////////////////////////////////////////////////////////////////// /// @brief Create our abstract socket, SSL or not /// @retval true if everything is ok, false otherwise /// @param [in] p_nType Socket type, like SOCK_STREAM /// @param [in] p_nFamily Socket family, like AF_INET ////////////////////////////////////////////////////////////////////////////// bool CAbstractSocket::Create(int p_nType /*= SOCK_STREAM*/, int p_nFamily /*= AF_INET*/) { if(m_bSSLFlag) { // Create socket if(m_oSecureSocket.Create(p_nType, p_nFamily)) { if(!m_oSecureSocket.InitSSL(CTcpSecureSocket::CLIENT_SIDE, NULL, NULL, NULL, TLS_1_0)) { NLOG_ERR("Cannot initialize SSL context!"); return false; } NLOG_INFO("SSL socket was succesfully created."); return true; } else { NLOG_ERR("Cannot create SSL socket!"); return false; } } // TcpSocket else { if(m_oNormalSocket.Create(p_nType, p_nFamily)) { NLOG_INFO("TcpSocket was succesfully created."); return true; } else { NLOG_ERR("Cannot create the TcpSocket!"); return false; } } }
/////////////////////////////////////////////////////////////////////////////////// // Name: CMutexWrapper // Author: Ghervase Gabriel // Description: contructor for creating a mutex with explicit attributes // Parameters: p_nPrioceiling - the priority ceiling of initialised mutexes, // which is the minimum priority level at which // the critical section guarded by the mutex is executed // Must be within the maximum range of priorities // defined under the SCHED_FIFO scheduling policy // p_nProtocol - protocol to be followed ; can be one of : // PTHREAD_PRIO_NONE, // PTHREAD_PRIO_INHERIT, // PTHREAD_PRIO_PROTECT // p_nPshared - mutex's process-shared state; // determines whether the mutex can be used to // synchronize threads within the current process // or threads within all processes on the system // Values : // PTHREAD_PROCESS_PRIVATE, // PTHREAD_PROCESS_SHARED // p_nType - type of mutex. Values: // PTHREAD_MUTEX_NORMAL, // PTHREAD_MUTEX_RECURSIVE, // PTHREAD_MUTEX_ERRORCHECK, // PTHREAD_MUTEX_DEFAULT // Return: none ////////////////////////////////////////////////////////////////////////////////// CMutexWrapper::CMutexWrapper(int p_nPrioceiling, int p_nProtocol, int p_nPshared, int p_nType) { int result; pthread_mutexattr_t m_pAttr; pthread_mutexattr_init(&m_pAttr); pthread_mutexattr_setprioceiling(&m_pAttr, p_nPrioceiling); pthread_mutexattr_setprotocol(&m_pAttr, p_nProtocol); pthread_mutexattr_setpshared(&m_pAttr, p_nPshared); if ( ( result = pthread_mutexattr_settype(&m_pAttr, p_nType) ) != 0 ) { NLOG_ERR( "%s, pthread_mutexattr_settype() failed with result %d.", __PRETTY_FUNCTION__, result ); return; } if ( ( result = pthread_mutex_init(&m_oMutex, &m_pAttr) ) != 0 ) { NLOG_ERR( "%s, pthread_mutex_init() failed with result %d.", __PRETTY_FUNCTION__, result ); return; } }
bool CNMS_DBMngt::DeleteNetPrefix(const unsigned char netPrefix[/*16*/]) { IDbSPHelper *pHelper = Connect(); if (pHelper == NULL) return false; pHelper->CreateSPCommand("DeleteNetworkPrefix"); if (!pHelper->AddINParam(1, netPrefix, 16)) { NLOG_ERR("[NMS_DBMngt:DeleteNetPrefix]: failed to add param for sp -> DeleteNetworkPrefix!"); delete pHelper; return false; } if (!pHelper->ExecuteUpdate()) { NLOG_ERR("[NMS_DBMngt:DeleteNetPrefix]: failed to execute update for sp -> DeleteNetworkPrefix!"); delete pHelper; return false; } delete pHelper; return true; }
//INIT bool CSumiUtils::APISendCreateSocket(uint16_t p_u16Port, uint8_t p_u8SerialMsgId, CBufferedSerialLink *p_poBufferedSerialLink) { //msg header API_MSG_HDR *pUDPCreateSockHdr = (API_MSG_HDR*)m_pucSendBuf; SET_API_HDR(pUDPCreateSockHdr, UDP_SPECIFIC, API_MSG_REQ, UDP_CREATE_SOCKET, p_u8SerialMsgId, sizeof(UDP_CREATE_SOCK_PYLD)); //msg payload UDP_CREATE_SOCK_PYLD *pUDPCreateSockPYLD = (UDP_CREATE_SOCK_PYLD*)(m_pucSendBuf + sizeof(API_MSG_HDR)); UDP_CREATE_SOCK_SET_PORT(pUDPCreateSockPYLD, p_u16Port); //check link if( !p_poBufferedSerialLink->IsLinkOpen() ) { NLOG_ERR("LINK NOT OPEN!"); return false; } //send msg int nSentLen = p_poBufferedSerialLink->Write(m_pucSendBuf, sizeof(API_MSG_HDR) + sizeof(UDP_CREATE_SOCK_PYLD)); if ( nSentLen <= 0 ) { NLOG_ERR("FAILED TO SEND UDP_CREATE_SOCKET ON SERIAL LINK!"); return false; } return true; }