Beispiel #1
0
/**
   @brief Send an other-the-air (OTA) debug frame.  This contains a
   string payload that is displayed on the coordintor end.
 */
void macOtaDebugRequest(u8 *str)
{
   if (NODETYPE != COORD)
   {
      macDataRequestInt(DEFAULT_COORD_ADDR, strlen((char *)str)+1, str, DEBUG_FRAME);
   }
}
Beispiel #2
0
/**
    @brief The macWakeRequest function is called by the coordinator to
            send a wakeup packet to a router.

    @param addr Short address of the parent router of the node to wake
    up.
    @param child Short address of the child node to wake up.
 */
void macWakeRequest(u16 addr, u16 child)
{
   if (NODETYPE != ENDDEVICE)
   {
      macDataRequestInt(addr, 2, (u8*)&child, WAKE_NODE);
   }
}
Beispiel #3
0
/**
      The macWakeRequest function is called by the coordinator to
            send a wakeup packet to a router.

    param:  addr Short address of the parent router of the node to wake
    up.
    param:  child Short address of the child node to wake up.
*/
void
macWakeRequest(u16 addr, u16 child)
{
    if (NODE_TYPE == ROUTER || NODE_TYPE== COORD)
    {
        macDataRequestInt(addr, 2, (u8*)&child, WAKE_NODE);
    }
}
Beispiel #4
0
/**
   This function is called when the MAC receives a packet that is
   addressed to this node.  The packet is dispatched according to its
   contents.
 */
void macDataIndication(uint8_t* pFrame)
{

   // Sort out the different types of data packets.
   ftData *frame = (ftData*)(((rx_frame_t*)pFrame)->data);

   /*
#if (__arm__)
    volatile s16 queue;
    if(fnGetTCP_state(host_socket) == TCP_STATE_ESTABLISHED)
    {
        if( (frame->fcf != FCF_BEACONREQ) &&
            (frame->fcf != FCF_ASSOC_REQ_DIRECT) &&
            (frame->fcf != FCF_ASSOC_REQ_IND) )
        {
            // ACK handling should occur in the tcpListener function in
            // rumtask.c.
            // fnSendBufTCP returns the number of bytes buffered if successful...
            queue = fnSendBufTCP(host_socket, (u8 *)"WIRELESSD", 9, TCP_BUF_SEND);
            if(telPrintReading && (queue > 0))
                fnDebugMsg("\r\nWIRELESSD buffered for TCP");
            else
                fnDebugMsg("\r\nWIRELESSD buffer problem");
            queue = fnSendBufTCP(host_socket, mac_buffer_rx, mac_buffer_rx[0]+1, TCP_BUF_SEND);
            if(telPrintReading && (queue > 0))
                fnDebugMsg("\r\nData indication buffered for TCP");
            else
                fnDebugMsg("\r\nData indication buffer problem");
        }
    }
#endif
    */
   switch (frame->type & 0x7f)  // Mask high bit just in case it was somehow missed
   {
   case DATA_FRAME:
      // Plain old data, send it up the chain
      appDataIndication();
      break;
   case DEBUG_FRAME:
      // Frame containing debug message, print it on coord
      if (NODETYPE == COORD && OTA_DEBUG && DEBUG)
      {
         debugMsgStr("\r\nNode ");
         debugMsgInt(frame->originAddr);
         debugMsgStr(": ");

         // Remove leading cr/lf's from string
         u8 *p = frame->payload;
         while (*p)
         {
            if (*p > ' ')
               break;
            p++;
         }
         debugMsgStr((char *)p);
      }
      break;
   case WAKE_NODE:
      // Wake up the end node.
      if (NODETYPE == ROUTER)
      {
         u8 addr = ((ftWake*)frame)->addr;
         // See if this is from parent or child
         if ((((ftWake*)frame)->srcAddr) == macConfig.parentShortAddress)
            // Set the flag to wake up the end node when it sends a packet
            macWakeChildNode(addr);
      }
      if (NODETYPE == ENDDEVICE)
      {
         // Wake yourself up now
         macConfig.sleeping = false;
         // Send parent a confirmation that we are awake
         macDataRequestInt(macConfig.parentShortAddress,
               2,
               (u8*)&macConfig.shortAddress,
               WAKE_NODE);
         debugMsgStr("\r\nAwake");
      }
      break;
   case PING_REQ_FRAME:
      // We got a ping request, let the app handle that
      appPingReq(frame->originAddr);
      break;
   case PING_RSP_FRAME:
      // We got a ping response, app will handle it
      appPingRsp(frame->originAddr);
      break;
   case DROP_CHILD_FRAME:
      // Coordinator is telling us to drop a child
      if (NODETYPE == ROUTER)
         macRemoveChild(*(u16*)(&frame->payload));
      break;
   case DATA_FRAME_6LOWPAN:
      //6lowpan data indication
      if (IPV6LOWPAN == 1)
         //sixlowpan_DataIndication(frame, *mac_buffer_rx - 16);
         sixlowpan_DataIndication(frame, (((rx_frame_t*)pFrame)->length) - 16);
      break;
   default:
      break;
   }
}
Beispiel #5
0
/**
    @brief The macsixlowpanDataRequest function is used to send a
    frame over the air to another node.  Note that the IPV6LOWPAN flag
    must be set to use any 6LoWPAN functionality.

    @param addr Short address of the destination node.

    @param len The length of the packet in bytes.

    @param data Pointer to the data to be sent.

    @ingroup avr6lowpan
 */
void macsixlowpanDataRequest(u16 addr, u8 len, u8 * data)
{
   if (IPV6LOWPAN == 1)
      macDataRequestInt(addr, len, data, DATA_FRAME_6LOWPAN);
}
Beispiel #6
0
/**
   @brief The macsixlowpanDataRequest function is used to send a frame over
   the air to another node.  Any node type can call this function.

   @param addr Short address of the destination node.

   @param len The length of the packet in bytes.

   @param data Pointer to the data to be sent.
 */
void macDataRequest(u16 addr, u8 len, u8 * data)
{
   macDataRequestInt(addr, len, data, DATA_FRAME);
}
Beispiel #7
0
/**
   This function is called when the MAC receives a packet that is
   addressed to this node.  The packet is dispatched according to its
   contents.
*/
void
macDataIndication(u16 dest)
{
    // Sort out the different types of data packets.
   ftData *frame = (ftData*)(mac_buffer_rx+1);
   u8 pl_len = *mac_buffer_rx - 16;
#if DEBUG==2
    debugMsgStr("\r\nmacDataIndication<-");
#endif
    switch (frame->type & 0x7f)  // Mask high bit just in case it was somehow missed
    {
		case DATA_FRAME:
			// Data, send it up the chain
			appDataIndication(frame->payload, pl_len, (dest ==  BROADCASTADDR));
			break;

		case DEBUG_FRAME:
			// Frame containing debug message, print it on coord
			if (NODE_TYPE == COORD && OTA_DEBUG && DEBUG)
			{
				debugMsgStr("\r\nNode ");
				debugMsgInt(frame->originAddr);
				debugMsgStr(": ");

				// Remove leading cr/lf's from string
				u8 *p = frame->payload;
				while (*p)
				{
					if (*p > ' ')
						break;
					p++;
				}
				debugMsgStr_d((char *)p);
			}
			break;

		case WAKE_NODE:
			// Wake up the end node.
#if (NODE_TYPE == ROUTER)
			{
				u8 addr = ((ftWake*)frame)->addr;
				// See if this is from parent or child
				if ((((ftWake*)frame)->srcAddr) == macConfig.parentShortAddress)
					// Set the flag to wake up the end node when it sends a packet
					macWakeChildNode(addr);
			}
#endif

#if (NODE_TYPE == ENDDEVICE) /* also include BC_ENDDEVICE ?*/
			{
				// Wake yourself up now
				macConfig.sleeping = false;
				// Send parent a confirmation that we are awake
				macDataRequestInt(macConfig.parentShortAddress,2,
								  (u8*)&macConfig.shortAddress,WAKE_NODE);
				debugMsgStr("\r\nAwake");
			}
#endif
			break;

		case PING_REQ_FRAME:
			// We got a ping request, let the app handle that
			appPingReq((ftPing *) (mac_buffer_rx+1));
			break;

		case PING_RSP_FRAME:
			// We got a ping response, app will handle it
			appPingRsp((ftPing *) (mac_buffer_rx+1));
			break;

#if (NODE_TYPE == ROUTER)
		case DROP_CHILD_FRAME:
			// Coordinator is telling us to drop a child
			macRemoveChild(*(u16*)(&frame->payload));
			break;
#endif
		default:
			break;
    }
}