Exemplo n.º 1
0
        public void DataRequest(
            MacAddressingMode srcAddrMode,
            MacAddress dstAddr,
            UInt16 dstPanId,
            ref Frame msdu,
            Byte msduHandle,
            TxOptions options,
            SecurityOptions securityOptions,
            DataConfirmHandler handler)
        {
            TaskDataRequest task = new TaskDataRequest(
                srcAddrMode,
                dstAddr,
                dstPanId,
                msdu,
                msduHandle,
                options,
                securityOptions,
                handler);

            if (!_taskQueue.Add(task))
            {
                Frame.Release(ref msdu);
                if (handler != null)
                {
                    handler.Invoke(this, msduHandle, MacEnum.Congested);
                }
            }

            msdu = null; // in any case, remove frame ownership from caller
        }
Exemplo n.º 2
0
        private void DataRequest(TaskDataRequest task)
        {
            if (task == null)
                return;

            MacEnum result = MacEnum.Success;
            bool is2006 = false;
            // check frame
            if (task.msdu == null || task.msdu.LengthDataUsed == 0)
            {
                result = MacEnum.InvalidParameter;
            }
            else if (task.msdu.LengthDataUsed > State.aMaxMACSafePayloadSize)
            {
                if (_state.phySupports2006)
                {
                    is2006 = true;
                }
                else
                {
                    result = MacEnum.FrameTooLong;
                }
            }

            if (result == MacEnum.Success)
            {
                // data request is a value type, cannot be null
                Header hdr = new Header();

                hdr.fcs.Type = Frames.Type.Data;
                if (is2006)
                    hdr.fcs.Version = Frames.Version.IEEE2006;
                else
                    hdr.fcs.Version = Frames.Version.IEEE2003;
                if (task.options.AcknowledgedTransmission)
                    hdr.fcs.Ack = true;
                // FIXME: security

                lock (_state)
                {
                    hdr.seqNo = _state.macDSN++;

                    // dst address
                    hdr.dstPanId = task.dstPANId;
                    switch (task.dstAddr.Mode)
                    {
                        case MacAddressingMode.NoAddress:
                            hdr.fcs.DstAddrMode = AddressingMode.None;
                            break;
                        case MacAddressingMode.ShortAddress:
                            hdr.fcs.DstAddrMode = AddressingMode.Short;
                            hdr.dstAddrShort = task.dstAddr.ShortAddress;
                            break;
                        case MacAddressingMode.ExtendedAddress:
                            hdr.fcs.DstAddrMode = AddressingMode.Extended;
                            hdr.dstAddrExt = task.dstAddr.ExtendedAddress;
                            break;
                    }

                    // src addr
                    if (_state.macPanId == task.dstPANId)
                    {
                        hdr.fcs.PanIdCompression = true;
                    }
                    else
                    {
                        hdr.srcPanId = _state.macPanId;
                    }

                    switch (task.srcAddrMode)
                    {
                        case MacAddressingMode.NoAddress:
                            hdr.fcs.SrcAddrMode = AddressingMode.None;
                            break;
                        case MacAddressingMode.ShortAddress:
                            hdr.fcs.SrcAddrMode = AddressingMode.Short;
                            hdr.srcAddrShort = _state.macShortAddr;
                            break;
                        case MacAddressingMode.ExtendedAddress:
                            hdr.fcs.SrcAddrMode = AddressingMode.Extended;
                            hdr.srcAddrExt = _state.aExtendedAddress;
                            break;
                    }
                }

                // encode
                result = MacEnum.Congested;
                if (hdr.WriteToFrameHeader(task.msdu))
                {
                    if (task.msdu.LengthDataUsed > State.aMaxPhyPacketSize)
                    {
                        result = MacEnum.FrameTooLong;
                    }
                    else
                    {
                        result = _sendReceive.SendFrame(ref task.msdu, task.options.AcknowledgedTransmission, hdr.seqNo);
                    }
                }
                else
                {
                    Trace.Print("Mac: DataRequest: cannot add Mac header");
                }
            }

            Frame.Release(ref task.msdu);

            if (task.handler != null)
            {
                task.handler.Invoke(this, task.msduHandle, result);
            }
        }
Exemplo n.º 3
0
        public void DataRequest(
            MacAddressingMode srcAddrMode,
            MacAddress dstAddr,
            UInt16 dstPanId,
            ref Frame msdu,
            Byte msduHandle,
            TxOptions options,
            SecurityOptions securityOptions,
            DataConfirmHandler handler)
        {
            TaskDataRequest task = new TaskDataRequest(
                srcAddrMode,
                dstAddr,
                dstPanId,
                msdu,
                msduHandle,
                options,
                securityOptions,
                handler);
            if (!_taskQueue.Add(task))
            {
                Frame.Release(ref msdu);
                if (handler != null)
                    handler.Invoke(this, msduHandle, MacEnum.Congested);
            }

            msdu = null; // in any case, remove frame ownership from caller
        }
        private void DataRequest(TaskDataRequest task)
        {
            if (task == null)
            {
                return;
            }

            MacEnum result = MacEnum.Success;
            bool    is2006 = false;

            // check frame
            if (task.msdu == null || task.msdu.LengthDataUsed == 0)
            {
                result = MacEnum.InvalidParameter;
            }
            else if (task.msdu.LengthDataUsed > State.aMaxMACSafePayloadSize)
            {
                if (_state.phySupports2006)
                {
                    is2006 = true;
                }
                else
                {
                    result = MacEnum.FrameTooLong;
                }
            }

            if (result == MacEnum.Success)
            {
                // data request is a value type, cannot be null
                Header hdr = new Header();

                hdr.fcs.Type = Frames.Type.Data;
                if (is2006)
                {
                    hdr.fcs.Version = Frames.Version.IEEE2006;
                }
                else
                {
                    hdr.fcs.Version = Frames.Version.IEEE2003;
                }
                if (task.options.AcknowledgedTransmission)
                {
                    hdr.fcs.Ack = true;
                }
                // FIXME: security

                lock (_state)
                {
                    hdr.seqNo = _state.macDSN++;

                    // dst address
                    hdr.dstPanId = task.dstPANId;
                    switch (task.dstAddr.Mode)
                    {
                    case MacAddressingMode.NoAddress:
                        hdr.fcs.DstAddrMode = AddressingMode.None;
                        break;

                    case MacAddressingMode.ShortAddress:
                        hdr.fcs.DstAddrMode = AddressingMode.Short;
                        hdr.dstAddrShort    = task.dstAddr.ShortAddress;
                        break;

                    case MacAddressingMode.ExtendedAddress:
                        hdr.fcs.DstAddrMode = AddressingMode.Extended;
                        hdr.dstAddrExt      = task.dstAddr.ExtendedAddress;
                        break;
                    }

                    // src addr
                    if (_state.macPanId == task.dstPANId)
                    {
                        hdr.fcs.PanIdCompression = true;
                    }
                    else
                    {
                        hdr.srcPanId = _state.macPanId;
                    }

                    switch (task.srcAddrMode)
                    {
                    case MacAddressingMode.NoAddress:
                        hdr.fcs.SrcAddrMode = AddressingMode.None;
                        break;

                    case MacAddressingMode.ShortAddress:
                        hdr.fcs.SrcAddrMode = AddressingMode.Short;
                        hdr.srcAddrShort    = _state.macShortAddr;
                        break;

                    case MacAddressingMode.ExtendedAddress:
                        hdr.fcs.SrcAddrMode = AddressingMode.Extended;
                        hdr.srcAddrExt      = _state.aExtendedAddress;
                        break;
                    }
                }

                // encode
                result = MacEnum.Congested;
                if (hdr.WriteToFrameHeader(task.msdu))
                {
                    if (task.msdu.LengthDataUsed > State.aMaxPhyPacketSize)
                    {
                        result = MacEnum.FrameTooLong;
                    }
                    else
                    {
                        result = _sendReceive.SendFrame(ref task.msdu, task.options.AcknowledgedTransmission, hdr.seqNo);
                    }
                }
                else
                {
                    Trace.Print("Mac: DataRequest: cannot add Mac header");
                }
            }

            Frame.Release(ref task.msdu);

            if (task.handler != null)
            {
                task.handler.Invoke(this, task.msduHandle, result);
            }
        }