Пример #1
0
        /// <summary>
        /// Handler for Mac sdu confirmations
        /// </summary>
        private void MacDataConfirmHandler(
                IMacDataSap sender,
                Byte msduHandle,
                MacEnum mStatus)
        {
            MessageContext.Context context = _messageContext.GetContext(msduHandle);
            if (context == null)
                return;

            Status status = Status.Success;
            if (mStatus != MacEnum.Success)
            {
                status = Status.Error;
                if (!context.useExtAddr && mStatus != MacEnum.Congested)
                {
                    // if network is congested, avoid route repairs causing additional traffic
                    Trace.Print("Link failure for 0x" + HexConverter.ConvertUintToHex(context.nextHopShort, 4));
                    _routingTable.HandleLinkFailure(context.nextHopShort);
                }
            }

            if (context.dataHandler != null)
                context.dataHandler.Invoke(_net, context.dataSduHandle, status);

            _messageContext.ReleaseContext(context);
        }
Пример #2
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);
        }