示例#1
0
void SmppClient::sendPdu(PDU &pdu)
{
	checkConnection();

	boost::optional<boost::system::error_code> ioResult;
	boost::optional<boost::system::error_code> timerResult;

	if (verbose) {
		*log << pdu;
	}

	deadline_timer timer(getIoService());
	timer.expires_from_now(boost::posix_time::milliseconds(socketWriteTimeout));
	timer.async_wait(boost::bind(&SmppClient::handleTimeout, this, &timerResult, _1));

	async_write(*socket, buffer(pdu.getOctets().get(), pdu.getSize()),
			boost::bind(&SmppClient::writeHandler, this, &ioResult, _1));

	socketExecute();

	if (ioResult) {
		timer.cancel();
	} else if (timerResult) {
		socket->cancel();
	}

	socketExecute();
}
void DecodeCallBack::onDebug ( const PDU& pdu) 
{
    const uint8 *buf = pdu.data ();
    size_t len = pdu.size ();

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

    if (buf[len - 1] == NUL)
    {
        printlf ("debug");
        printlf (" \"");
        while (len--)
        {
            printChar (*buf++);
        }
        printlf ("\"\n");
    }
    else
    {
        printlf ("debug");
        for (; len != 0; --len)
        {
            printlf (" 0x%02x", *buf++);
        }
        printlf ("\n");
    }
#else   
    decodeDebug(buf, len);
#endif
}
示例#3
0
PDU SmppClient::sendCommand(PDU &pdu)
{
	sendPdu(pdu);

	PDU resp = readPduResponse(pdu.getSequenceNo(), pdu.getCommandId());

	switch (resp.getCommandStatus()) {
		case smpp::ESME_RINVPASWD:
			throw smpp::InvalidPasswordException(smpp::getEsmeStatus(resp.getCommandStatus()));
			break;
		case smpp::ESME_RINVSYSID:
			throw smpp::InvalidSystemIdException(smpp::getEsmeStatus(resp.getCommandStatus()));
			break;
		case smpp::ESME_RINVSRCADR:
			throw smpp::InvalidSourceAddressException(smpp::getEsmeStatus(resp.getCommandStatus()));
			break;
		case smpp::ESME_RINVDSTADR:
			throw smpp::InvalidDestinationAddressException(smpp::getEsmeStatus(resp.getCommandStatus()));
			break;
	}

	if (resp.getCommandStatus() != smpp::ESME_ROK) throw smpp::SmppException(
			smpp::getEsmeStatus(resp.getCommandStatus()));

	return resp;
}
示例#4
0
SMS SmppClient::readSms()
{
	// see if we're bound correct.
	checkState(BOUND_RX);

	// if  there are any messages in the queue pop the first usable one off and return it
	if (!pdu_queue.empty()) return parseSms();

	// fill queue until we get a DELIVER_SM command
	try {
		bool b = false;

		while (!b) {
			PDU pdu = readPdu(true);

			if (pdu.getCommandId() == ENQUIRE_LINK) {
				PDU resp = PDU(ENQUIRE_LINK_RESP, 0, pdu.getSequenceNo());
				sendPdu(resp);
				continue;
			}

			if (pdu.null) {
				break;
			}

			if (!pdu.null) pdu_queue.push_back(pdu); // save pdu for reading later
			b = pdu.getCommandId() == DELIVER_SM;
		}
	} catch (std::exception &e) {
		throw smpp::TransportException(e.what());
	}

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

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

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

        if (pa == 0)
        {
            return;
        }

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

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

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

        printlf ("App: received event, code 0x%02x, pa[] =", ec);
        for (i = 2; i < pa[0]; ++i)
        {
            printlf (" 0x%lx", (ul) pa[i]);
        }
        printlf (" [%u args]\n", pa[0] - 2);
#else
        decodeEvt (pa);
#endif
    }
}
示例#6
0
// blocks until response is read
PDU SmppClient::readPduResponse(const uint32_t &sequence, const uint32_t &commandId)
{
	uint32_t response = GENERIC_NACK | commandId;
	list<PDU>::iterator it = pdu_queue.begin();

	while (it != pdu_queue.end()) {
		PDU pdu = (*it);

		if (pdu.getSequenceNo() == sequence && pdu.getCommandId() == response) {
			it = pdu_queue.erase(it);
			return pdu;
		}
		it++;
	}

	while (true) {
		PDU pdu = readPdu(true);
		if (!pdu.null) {
			if ((pdu.getSequenceNo() == sequence
					&& (pdu.getCommandId() == response || pdu.getCommandId() == GENERIC_NACK))
					|| (pdu.getSequenceNo() == 0 && pdu.getCommandId() == GENERIC_NACK)) return pdu;
		}
	}

	PDU pdu;
	return pdu;
}
示例#7
0
void SmppClient::unbind()
{
	checkConnection();
	PDU pdu(smpp::UNBIND, 0, nextSequenceNumber());
	PDU resp = sendCommand(pdu);

	uint32_t pduStatus = resp.getCommandStatus();

	if (pduStatus != smpp::ESME_ROK) throw smpp::SmppException(smpp::getEsmeStatus(pduStatus));

	state = OPEN;
}
示例#8
0
void PacketSender::send_l3(PDU &pdu, struct sockaddr* link_addr, uint32_t len_addr, SocketType type) {
    open_l3_socket(type);
    int sock = _sockets[type];
    PDU::serialization_type buffer = pdu.serialize();
    if(sendto(sock, (const char*)&buffer[0], buffer.size(), 0, link_addr, len_addr) == -1)
        throw socket_write_error(make_error_string());
}
// Send a PDU that requires HCI tunnelling for manufacturer extensions
void BlueCoreTransportImplementation::sendTunnel ( const PDU& aPacket )
{
    if (tunnel)
    {
        uint8 data[HCI_TUNNEL_HEADER_SIZE+HCI_TUNNEL_MAX_PAYLOAD];
        size_t offset = 0;
        while ( offset < aPacket.size() )
        {
			size_t lLength = aPacket.size() - offset;
			while (1)
			{
				// Calculate the payload length and descriptor
				uint8 descriptor = aPacket.channel();
				if (offset == 0)
					descriptor |= HCI_TUNNEL_FIRST;

				if (HCI_TUNNEL_MAX_PAYLOAD < lLength)
					lLength = HCI_TUNNEL_MAX_PAYLOAD;

				if (offset + lLength == aPacket.size())
					descriptor |= HCI_TUNNEL_LAST;

				// Build and send the HCI command for this fragment
				data[0] = uint8(HCI_TUNNEL_COMMAND & 0xff);
				data[1] = uint8(HCI_TUNNEL_COMMAND >> 8);
				data[2] = uint8(lLength + 1);
				data[3] = descriptor;
				memcpy(data + HCI_TUNNEL_HEADER_SIZE, aPacket.data() + offset, lLength);
				PDU p(PDU::hciCommand, data, HCI_TUNNEL_HEADER_SIZE + lLength);
				if (pdu_size_forbidden(p))
				{
					// can't send pdu of this length. try one size smaller.
					--lLength;
				}
				else
				{
					sendpdu(p);
					break;
				}
			}

            offset += lLength;
        }
    }
}
示例#10
0
	bool PacketSenderGeneric::generic_response_handler(PDU& rpdu)
	{
		if (sent_pdu->matches_response_generic(rpdu))
		{
			response_pdu = rpdu.clone();
			return false;
		}
		return true;
	}
void DecodeCallBack::onHCIACLData(const PDU &pdu) 
{
    HCIACLPDU aclpdu(pdu);
#if 0
    uint16 ch = pdu.get_handle ();
    bool pb = pdu.get_pbf () == HCIACLPDU::start;
    BROADCAST_TYPE bf = conv (pdu.get_bct ());
    const uint8 *data = pdu.get_dataPtr ();
    uint16 length = pdu.get_length ();
    unsigned u;

    ASSERT (bf <= 2);

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

    pdd->sendHCIData (ch, pb, bf, data, length);
#else
    {
        
        btcli_enter_critical_section();
        if (fastpipeEngineIsConnected(aclpdu.get_handle()))
        {
            fastpipeEngineReceive(aclpdu);
            btcli_leave_critical_section();
        }
        else
        {
            // Leave critical section before entering aclEngine.
            // AclEngine isn't very hygeinic about its threads, so printlf 
            // (which needs locking) is called from various different threads.
            // CriticalSection::Lock on Linux can't be obtained recursively, so
            // just drop the lock now to make life easier.
            btcli_leave_critical_section();
            aclEngine->receive(aclpdu);
        }
    }
#endif
}
static bool ignoresFlowControl ( const PDU& pdu )
{
    switch ( pdu.channel() )
    {
    case PDU::hciCommand :
        {
        HCICommandPDU cmd ( pdu.data() , pdu.size() );
        switch ( cmd.get_op_code() )
        {
		case HCI_ACCEPT_CONNECTION_REQ:
		case HCI_REJECT_CONNECTION_REQ:
        case HCI_LINK_KEY_REQ_REPLY:
        case HCI_LINK_KEY_REQ_NEG_REPLY:
        case HCI_PIN_CODE_REQ_REPLY:
        case HCI_PIN_CODE_REQ_NEG_REPLY:
		case HCI_ACCEPT_SYNCHRONOUS_CONN_REQ:
		case HCI_REJECT_SYNCHRONOUS_CONN_REQ:
		case HCI_IO_CAPABILITY_RESPONSE:
		case HCI_USER_CONFIRMATION_REQUEST_REPLY:
		case HCI_USER_CONFIRMATION_REQUEST_NEG_REPLY:
		case HCI_USER_PASSKEY_REQUEST_REPLY:
		case HCI_USER_PASSKEY_REQUEST_NEG_REPLY:
		case HCI_REMOTE_OOB_DATA_REQUEST_REPLY:
		case HCI_REMOTE_OOB_DATA_REQUEST_NEG_REPLY:
		case HCI_IO_CAPABILITY_REQUEST_NEG_REPLY:
        case HCI_RESET:
        case HCI_HOST_NUM_COMPLETED_PACKETS:
        case HCI_ULP_LONG_TERM_KEY_REQUESTED_REPLY:
        case HCI_ULP_LONG_TERM_KEY_REQUESTED_NEGATIVE_REPLY:
        case 0xFC00:
            return true;
            break;
        default:
            break;
        }
        break;
        }
    default:
        break;
    };
    return false;
}
void DecodeCallBack::onLMPdebug(const PDU &pdu)
{
    const uint8 *buf = pdu.data ();
    size_t len = pdu.size ();

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

    printlf ("lmp");
    for (; len != 0; --len)
    {
        printlf (" 0x%02x", *buf++);
    }
    printlf ("\n");
#else
    decodeLMPdebug (buf, len, NULL);
#endif
}
void DecodeCallBack::onHQRequest(const PDU &pdu) 
{
    BadPDUReason failCode;

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

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

        if (pa == 0)
        {
            return;
        }

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

        printlf ("App: received hq indication; cmd 0x%lx with seqno 0x%lx, status %lu, pa[] =", (ul) pa[1], (ul) pa[2], (ul) pa[3]);
        for (i = 4; i < pa[0]; ++i)
        {
            printlf (" 0x%lx", (ul) pa[i]);
        }
        printlf (" [%u args]\n", pa[0] - 4);
#else
        decodeHQ (pa);
#endif
    }
}
示例#15
0
void PacketSender::send_l2(PDU &pdu, struct sockaddr* link_addr, 
  uint32_t len_addr, const NetworkInterface &iface) 
{
    int sock = get_ether_socket(iface);
    PDU::serialization_type buffer = pdu.serialize();
    if(!buffer.empty()) {
        #if defined(BSD) || defined(__FreeBSD_kernel__)
        if(::write(sock, &buffer[0], buffer.size()) == -1)
        #else
        if(::sendto(sock, &buffer[0], buffer.size(), 0, link_addr, len_addr) == -1)
        #endif
            throw socket_write_error(make_error_string());
    }
}
示例#16
0
bool InfoWriter::callback(PDU& pdu) {
    QString info = "", src_addr = "", dst_addr = "";
    QString detailInfo;
    QString rawInfo = getRawString(&pdu);
    bool foundOurPDUs = false;

    if (EthernetII *eth = pdu.find_pdu<EthernetII>()) {
        info = "EthernetII";
        detailInfo += getEthernetIIString(eth) + "\r\n";
        src_addr = QString::fromStdString(eth->src_addr().to_string());
        dst_addr = QString::fromStdString(eth->dst_addr().to_string());
    }
    if (IPv6 *ipv6 = pdu.find_pdu<IPv6>()) {
        info = "IPv6";
        detailInfo += getIpv6String(ipv6) + "\r\n";
        src_addr = QString::fromStdString(ipv6->src_addr().to_string());
        dst_addr = QString::fromStdString(ipv6->dst_addr().to_string());
    }
    if (IP *ip = pdu.find_pdu<IP>()) {
        info = "IP";
        detailInfo += getIpString(ip) + "\r\n";
        src_addr = QString::fromStdString(ip->src_addr().to_string());
        dst_addr = QString::fromStdString(ip->dst_addr().to_string());
    }
    if (ICMP *icmp = pdu.find_pdu<ICMP>()) {
        info = "ICMP";
        detailInfo += getIcmpString(icmp) + "\r\n";
        foundOurPDUs = true;
    } else if (UDP *udp = pdu.find_pdu<UDP>()) {
        info = "UDP";
        detailInfo += getUdpString(udp) + "\r\n";
        foundOurPDUs = true;
    } else if (TCP *tcp = pdu.find_pdu<TCP>()) {
        info = "TCP";
        detailInfo += getTcpString(tcp) + "\r\n";
        foundOurPDUs = true;
    }
    if (foundOurPDUs) {
        if (RawPDU *rawpdu = pdu.find_pdu<RawPDU>())
            detailInfo += getData(rawpdu);
        pduVector->push_back(StringPacket(rawInfo,detailInfo));

        int length = pdu.size();
        QStringList row;
        row << src_addr << dst_addr << info << QString::number(length);
        emit addRow(row);
    }
    return true;
}
void DecodeCallBack::onPDU ( const PDU& pdu)
{
    switch (pdu.channel())
    {
    case PDU::other:
        break;
    case PDU::le:
        break;    
    case PDU::bccmd:
        onBCCMDResponse(pdu);
        break;
    case PDU::hq:
        onHQRequest(pdu);
        break;
    case PDU::dm:
        break;
    case PDU::hciCommand:
        onHCIEvent(pdu);
        break;
    case PDU::hciACL:
        onHCIACLData(pdu);
        break;
    case PDU::hciSCO:
        onHCISCOData(pdu);
        break;
    case PDU::l2cap:
        break;
    case PDU::rfcomm:
        break;
    case PDU::sdp:
        break;
    case PDU::debug:
        onDebug(pdu);
        break;
    case PDU::upgrade:
        break;
    case PDU::vm:
        onVMData(pdu);
        break;
    case PDU::bcsp_channel_count:
        break;
    case PDU::lmp_debug:
        onLMPdebug(pdu);
        break;
    default:
        break;
    }
}
示例#18
0
void PacketWriter::write(PDU &pdu) {
    PDU::serialization_type buffer = pdu.serialize();
    timeval tm;
    #ifndef _WIN32
        gettimeofday(&tm, 0);
    #else
        // fixme
        tm = timeval();
    #endif
    struct pcap_pkthdr header = { 
        tm,
        static_cast<bpf_u_int32>(buffer.size()),
        static_cast<bpf_u_int32>(buffer.size())
    };
    pcap_dump((u_char*)dumper, &header, &buffer[0]);
}
示例#19
0
void PacketSender::send(PDU &pdu, const NetworkInterface &iface) {
    PDU::PDUType type = pdu.pdu_type();
    switch(type) {
        case PDU::ETHERNET_II:
            send<Tins::EthernetII>(pdu, iface);
            break;
        #ifdef HAVE_DOT11
            case PDU::DOT11:
                send<Tins::Dot11>(pdu, iface);
                break;
            case PDU::RADIOTAP:
                send<Tins::RadioTap>(pdu, iface);
                break;
        #endif // HAVE_DOT11
        case PDU::IEEE802_3:
            send<Tins::IEEE802_3>(pdu, iface);
            break;
        default:
            send(pdu);
    };
}
void H4Queues::addNewPacket(const PDU &pdu, uint8 h4HeaderByte, bool needCallback)
{
#ifdef H4_MULTIQUEUE
	int queuenum;
	// Search for an ordered Q of this type, if none is found then 
	// queuenum is left at the last unordered Q.
    for (queuenum = 0; queuenum < H4_NUM_ORDERED_QUEUES; ++queuenum)
		if (queue[queuenum].pktType == pdu.channel())
			break;
#endif

    CriticalSection::Lock here(cs);

#ifdef H4_MULTIQUEUE
	queue[queuenum].list.push(H4_QUEUE::QueueItem(pdu, h4HeaderByte, needCallback));
#else
	queue.list.push(H4_QUEUE::QueueItem(pdu, h4HeaderByte, needCallback));
#endif

	++packetCount;
}
示例#21
0
void smpp::SmppClient::enquireLinkRespond()
{
	list<PDU>::iterator it = pdu_queue.begin();

	while (it != pdu_queue.end()) {
		PDU pdu = (*it);
		if (pdu.getCommandId() == ENQUIRE_LINK) {
			PDU resp = PDU(ENQUIRE_LINK_RESP, 0, pdu.getSequenceNo());
			sendCommand(resp);
		}
		it++;
	}

	PDU pdu = readPdu(false);

	if (!pdu.null && pdu.getCommandId() == ENQUIRE_LINK) {
		PDU resp = PDU(ENQUIRE_LINK_RESP, 0, pdu.getSequenceNo());
		sendPdu(resp);
	}
}
bool OfflinePacketFilter::matches_filter(PDU& pdu) const {
    PDU::serialization_type buffer = pdu.serialize();
    return matches_filter(&buffer[0], static_cast<uint32_t>(buffer.size()));
}
示例#23
0
bool Session::snmpGetInternal( int getType, const IdentifierList &identifiers, ValueMap &variables, ErrorInfo *error )
{
    if ( !d->initialized && !initialize( error ) )
        return false;

    bool result = false;

    if ( getType != SNMP_MSG_GETNEXT && d->session ) {
        SnmpLib::self()->snmp_close( d->session );
        d->session = 0;
    }

    if ( getType != SNMP_MSG_GETNEXT ||
         !d->session ) {

        if ( ( d->session = SnmpLib::self()->snmp_open( &d->defaultSession ) ) == 0 ) {
            if ( error )
                *error = ErrorInfo( sessionErrorCode( d->defaultSession ) );
            return false;
        }
    }

    PDU request( getType );
    PDU response;

    request.addNullVariables( identifiers );

    int status = SnmpLib::self()->snmp_synch_response( d->session, request.release(), &response );

    if ( status == STAT_SUCCESS ) {

        if ( response.hasError() ) {

            if ( error )
                *error = ErrorInfo( response.errorCode() );

        } else {

            variables = response.variables();
            result = true;

            if ( error )
                *error = ErrorInfo( ErrorInfo::NoError );
        }

    } else if ( status == STAT_TIMEOUT ) {

        if ( error )
            *error = ErrorInfo( ErrorInfo::ErrTimeout );

    } else {

        if ( error )
            *error = ErrorInfo( sessionErrorCode( *d->session ) );

    }

    if ( getType != SNMP_MSG_GETNEXT ) {
        SnmpLib::self()->snmp_close( d->session );
        d->session = 0;
    }

    return result;

}
/*virtual*/ void BCSPH5Transport::recvOther(const PDU &aPacket)
{
	recvData(aPacket.channel(), aPacket.data(), aPacket.size());
}
示例#25
0
void PacketSender::send(PDU &pdu) {
    pdu.send(*this, default_iface);
}
示例#26
0
文件: pdu.cpp 项目: Imva/libtins
void PDU::inner_pdu(const PDU &next_pdu) {
    inner_pdu(next_pdu.clone());
}
示例#27
0
文件: pdu.cpp 项目: Imva/libtins
void PDU::copy_inner_pdu(const PDU &pdu) {
    if(pdu.inner_pdu())
        inner_pdu(pdu.inner_pdu()->clone());
}
示例#28
0
bool PacketCapturer::callback(const PDU& pdu) {
    storage_.emplace_back(pdu.clone());
    return running_;
}