Example #1
0
//! Creating OSERVCE__CLIENT_ONLINE packet
//! \return
//! \sa QOscarBA
QOscarBA QOscarOService::createOSERVICE__CLIENT_ONLINE()
{
    QOscarBA ba(createPacket(0x0001, 0x0004, 0x0110, 0x08E4));
    ba.append(createPacket(0x0013, 0x0004, 0x0110, 0x08E4));
    ba.append(createPacket(0x0002, 0x0004, 0x0110, 0x08E4));
    ba.append(createPacket(0x0003, 0x0004, 0x0110, 0x08E4));
    ba.append(createPacket(0x0015, 0x0004, 0x0110, 0x08E4));
    ba.append(createPacket(0x0004, 0x0004, 0x0110, 0x08E4));
    ba.append(createPacket(0x0006, 0x0004, 0x0110, 0x08E4));
    ba.append(createPacket(0x0009, 0x0004, 0x0110, 0x08E4));
    ba.append(createPacket(0x000A, 0x0004, 0x0110, 0x08E4));
    ba.append(createPacket(0x000B, 0x0004, 0x0110, 0x08E4));

    return QSnac::toByteArray(0x0001, 0x0002, 0x00, 0x00, ba);
}
Example #2
0
void Message::prepare()
{
	if( !packet ) createPacket();

	size_t totalSize = (size_t) ms->position;

	size_t bufSize = GetCompressionBufferSize(totalSize);
	enet_packet_resize(packet, bufSize);

	MemoryStream pms;
	StreamMemoryInit(&pms);
	StreamMemorySetRawBuffer(&pms, packet->data);

	EncodeVariableInteger(&pms, id);
	StreamWrite(&pms, &flags, sizeof(flags));
	
	if( GetBitFlag(flags, MessageFlags::Compressed) )
	{
		uint8* in = &ms->data[0];
		uint8* out = pms.buffer + pms.position;
		int32 length = fastlz_compress_level(1, in, totalSize, out);
		pms.position += length;
	}
	else
	{
		enet_packet_resize(packet, totalSize + pms.position);
		StreamWrite(&pms, &ms->data[0], totalSize);
	}

	packet->dataLength = (size_t) pms.position;
}
Example #3
0
static void runTX(char c1, char c2, char c3, char c4)
{
  // Initialize packet buffer of size PKTLEN + 1
  uint8 txBuffer[PKTLEN+1] = {0};

   P2SEL &= ~0x40; // P2SEL bit 6 (GDO0) set to one as default. Set to zero (I/O)
  // connect ISR function to GPIO0, interrupt on falling edge
  trxIsrConnect(GPIO_0, FALLING_EDGE, &radioRxTxISR);

  // enable interrupt from GPIO_0
  trxEnableInt(GPIO_0);

	// create a random packet with PKTLEN + 2 byte packet counter + n x random bytes
	createPacket(txBuffer, c1, c2, c3, c4);

  // write packet to tx fifo
  cc11xLSpiWriteTxFifo(txBuffer,sizeof(txBuffer));

  // strobe TX to send packet
  trxSpiCmdStrobe(CC110L_STX);

	// wait for interrupt that packet has been sent.
	// (Assumes the GPIO connected to the radioRxTxISR function is set
	// to GPIOx_CFG = 0x06)
	while(!packetSemaphore);

	// clear semaphore flag
	packetSemaphore = ISR_IDLE;

  halLedToggle(LED1);
   __delay_cycles(250000);
   halLedToggle(LED1);
}
Example #4
0
// sender uses the function
int send_file(int sock, struct sockaddr_in *recv_adr, char *filename, akh_disconn_response *disconn_response)
{
    uint32_t seg_size = disconn_response->segment_size;
    uint32_t req_num = disconn_response->segment_num;
    uint32_t *seg_list = disconn_response->segment_list;
    uint32_t seg_num;

    akh_pdu_header header;
    char buf[MAX_BUFFER_SIZE];
    packet pac;
    size_t buf_len, pac_len;

    int i;
    for(i = 0; i < req_num; i++) {
        seg_num = seg_list[i];
        header = createHeader(SS, seg_num);
        buf_len = read_segment(buf, seg_size, seg_num, filename);
        pac_len = createPacket(&pac, &header, buf, buf_len);
        sendto(sock, pac, pac_len, 0, (struct sockaddr *)recv_adr, sizeof(*recv_adr));

        deletePacket(pac);

        puts("< send file segment >");
        displayHeader(header);
    }
    return 0;
}
Example #5
0
void client_printer()
{
 	Message_t msg, reply;
    int reply_port, status, i, received = 0;
    char * all_strings;

    reply_port = getCurrentThreadId();

    openPort(reply_port);

    msg = (Message_t)malloc(sizeof(struct message));
    reply = (Message_t)malloc(sizeof(struct message));

    srand(getCurrentThreadId());

    while(1)
    {
        if(rand() % 3 == 0)
        {
            createPacket(msg, PRINT, 10, 0);

            printf("\n[Client_on_port_%d]:Sent message:\t", getCurrentThreadId());
            if((status = Send(SERVER_PORT, msg))<0)
            {
                     printf("\n[Client_%d]:Send error",getCurrentThreadId());
                     exit(-1);
            }

            if((status = Receive(reply_port, reply))<0)
            {
                printf("\n[Client_%d]:Receive error",getCurrentThreadId());
                exit(-1);
            }

            all_strings = malloc((reply->total_size) * sizeof(char));

            while(reply->error_code == 1)
            {
                for(i = 0; i < MESSAGE_LENGTH; i++)
                    all_strings[received++] = reply->msg[i];

                if((status = Receive(reply_port, reply))<0)
                {
                    printf("\n[Client_%d]:Receive error",getCurrentThreadId());
                    exit(-1);
                }

            }
			if(reply->error_code != -1)
			{
				i=0;
				while(received < reply->total_size)
					all_strings[received++] = reply->msg[i++];

				printf("Table Entries: \n %s", all_strings);
			}
        }
    }

}
Example #6
0
void Packet::prepare()
{
	if( !packet ) createPacket();

	size_t totalSize = (size_t) ms.getPosition();

	size_t bufSize = GetCompressionBufferSize(totalSize);
	enet_packet_resize(packet, bufSize);

	MemoryStream pms;
	pms.setRawBuffer(packet->data);

	EncodeVariableInteger(&pms, id);
	pms.write((uint8*) &flags, sizeof(flags));
	
	if( GetBitFlag(flags, PacketFlags::Compressed) )
	{
		uint8* in = ms.data.Buffer();
		uint8* out = pms.buffer + pms.position;
		int32 length = fastlz_compress_level(1, in, totalSize, out);
		pms.position += length;
	}
	else
	{
		enet_packet_resize(packet, totalSize + pms.position);
		pms.write(ms.data.Buffer(), totalSize);
	}

	packet->dataLength = (size_t) pms.position;
}
Example #7
0
maanet::packet* maaPacketStreamer::decode(maanet::dataBuffer* input, maanet::packetHeader* header ) {
	if (input == NULL || header == NULL) {
		return NULL;	
	}

	//解析不出来头,则是纯代理数据	
	if (header->dataLen == 0) {
		header->dataLen = input->getDataLen();	
		if (pattern == 1 ) {		
			header->type = 2;
		} else if (pattern == 3) {	
			header->type = 3;
		}	
	}	

	maanet::packet* _packet = createPacket(input, header);
	if (_packet != NULL) {
		if (!_packet->decode(input, header)) {
			_packet->free();
			_packet = NULL;
		}
	} else {
		input->drainData(header->dataLen);
	}

	return _packet;
}
Example #8
0
void Packet::registerPacketClass( PClassType eType, PacketCreateFuncType createFunc, const char* szClassName ) 
{
	UT_return_if_fail( !createPacket(eType) ); // if this fails, we have a duplicate eType registration
	ClassData cd;
	cd.StaticConstructor = createFunc;
	cd.ClassName = szClassName;
	GetClassMap()[eType] = cd;
}
Example #9
0
int main() {
	Packet *packet = createPacket();
	if (packet != NULL) {
		destroyPacket(&packet);
		handlePacket(packet);
	}
	return 0;
}
Example #10
0
UdpOutPacket *UdpSession::createPacket(uint16 cmd, uint16 ackseq)
{
	UdpOutPacket *p = new UdpOutPacket;
	p->cmd = cmd;
	p->seq = ++sendSeq;
	createPacket(*p, cmd, sendSeq, ackseq);
	return p;
}
Example #11
0
//FONCTION : envoie le message à tous les clients
void Server::sendToAll(const QString &message)
{
    QByteArray paquet=createPacket(message);

    for (int i = 0; i < clients.size(); i++)
    {
        clients[i].sock->write(paquet);
    }
    qDebug() << "SENDING TO ALL " << message;
}
Example #12
0
void* arriveThread(void* arg)
{
	useconds_t sleepTime; //time to sleep
	TimeVal startTime, endTime;
	
	int emptyFlag;
	int waitingTime;

	sleepTime = -1;
	emptyFlag = -1;
	waitingTime = -1;

	while(TRUE)
	{
		if(-1 == usleep(sleepTime))
		{
			printf("something wrong with usleep\n");
		}

		gettimeofday(&startTime, &tz);

		Packet* p = createPacket();

		if(p->requiredToken > g_tokenSize)
			continue;


		// ******start critical section*************
		pthread_mutex_lock(&m);
		emptyFlag = MyQueueEmpty(&arrivalQueue);
		MyQueueEnqueue(&arrivalQueue, (void*)p);

		if (emptyFlag && p->requiredToken <= g_tokens)
		{
			g_tokens -= p->requiredToken;
			MyQueueDequeue(&arrivalQueue);
			MyQueueEnqueue(&serverQueue, (void*)p);

			if( 1 == My402ListLength(&serverQueue.list))
			{
				pthread_cond_signal(&newPacketToServer);
			}

		}
		pthread_mutex_unlock(&m);
		// *********end critical section*************
		gettimeofday(&endTime, &tz);


		// read file here if needed
		sleepTime = waitingTime - diff2Timeval(startTime, endTime);


	}
}
Example #13
0
bool ESP8266::sendData (char * data, PacketType type, CmdType cmd ){

	//DataPacket packet =
	createPacket();
	_sendingPacket.type = type;
	_sendingPacket.cmd = cmd;
	strcpy(_sendingPacket.data,  data);

	//return sendData(packet);

	return sendData(_sendingPacket);
}
Example #14
0
void sendValues(void){
	char packet[162];

	createPacket(packet);

	if(uart1_check_free_space(162)){
		int i;
		for(i=0;i<162;i++){
			downlink_send(packet[i]);
		}
	}

}
Example #15
0
//FONCTION : envoie le message à tous les clients
void Server::sendToAllConnected(const QString &message)
{
    QByteArray paquet=createPacket(message);

    for (int i = 0; i < clients.size(); i++)
    {
        if(clients[i].isSending)
        {
            clients[i].sock->write(paquet);
        }
    }
    qDebug() << "SENDING TO ALL CONNECTED" << message;
}
Example #16
0
void client()
{
	Message_t msg, reply;
	int reply_port, status, code, func, packet_no = 0;
	char precoded_string[15] = "+++--*+*-+--*-*";
	int op = 0;
	reply_port = getCurrentThreadId();

	openPort(reply_port);

	msg = (Message_t)malloc(sizeof(struct message));
    reply = (Message_t)malloc(sizeof(struct message));

    srand(getCurrentThreadId());

	while(1)
	{
		if(precoded_string[op] == '+')
			func = ADD;
		else if(precoded_string[op] == '-')
			func = DELETE;
		else
			func = MODIFY;

		do
		{
			code = createPacket(msg, func, rand() % 10, packet_no++);
			printf("\n[Client_on_port_%d]:Sent message:\t", getCurrentThreadId());
			if((status = Send(SERVER_PORT, msg))<0)
			{
                 printf("\n[Client_%d]:Send error",getCurrentThreadId());
                 exit(-1);
			}
			if((status = Receive(reply_port, reply))<0)
			{
				printf("\n[Client_%d]:Receive error",getCurrentThreadId());
				exit(-1);
			}
			if(reply->error_code == -1) break;
		}while(code);

		if(++op == 15)
			op=0;

		packet_no = 0;
		sleep(1);
	}
	closePort(reply_port);
}
Example #17
0
//deal with its communication with sender later.
void *application()
{
    FILE *ptr_file;
    char buf[1000];
    ptr_file = fopen("reluctance.txt","r");
    int seq = 0;
    int curr_index = 0;
    int sent = 0;
    
    if (!ptr_file){
        perror("opening file failed");
        exit(1);
    }
    
    printf("Application: I'm reading to start sending.\n\n");
    while (fgets(buf, 1000, ptr_file) != NULL){ //read til new line
        struct packet * new_packet = malloc(sizeof(struct packet));
        createPacket(new_packet, buf, seq);
        buffer[curr_index] = new_packet;
        
        sent++;
        num_in_buffer++; //number in the queue. This tells the sender to start sending.
        curr_index = (curr_index + 1) % BUFF_SIZE;
        seq = ((seq + 1) % (wsize * 2)); //update seq #
        
        while(sent >= can_send); //hang until receiver tells us that we can go
    }
    
    //send DONE packet
    char * g = "Client: DONE!\n";
    struct packet * newpacket = malloc(sizeof(struct packet));
    createPacket(newpacket, g , -1);
    buffer[curr_index] = newpacket;
    sent++;
    num_in_buffer++;
}
Example #18
0
bool TcpSession::onTcpEstablished()
{
	status = TCP_STATUS_ESTABLISHED;

	if (listener && listener->onTcpEstablished())
		return true;

	OutPacket *p = createPacket(TCP_HELLO);
	*p << (uint8) isSend;
	sendDirect(p);
	delete p;

	createPlugin();
	return true;
}
Example #19
0
bool KovanModule::send(const CommandVector& commands)
{
	uint32_t packetSize = 0;
	Packet *packet = createPacket(commands.size(), packetSize);
	memcpy(packet->commands, &commands[0], commands.size() * sizeof(Command));
	
	bool ret = true;
	if(sendto(m_sock, packet, packetSize, 0, (sockaddr *)&m_out, sizeof(m_out)) != packetSize) {
		perror("sendto");
		ret = false;
	}
	
	free(packet);
	return ret;
}
Example #20
0
int NTPClient::send()
{
  if (m_udp == NULL)
    return 0;

  createPacket();
  IPAddress address(m_address);

  // all NTP fields have been given values, now
  // you can send a packet requesting a timestamp:
  m_udp->beginPacket(address, 123); //NTP requests are to port 123
  //Serial.println("4");
  m_udp->write(m_packetBuffer, NTP_PACKET_SIZE);
  //Serial.println("5");
  return m_udp->endPacket();
}
Example #21
0
void advertise(int udp , int senderId, int numLinks, int numFiles){
	node* curr = routing.head;
	char* ptr;
	
	while( curr != NULL ){
		routingEntry* re = (routingEntry*)curr->data;
		if (re->isNeighbor){
			
			
			struct sockaddr_in cli_addr;
			struct hostent *h;
			
			if((h = gethostbyname(re->hostName))==NULL) {
				printf("error resolving host\n");
				return;
			}
			memset(&cli_addr, '\0', sizeof(cli_addr));
			cli_addr.sin_family = AF_INET;
			cli_addr.sin_addr.s_addr = *(in_addr_t *)h->h_addr;
			cli_addr.sin_port = htons(re->routingPort);
			
			char* sendBuf = createPacket(numLinks, numFiles);
			ptr = addHeader(sendBuf, '1', senderId, re->seqNumSend, numLinks, numFiles);
			printBuf(sendBuf, ptr-sendBuf+1);
			//printf("Header length is %ld\n", ptr-sendBuf+1);
			ptr = addNodeIds(ptr, senderId);
			printBuf(sendBuf, ptr-sendBuf+1);
			//printf("header + Nodes length is %ld\n", ptr-sendBuf+1);
			ptr = addFiles(ptr);
			int packetSize = ptr-sendBuf+1;
			printf("The packet length is %d\n",packetSize );
			
			printBuf(sendBuf, packetSize);
			char* tmp = "ssdsds";
			ssize_t sen;
			sen = sendto(udp, sendBuf,packetSize, 0, (struct sockaddr *)&cli_addr, sizeof(cli_addr));
			//printf("Send to node %d on port %d\n", re->nodeId, re->routingPort);
			if(sen <= 0 ){
				printf("This is really bad\n");
			}
			
			
			
		}
		curr = curr->next;
	}
}
Example #22
0
int main(){
	rsfd=createRawSocket(55);
    
    char msg[25];
    sprintf(msg, "%s", "This is message!!");
    int l=strlen(msg);
    msg[l]='\0';

    char optional[25];
    sprintf(optional, "%s", "This is optional!!");
   	l=strlen(optional);
    optional[l]='\0';

    char datagram[BUFF];
    createPacket(datagram, msg, optional);

    sendPacket(datagram);

    return 0;
}
Example #23
0
size_t WwRIFFVorbisStream::readBuffer(int16 *buffer, const size_t numSamples) {
	size_t samples = 0;
	while (samples < numSamples) {
		const size_t needSamples = numSamples - samples;
		const size_t gotSamples  = _vorbis->readBuffer(buffer, needSamples);

		buffer  += gotSamples;
		samples += gotSamples;

		if (gotSamples < needSamples) {
			Common::ScopedPtr<Common::SeekableReadStream> packet(createPacket());
			if (!packet) {
				_end = true;
				break;
			}

			_vorbis->queuePacket(packet.release());
		}
	}

	return samples;
}
Example #24
0
 Packet::Packet(const ByteArray& packet) : data(new ByteArray())
 {
   createPacket(packet);
 }
Example #25
0
 Packet::Packet(CommandType cmd, const ByteArray& inputData) : data(new ByteArray())
 {
   createPacket(cmd, inputData);
 }
Example #26
0
void UdpSession::sendAckPacket(uint16 seq)
{
	UdpOutPacket out;
	createPacket(out, UDP_ACK, seq);
	sendDirect(&out);
}
Example #27
0
void CWOP::main()
{
   char buf[255];
   while( threadRunning )
   {
      pthread_mutex_lock( &notify );
      if ( !threadRunning )
      {
         dbg.printf(NOTICE, "Exiting\n");
         return;
      }

      if ( !wd->now->isNewMinute() || wd->now->getMinute() % 10 != cfg.getInteger("cwop_ul_min"))
      {
         dbg.printf(DEBUG, "Not on minute bounary\n");
         continue;
      }

      if ( cfg.getInteger("test_only") != 1 )
      {
         createPacket();
         int randSleepTime = random() % 10;
         dbg.printf(DEBUG, "Sleeping %d seconds before sending data\n", randSleepTime );
         sleep( randSleepTime );
         char serverName[64];
         if ( !connectToServer( serverName, 64) )
         {
            dbg.printf(NOTICE, "Could not connect to any CWOP server\n");
            continue;
         }

         dbg.printf(DEBUG, "sending data to CWOP (%s)\n", serverName);
         if ( !receiveFromServer( buf, 20, 255 ) )
         {
            dbg.printf(ERR, "Could not read from server\n");
            close(sock);
            continue;
         }
         // Check if this is a real APRS server
         for ( int i = 0; i < 20; i++ )
         {
            if ( isalpha(buf[i]) )
               buf[i] = tolower( buf[i] );
         }

         if ( strstr( buf, "aprs" ) == 0 )
         {
            dbg.printf(ERR, "Expected '*aprs*', received: %s\n", buf );
            close( sock );
            continue;
         }

         if ( sendToServer( login ) != -1 )
         {
            if (!receiveFromServer( buf, 25, 255 ))
            {
               dbg.printf(ERR, "Could not read from server\n");
               close(sock);
               continue;
            }

            sendToServer( packet );
         }
         close( sock );
      }
      else
      {
         dbg.printf(NOTICE, "pretending: CWOP data uploading to %s\n", cfg.getString("cwop_server").c_str());
      }
   }
}
Example #28
0
//FONCTION : Envoie à la socket le message
void Server::sendToClient(const QString &message,QTcpSocket*socket)
{
    socket->write(createPacket(message));
    qDebug() << "SENDING " << message;
}
Example #29
0
cServerPacket* cBasicMenu::build()
{
	return createPacket();
}
Example #30
0
void ServerSession::sendKeepAlive()
{
	UdpOutPacket *out = createPacket(UDP_KEEPALIVE);
	sendPacket(out);
}