Beispiel #1
0
/**
 * @brief   Event loop of the RAW dump thread
 *
 * @param[in] arg   unused parameter
 */
void *rawdump(void *arg)
{
    (void)arg;
    msg_t msg;

    while (1) {
        msg_receive(&msg);

        switch (msg.type) {
            case GNRC_NETAPI_MSG_TYPE_RCV:
                dump_pkt((gnrc_pktsnip_t *)msg.content.ptr);
                break;
            default:
                /* do nothing */
                break;
        }
    }

    /* never reached */
    return NULL;
}
Beispiel #2
0
/*
  Parse one logical MySQL packet

  This function has 6 parts:
    1. Parse error pkts
    2. Handle no last origin
    3. Handle client re-sending pkt (set state back to STATE_SLEEP)
    4. Set state and number of possible events for state
    5. Try to handle pkt given state and possible events
    6. Check if pkt was handled/parsed ok

  If the pkt fails to be handled, something is broken or missing because
  when 6 fails, it goes to 2 which acts as a kind of catch-all.
  But if 2 then fails and we get back to 6 a second time, a warning
  is printed ("Client pkt has no valid handler") and the function returns
  a failure.
*/
int parse_pkt(u_char *pkt, u_int len)
{
   u_short state;
   u_short event;
   u_short num_events;
   u_short have_failed_before = 0;
   PKT_HANDLER ha = 0;

   if(op.dump) {
      dump_pkt(pkt, len, 1);
      return PKT_PARSED_OK;
   }

   if(*pkt == 0xFF) { // Error
      pkt_error(pkt, len);
      tag->state = STATE_SLEEP;
      return PKT_PARSED_OK;
   }

   /*
     If there is no last origin, this usually means this is the first pkt
     we're seeing for this connection. However, this pkt could then be
     anything, so we have to wait for a reliable starting point which is
     any client > server command because a client will only send a command
     from a state of sleep (i.e, after the server is done responding).
   */
   if(!tag->last_origin) {
DETERMINE_PKT:
      if(tag->current_origin == ORIGIN_SERVER) {

         ha = state_map[STATE_NOT_CONNECTED].ha[0]; // server handshake pkt?
         if((*ha)(pkt, len) == PKT_HANDLED) {
            tag->state = state_map[STATE_NOT_CONNECTED].next_state[0];
            return PKT_PARSED_OK;
         }
         else {
            /*
              We're in the middle of a pre-established connection or something
              weird happened like the server responding for no reason (perhaps
              the client sent a TCP re-xmit?)
            */
            printf("Waiting for server to finish response... ");
            dump_pkt(pkt, len, 0);
            tag->state = STATE_SLEEP; // Will be asleep when done
            tag->last_origin = 0;
            return PKT_UNKNOWN_STATE; // Keeps multi_pkts() from setting tag->last_origin
         }

      }
      else { // pkt from client

         /*
           Since the MySQL protocol is purely request-response, if a pkt is from
           the client it must mean MySQL has finished responding and is asleep
           waiting for further commands.
         */
         tag->state = STATE_SLEEP;

         // Special cases
         if(len == 1) {
            if(*pkt == COM_STATISTICS) tag->state = STATE_ONE_STRING;
         }

      }
   }

   // Client re-sent pkt (MySQL probably didn't respond to the first pkt)
   if(tag->last_origin == ORIGIN_CLIENT &&
      tag->current_origin == ORIGIN_CLIENT &&
      tag->state != STATE_SLEEP)
   {
      printf("::RETRANSMIT:: ");
      tag->state = STATE_SLEEP;
   }

   // Safeguard
   if(tag->current_origin == ORIGIN_CLIENT &&
      tag->current_pkt_id == 0 &&
      tag->state != STATE_SLEEP)
   {
      tag->state = STATE_SLEEP;
   }

   state = tag->state; // Current state
   num_events = state_map[state].num_events; // Number of possible events for current state
   if(op.state) printf("state '%s' ", state_name[state]);

   // Try to handle the pkt...
   if(num_events == 1) {
      tag->event = state_map[state].event[0];
      ha = state_map[state].ha[0];

      if((*ha)(pkt, len))
         tag->state = state_map[state].next_state[0]; // pkt was handled
      else
         ha = 0;
   }
   else {
      for(event = 0; event < num_events; event++) {
         tag->event = state_map[state].event[event];
         ha = state_map[state].ha[event];

         if((*ha)(pkt, len)) {
            // pkt was handled
            tag->state = state_map[state].next_state[event];
            break;
         }
         else ha = 0;
      }
   }

   // ...Check if pkt was handled
   if(!ha) {
      printf("::Unhandled Event:: ");

      if(!have_failed_before) {
         have_failed_before = 1; // Prevent infinite loop
         goto DETERMINE_PKT;
      }
      else {
         printf("Client pkt has no valid handler ");
         dump_pkt(pkt, len, 1);
         return PKT_UNKNOWN_STATE;
      }
   }

   return PKT_PARSED_OK;
}
Beispiel #3
0
struct ol_tx_desc_t *ol_tx_desc_ll(struct ol_txrx_pdev_t *pdev,
				   struct ol_txrx_vdev_t *vdev,
				   cdf_nbuf_t netbuf,
				   struct ol_txrx_msdu_info_t *msdu_info)
{
	struct ol_tx_desc_t *tx_desc;
	unsigned int i;
	uint32_t num_frags;

	msdu_info->htt.info.vdev_id = vdev->vdev_id;
	msdu_info->htt.action.cksum_offload = cdf_nbuf_get_tx_cksum(netbuf);
	switch (cdf_nbuf_get_exemption_type(netbuf)) {
	case CDF_NBUF_EXEMPT_NO_EXEMPTION:
	case CDF_NBUF_EXEMPT_ON_KEY_MAPPING_KEY_UNAVAILABLE:
		/* We want to encrypt this frame */
		msdu_info->htt.action.do_encrypt = 1;
		break;
	case CDF_NBUF_EXEMPT_ALWAYS:
		/* We don't want to encrypt this frame */
		msdu_info->htt.action.do_encrypt = 0;
		break;
	default:
		cdf_assert(0);
		break;
	}

	/* allocate the descriptor */
	tx_desc = ol_tx_desc_alloc_wrapper(pdev, vdev, msdu_info);
	if (!tx_desc)
		return NULL;

	/* initialize the SW tx descriptor */
	tx_desc->netbuf = netbuf;

	if (msdu_info->tso_info.is_tso) {
		tx_desc->tso_desc = msdu_info->tso_info.curr_seg;
		tx_desc->pkt_type = ol_tx_frm_tso;
		TXRX_STATS_MSDU_INCR(pdev, tx.tso.tso_pkts, netbuf);
	} else {
		tx_desc->pkt_type = ol_tx_frm_std;
	}

	/* initialize the HW tx descriptor */

	htt_tx_desc_init(pdev->htt_pdev, tx_desc->htt_tx_desc,
			 tx_desc->htt_tx_desc_paddr,
			 ol_tx_desc_id(pdev, tx_desc), netbuf, &msdu_info->htt,
			 &msdu_info->tso_info,
			 NULL, vdev->opmode == wlan_op_mode_ocb);

	/*
	 * Initialize the fragmentation descriptor.
	 * Skip the prefix fragment (HTT tx descriptor) that was added
	 * during the call to htt_tx_desc_init above.
	 */
	num_frags = cdf_nbuf_get_num_frags(netbuf);
	/* num_frags are expected to be 2 max */
	num_frags = (num_frags > CVG_NBUF_MAX_EXTRA_FRAGS)
		? CVG_NBUF_MAX_EXTRA_FRAGS
		: num_frags;
#if defined(HELIUMPLUS_PADDR64)
	/*
	 * Use num_frags - 1, since 1 frag is used to store
	 * the HTT/HTC descriptor
	 * Refer to htt_tx_desc_init()
	 */
	htt_tx_desc_num_frags(pdev->htt_pdev, tx_desc->htt_frag_desc,
			      num_frags - 1);
#else /* ! defined(HELIUMPLUSPADDR64) */
	htt_tx_desc_num_frags(pdev->htt_pdev, tx_desc->htt_tx_desc,
			      num_frags - 1);
#endif /* defined(HELIUMPLUS_PADDR64) */

	if (msdu_info->tso_info.is_tso) {
		htt_tx_desc_fill_tso_info(pdev->htt_pdev,
			 tx_desc->htt_frag_desc, &msdu_info->tso_info);
		TXRX_STATS_TSO_SEG_UPDATE(pdev,
			 msdu_info->tso_info.curr_seg->seg);
	} else {
		for (i = 1; i < num_frags; i++) {
			cdf_size_t frag_len;
			uint32_t frag_paddr;

			frag_len = cdf_nbuf_get_frag_len(netbuf, i);
			frag_paddr = cdf_nbuf_get_frag_paddr_lo(netbuf, i);
#if defined(HELIUMPLUS_PADDR64)
			htt_tx_desc_frag(pdev->htt_pdev, tx_desc->htt_frag_desc, i - 1,
				 frag_paddr, frag_len);
#if defined(HELIUMPLUS_DEBUG)
			cdf_print("%s:%d: htt_fdesc=%p frag_paddr=%u len=%zu\n",
					  __func__, __LINE__, tx_desc->htt_frag_desc,
					  frag_paddr, frag_len);
			dump_pkt(netbuf, frag_paddr, 64);
#endif /* HELIUMPLUS_DEBUG */
#else /* ! defined(HELIUMPLUSPADDR64) */
			htt_tx_desc_frag(pdev->htt_pdev, tx_desc->htt_tx_desc, i - 1,
							 frag_paddr, frag_len);
#endif /* defined(HELIUMPLUS_PADDR64) */
		}
	}

#if defined(HELIUMPLUS_DEBUG)
	dump_frag_desc("ol_tx_desc_ll()", tx_desc);
#endif
	return tx_desc;
}