Beispiel #1
0
static __u16 capi_put_message(__u16 applid, struct sk_buff *skb)
{
	avmb1_ncci *np;
	int contr;
	if (ncards == 0)
		return CAPI_REGNOTINSTALLED;
	if (!VALID_APPLID(applid))
		return CAPI_ILLAPPNR;
	if (skb->len < 12
	    || !capi_cmd_valid(CAPIMSG_COMMAND(skb->data))
	    || !capi_subcmd_valid(CAPIMSG_SUBCOMMAND(skb->data)))
		return CAPI_ILLCMDORSUBCMDORMSGTOSMALL;
	contr = CAPIMSG_CONTROLLER(skb->data);
	if (!VALID_CARD(contr) || CARD(contr)->cardstate != CARD_RUNNING) {
		contr = 1;
	        if (CARD(contr)->cardstate != CARD_RUNNING) 
			return CAPI_REGNOTINSTALLED;
	}
	if (CARD(contr)->blocked)
		return CAPI_SENDQUEUEFULL;

	if (   CAPIMSG_COMMAND(skb->data) == CAPI_DATA_B3
	    && CAPIMSG_SUBCOMMAND(skb->data) == CAPI_REQ
	    && (np = find_ncci(APPL(applid), CAPIMSG_NCCI(skb->data))) != 0
	    && mq_enqueue(np, CAPIMSG_MSGID(skb->data)) == 0)
		return CAPI_SENDQUEUEFULL;

	B1_send_message(CARD(contr)->port, skb);
	return CAPI_NOERROR;
}
Beispiel #2
0
/*************************************************************************
 * will be called by post_net, etc functions to send message             *
 *************************************************************************/
void radio_msg_alloc(Message *msg)
{
	HAS_CRITICAL_SECTION;
	uint16_t sleeptime = 0;
	uint8_t resend_pack = 1;

	ENTER_CRITICAL_SECTION();

	if( Radio_Check_CCA() ) {
		incSeq();
		if(radio_msg_send(msg))
		{
			resend_pack = 0;
			msg_send_senddone(msg, 1, RADIO_PID);
		}
	}
	
	if(resend_pack)
	{
		if( getMsgNumOfQueue() < MAX_MSGS_IN_QUEUE )		//queue is full?
		{
			mq_enqueue(&vmac_pq, msg);
			ENTER_CRITICAL_SECTION(); // most probably mq_enqueue calls LEAVE_CRITICAL_SECTION somewhere!
		}
		else
		{
			msg_send_senddone(msg, 0, RADIO_PID);		//release the memory for the msg
			ENTER_CRITICAL_SECTION(); // most probably msg_send_senddone calls LEAVE_CRITICAL_SECTION somewhere!
		}
		sleeptime = MacBackoff_congestionBackoff(retry_count);
		ker_timer_restart(RADIO_PID, WAKEUP_TIMER_TID, sleeptime);	// setup backoff timer
	}

	LEAVE_CRITICAL_SECTION();
}
Beispiel #3
0
static __u16 capi_put_message(__u16 applid, struct sk_buff *skb)
{
	struct capi_ncci *np;
	__u32 contr;
	int showctl = 0;
	__u8 cmd, subcmd;

	if (ncards == 0)
		return CAPI_REGNOTINSTALLED;
	if (!VALID_APPLID(applid))
		return CAPI_ILLAPPNR;
	if (skb->len < 12
	    || !capi_cmd_valid(CAPIMSG_COMMAND(skb->data))
	    || !capi_subcmd_valid(CAPIMSG_SUBCOMMAND(skb->data)))
		return CAPI_ILLCMDORSUBCMDORMSGTOSMALL;
	contr = CAPIMSG_CONTROLLER(skb->data);
	if (!VALID_CARD(contr) || CARD(contr)->cardstate != CARD_RUNNING) {
		contr = 1;
	        if (CARD(contr)->cardstate != CARD_RUNNING) 
			return CAPI_REGNOTINSTALLED;
	}
	if (CARD(contr)->blocked)
		return CAPI_SENDQUEUEFULL;

	cmd = CAPIMSG_COMMAND(skb->data);
        subcmd = CAPIMSG_SUBCOMMAND(skb->data);

	if (cmd == CAPI_DATA_B3 && subcmd== CAPI_REQ) {
	    	if ((np = find_ncci(APPL(applid), CAPIMSG_NCCI(skb->data))) != 0
	            && mq_enqueue(np, CAPIMSG_MSGID(skb->data)) == 0)
			return CAPI_SENDQUEUEFULL;
		CARD(contr)->nsentdatapkt++;
		APPL(applid)->nsentdatapkt++;
	        if (CARD(contr)->traceflag > 2) showctl |= 2;
	} else {
		CARD(contr)->nsentctlpkt++;
		APPL(applid)->nsentctlpkt++;
	        if (CARD(contr)->traceflag) showctl |= 2;
	}
	showctl |= (CARD(contr)->traceflag & 1);
	if (showctl & 2) {
		if (showctl & 1) {
			printk(KERN_DEBUG "kcapi: put [0x%lx] id#%d %s len=%u\n",
			       (unsigned long) contr,
			       CAPIMSG_APPID(skb->data),
			       capi_cmd2str(cmd, subcmd),
			       CAPIMSG_LEN(skb->data));
		} else {
			printk(KERN_DEBUG "kcapi: put [0x%lx] %s\n",
					(unsigned long) contr,
					capi_message2str(skb->data));
		}

	}
	CARD(contr)->driver->send_message(CARD(contr), skb);
	return CAPI_NOERROR;
}
Beispiel #4
0
Datei: sched.c Projekt: nesl/umpu
void sched_msg_alloc(Message *m)
{
  if(flag_msg_release(m->flag)){
		ker_change_own(m->data, KER_SCHED_PID);
  }	
	DEBUG("sched_msg_alloc\n");
  mq_enqueue(&schedpq, m);	
	return;
}
Beispiel #5
0
int test_is_empty() {
  message_queue* mq = NULL;
  mq_allocate(&mq);
  MessageEnvelope* env = (MessageEnvelope*)malloc(sizeof(MessageEnvelope));
  mq_enqueue(env, mq);
  if (mq_is_empty(mq)) { return 0; }
  mq_free(&mq);
  return 1;
}
Beispiel #6
0
/*===========================================================================*
 *				blockdriver_mq_queue			     *
 *===========================================================================*/
PUBLIC int blockdriver_mq_queue(message *m, int status)
{
/* Queue a message for later processing. */

  return mq_enqueue(SINGLE_THREAD, m, status);
}
Beispiel #7
0
/**
 * @brief allocate send buffer
 */
void radio_msg_alloc(Message *m)
{
	int sock = send_sock;
	struct sockaddr_in name;
	Message *txmsgptr = m;    //!< pointer to transmit buffer
	HAS_CRITICAL_SECTION;

	//! change ownership
	if(flag_msg_release(m->flag)){
		ker_change_own(m->data, RADIO_PID);
	}
	DEBUG("Radio: Got packet to send\n");

	ENTER_CRITICAL_SECTION();

	if(txmsgptr->type == MSG_TIMESTAMP)
	{ 
		uint32_t timestamp = ker_systime32();
		memcpy(txmsgptr->data, (uint8_t*)(&timestamp),sizeof(uint32_t));  
	}


	name.sin_family = AF_INET;
	name.sin_addr.s_addr = sockaddr.sin_addr.s_addr;

	//! packet comes in, send all of them
	{
		int i = 0;
		int bytes_sent;
		bool succ = false;
		/* See man rand for why this way is prefered */
		//r = (int) (100.0*rand()/RAND_MAX);
		// always broadcast
		uint8_t send_buf[SEND_BUF_SIZE];
		int k = 0;
		DEBUG("sim: send_thread %d\n",radio_pkt_success_rate);
		for(i = 0; i < SOS_MSG_HEADER_SIZE; i++, k++) {
			send_buf[k] = *(((uint8_t*)txmsgptr) + i);
		}
		for(i = 0; i < txmsgptr->len; i++, k++) {
			send_buf[k] = txmsgptr->data[i];
		}

		DEBUG("totalNodes = %d\n", totalNodes);
		for(i = 0; i < totalNodes; i++){
			if(topo_array[i].type == TOPO_TYPE_NEIGHBOR){
				int r;
				r = (int) (100.0*rand()/RAND_MAX);
				if(r <= radio_pkt_success_rate){
					if((txmsgptr->daddr == topo_array[i].id) ||
							(txmsgptr->daddr == BCAST_ADDRESS))
						succ = true;
					name.sin_port = htons( get_sin_port(topo_array[i].id) );
					DEBUG("sim: sending to topo_array[%d].id = %d\n",i,topo_array[i].id);
					bytes_sent = sendto(sock, send_buf, k, 0,
							(struct sockaddr *)&name,
							sizeof(struct sockaddr_in));
					if (bytes_sent < 0) {
						DEBUG("Radio: Error Sending Packet ! \n");
					}
					else {
						DEBUG("Radio: Sent %d bytes to port %d\n", bytes_sent, ntohs(name.sin_port));
					}
				}
			}
		}
		if(bTsEnable) {
			timestamp_outgoing(txmsgptr, ker_systime32());
		}

		if( succ == false ) {
			txmsgptr->flag |= SOS_MSG_SEND_FAIL;
		}
		mq_enqueue( &senddoneq, txmsgptr );

		if( senddone_callback_requested == false ) {
			interrupt_add_callbacks(handle_senddone);
			senddone_callback_requested = true;
		}
	}
	LEAVE_CRITICAL_SECTION();
}