Exemplo n.º 1
0
        /// <summary>
        /// Send a Mac SDU using context information. SrcAddr is automatically choosen.
        /// </summary>
        /// <param name="msdu">The frame to sent.</param>
        /// <param name="context">Sent context. If null, frame is broadcasted</param>
        private void MacDataRequestReal(
            bool useExtAddr,
            UInt16 nextHopAddrShort,
            UInt64 nextHopAddrExt,
            ref Frame sdu,
            Byte sduHandle,
            DataConfirmHandler handler)
        {
            // srcAddr: always use short addr when available
            MacAddressingMode srcAddrMode = new MacAddressingMode();
            if (_addrShort == cUnallocatedShortAddr)
                srcAddrMode = MacAddressingMode.ExtendedAddress;
            else
                srcAddrMode = MacAddressingMode.ShortAddress;

            MacAddress dstAddr = new MacAddress();
            if (useExtAddr)
                dstAddr.ExtendedAddress = nextHopAddrExt;
            else
                dstAddr.ShortAddress = nextHopAddrShort;

            byte msduHandle;
            Mac.DataConfirmHandler macHandler;

            bool broadcast = (!useExtAddr) && IsMulticast(nextHopAddrShort);
            if (!broadcast || handler != null)
            { // need a send context
                MessageContext.Context context = _messageContext.GetFreeContext();
                if (context == null)
                { // busy
                    if (handler != null)
                        handler.Invoke(_net, sduHandle, Status.Busy);
                    Frame.Release(ref sdu);
                    return;
                }

                context.useExtAddr = useExtAddr;
                context.nextHopShort = nextHopAddrShort;
                context.nextHopExt = nextHopAddrExt;
                context.dataSduHandle = sduHandle;
                context.dataHandler = handler;

                macHandler = MacDataConfirmHandler;
                msduHandle = context.macSduHandle;
            }
            else
            {
                macHandler = null;
                msduHandle = MessageContext.cHandleDontCare;
            }

            TxOptions tx = new TxOptions();
            if (!broadcast)
                tx.AcknowledgedTransmission = true;

            _mac.DataRequest(
                srcAddrMode,
                dstAddr,
                _panId,
                ref sdu,
                msduHandle,
                tx,
                new SecurityOptions(),
                macHandler);
            Frame.Release(ref sdu);
        }