Esempio n. 1
0
 private object get_ulong_swp(pointer owner, int index)
 {
     byte[] temp = new byte[sizeof(ulong)];
     Buffer.BlockCopy(owner.data, owner.offset + _offset + (index * _size), temp, 0, sizeof(ulong));
     Array.Reverse(temp);
     return(BitConverter.ToUInt64(temp, 0));
 }
Esempio n. 2
0
        internal void input(pointer packet, int length, ip_addr srcn, ip_addr destn, byte proto)
        {
            ip_addr src = new ip_addr(lwip.lwip_htonl(srcn.addr));
            ip_addr dest = new ip_addr(lwip.lwip_htonl(destn.addr));
            pbuf    p = pbuf_alloc(pbuf_layer.PBUF_RAW, (ushort)length, pbuf_type.PBUF_POOL);
            int     pos = 0, rest = length;

            for (pbuf q = p; q != null; q = q.next)
            {
                int len = rest;
                if (len > q.len)
                {
                    len = q.len;
                }

                pointer.memcpy(q.payload, new pointer(packet, pos), len);
                pos  += len;
                rest -= len;
            }

            if (ip_input(p, src, dest, proto) != err_t.ERR_OK)
            {
                pbuf_free(p);
            }
        }
Esempio n. 3
0
        public ER ReleaseMemoryBlock(pointer blk)
        {
            if (blk == null)
            {
                return(ER.E_PAR);
            }

            //if ((int)blk != 0)
            //	return ER.E_PAR;

            if ((blk < m_cmpf.addr) || (blk >= m_cmpf.addr + (m_cmpf.blkcnt * m_cmpf.blksz)))
            {
                return(ER.E_PAR);
            }

            m_MpfQueue.AddLast(blk);

            for (LinkedListNode <Task> Node = m_TskQueue.First; Node != null; Node = Node.Next)
            {
                Task task = Node.Value;

                m_TskQueue.Remove(Node);

                if (!task.ReleaseWait())
                {
                    return(ER.E_RLWAI);
                }
            }

            return(ER.E_OK);
        }
Esempio n. 4
0
 private object get_ushort_swp(pointer owner)
 {
     byte[] temp = BitConverter.GetBytes(
         BitConverter.ToUInt16(owner.data, owner.offset + _offset) & _mask);
     Array.Reverse(temp);
     return((ushort)(BitConverter.ToUInt16(temp, 0) >> (16 - _bit_offset - _bit_size)));
 }
Esempio n. 5
0
 private object get_ulong_swp(pointer owner)
 {
     byte[] temp = BitConverter.GetBytes(
         BitConverter.ToUInt64(owner.data, owner.offset + _offset) & _mask);
     Array.Reverse(temp);
     return(BitConverter.ToUInt64(temp, 0) >> (64 - _bit_offset - _bit_size));
 }
Esempio n. 6
0
            private void set_ulong(pointer owner, object value)
            {
                ulong temp = (ulong)((((ulong)value << _bit_offset) & (ulong)_mask)
                                     | (BitConverter.ToUInt16(owner.data, owner.offset + _offset) & (ulong)~_mask));

                Buffer.BlockCopy(BitConverter.GetBytes(temp), 0, owner.data, owner.offset + _offset, sizeof(ulong));
            }
Esempio n. 7
0
 public static void stats_display_mem(stats_mem mem, pointer name)
 {
     LWIP_PLATFORM_DIAG(("\nMEM {0}\n\t", name));
     LWIP_PLATFORM_DIAG(("avail: {0}\n\t", (uint)mem.avail));
     LWIP_PLATFORM_DIAG(("used: {0}\n\t", (uint)mem.used));
     LWIP_PLATFORM_DIAG(("max: {0}\n\t", (uint)mem.max));
     LWIP_PLATFORM_DIAG(("err: {0}\n", (uint)mem.err));
 }
Esempio n. 8
0
 internal static void STATS_INC_USED(pointer x, int y)
 {
     lwip_stats[x].used += y;
     if (lwip_stats[x].max < lwip_stats[x].used)
     {
         lwip_stats[x].max = lwip_stats[x].used;
     }
 }
Esempio n. 9
0
 public udp_hdr(byte[] buffer, int offset)
     : base(buffer, offset)
 {
     _src    = new pointer(data, offset + 0);          /* ushort */
     _dest   = new pointer(data, offset + 2);          /* ushort */
     _len    = new pointer(data, offset + 4);          /* ushort */
     _chksum = new pointer(data, offset + 6);          /* ushort */
 }
Esempio n. 10
0
 private mem(lwip lwip, byte[] buffer, int offset)
     : base(buffer, offset)
 {
     this.lwip = lwip;
     _next     = new pointer(buffer, offset + 0);
     _prev     = new pointer(buffer, offset + 4);
     _used     = new pointer(buffer, offset + 8);
 }
Esempio n. 11
0
 private void set_ulong_swp(pointer owner, object value)
 {
     byte[] mskval = BitConverter.GetBytes((((ulong)value << _bit_offset) & (ulong)_mask) << (64 - _bit_offset - _bit_size));
     Array.Reverse(mskval);
     byte[] temp = BitConverter.GetBytes((ulong)(BitConverter.ToUInt64(mskval, 0)
                                                 | (BitConverter.ToUInt64(owner.data, owner.offset + _offset) & ~_mask)));
     Buffer.BlockCopy(temp, 0, owner.data, owner.offset + _offset, sizeof(ulong));
 }
Esempio n. 12
0
 public void SetReference(pointer value)
 {
     if (m_Data != value.data)
     {
         throw new ArgumentException();
     }
     SetValue(value.offset);
 }
Esempio n. 13
0
        public static void memset(pointer dst, byte value, int len)
        {
            int end = dst.m_Offset + len;

            for (int i = dst.m_Offset; i < end; i++)
            {
                dst.m_Data[i] = value;
            }
        }
Esempio n. 14
0
        public static int strlen(pointer This)
        {
            int result = Array.FindIndex(This.m_Data, This.m_Offset, (p) => p == 0);

            if (result == -1)
            {
                return(-1);
            }
            return(result - This.m_Offset);
        }
Esempio n. 15
0
 public void set(pointer owner, bool value)
 {
     if (value)
     {
         owner.data[owner.offset + _offset] |= (byte)(1 << _bit);
     }
     else
     {
         owner.data[owner.offset + _offset] &= (byte)~(1 << _bit);
     }
 }
Esempio n. 16
0
        public TMemNode(pointer data, int size)
            : base(data)
        {
#if DEBUG
            m_Header = new _CrtMemBlockHeader(this, 0, null, null, "", 0, size,
                                              _CrtMemBlockHeader._NORMAL_BLOCK, 0);
#endif
            Previous = null;
            Next     = null;
            Size     = size;
        }
Esempio n. 17
0
        public ER GetMemoryBlock(out pointer p_blk, int blksz, TMO tmout)
        {
            ER ret;

            p_blk = null;

            //if (p_blk == null)
            //	return ER.E_PAR;

            for (; ;)
            {
                TMemNode Node = Allocate(blksz);

                if (Node != null)
                {
                    p_blk = Node.GetData();
                    break;
                }

                if (tmout == 0)
                {
                    return(ER.E_TMOUT);
                }

                Task task = m_Nucleus.GetTask(ID.TSK_SELF);

                if (task == null)
                {
                    return(ER.E_CTX);
                }

                task.MemoryBlockSize = blksz;
                ret = task.Wait(m_TskQueue, TSKWAIT.TTW_MPL, m_MplID, tmout);

                switch (ret)
                {
                case ER.E_OK:
                    continue;

                case ER.E_TMOUT:
                    return(ER.E_TMOUT);

                default:
                    return(ER.E_RLWAI);
                }
            }
#if DEBUG
            string lpszFileName = "";
            int    nLine        = 0;
            _CrtMemBlockHeader.AddBlock(m_pFirstBlock, m_pLastBlock, p_blk, blksz, lpszFileName, nLine);
            m_nBlockCount++;
#endif
            return(ER.E_OK);
        }
Esempio n. 18
0
        private int CopyRecvData(pointer p_data, int len)
        {
            int  spos = 0, rest = len;
            int  dpos = m_RecvPos;
            pbuf buf = m_RecvPBuf;
            pbuf p = m_RecvPBufPos, q;

            do
            {
                for (q = p; q != null; q = q.next, dpos = 0)
                {
                    int tmp = dpos + rest;
                    if (tmp > q.len)
                    {
                        tmp = q.len;
                    }
                    tmp -= dpos;

                    pointer.memcpy(p_data + spos, q.payload + dpos, tmp);
                    spos += tmp;
                    dpos += tmp;
                    rest -= tmp;
                    if (rest == 0)
                    {
                        if (dpos == q.len)
                        {
                            q    = q.next;
                            dpos = 0;
                            if (q == null)
                            {
                                if (buf != null)
                                {
                                    m_lwIP.pbuf_free(buf);
                                }
                                buf = p = (m_RecvDataQueue.Count > 0) ? m_RecvDataQueue.Dequeue() : null;
                            }
                        }
                        goto end;
                    }
                }
                if (buf != null)
                {
                    m_lwIP.pbuf_free(buf);
                }
                buf = p = (m_RecvDataQueue.Count > 0) ? m_RecvDataQueue.Dequeue() : null;
            } while (p != null);

end:
            m_RecvPBuf    = buf;
            m_RecvPBufPos = p;
            m_RecvPos     = dpos;

            return(spos);
        }
Esempio n. 19
0
        public override bool Equals(object obj)
        {
            pointer a = obj as pointer;

            if (a == null)
            {
                return(base.Equals(obj));
            }

            return(m_Data == a.m_Data && m_Offset == a.m_Offset);
        }
Esempio n. 20
0
 public tcp_hdr(byte[] buffer, int offset)
     : base(buffer, offset)
 {
     _src   = new pointer(data, offset + 0);               /* ushort */
     _dest  = new pointer(data, offset + 2);               /* ushort */
     _seqno = new pointer(data, offset + 4);               /* uint */
     _ackno = new pointer(data, offset + 8);               /* uint */
     __hdrlen_rsvd_flags = new pointer(data, offset + 12); /* ushort */
     _wnd    = new pointer(data, offset + 14);             /* ushort */
     _chksum = new pointer(data, offset + 16);             /* ushort */
     _urgp   = new pointer(data, offset + 18);             /* ushort */
 }
Esempio n. 21
0
 public _CrtMemBlockHeader(pointer src, int offset,
                           _CrtMemBlockHeader pBlockHeaderNext, _CrtMemBlockHeader pBlockHeaderPrev,
                           string szFileName, int nLine, int nDataSize, int nBlockUse, int lRequest)
     : base(src, offset)
 {
     this.pBlockHeaderNext = pBlockHeaderNext;
     this.pBlockHeaderPrev = pBlockHeaderPrev;
     this.szFileName       = szFileName;
     this.nLine            = nLine;
     this.nDataSize        = nDataSize;
     this.nBlockUse        = nBlockUse;
     this.lRequest         = lRequest;
 }
Esempio n. 22
0
            public T get(pointer owner)
            {
                System.Reflection.ConstructorInfo ci;

                ci = typeof(T).GetConstructor(new Type[] { typeof(byte[]), typeof(int) });
                if (ci != null)
                {
                    return((T)ci.Invoke(new object[] { owner.m_Data, owner.offset + _offset }));
                }

                ci = typeof(T).GetConstructor(new Type[] { typeof(pointer), typeof(int) });
                return((T)ci.Invoke(new object[] { owner, owner.data, owner.offset + _offset }));
            }
Esempio n. 23
0
        public ER GetMemoryBlock(out pointer p_blk, int blksz, TMO tmout)
        {
            ER ret;

            p_blk = null;

            //if (p_blk == null)
            //	return ER.E_PAR;

            for (; ;)
            {
                LinkedListNode <pointer> Node = m_MpfQueue.First;

                if (Node != null)
                {
                    p_blk = Node.Value;
                    m_MpfQueue.RemoveFirst();
                    break;
                }

                if (tmout == 0)
                {
                    return(ER.E_TMOUT);
                }

                Task task = m_Nucleus.GetTask(ID.TSK_SELF);

                if (task == null)
                {
                    return(ER.E_CTX);
                }

                ret = task.Wait(m_TskQueue, TSKWAIT.TTW_MPF, m_MpfID, tmout);

                switch (ret)
                {
                case ER.E_OK:
                    continue;

                case ER.E_TMOUT:
                    return(ER.E_TMOUT);

                default:
                    return(ER.E_RLWAI);
                }
            }

            return(ER.E_OK);
        }
Esempio n. 24
0
        private err_t SentData(object arg, tcp_pcb tpcb, ushort space)
        {
            err_t   err  = err_t.ERR_OK;
            int     rest = space;
            int     pos  = m_SendPos;
            pointer buf  = m_SendPBuf;
            int     len  = m_SendLen;

            if (buf != null)
            {
                int tmp = rest;
                if (tmp > len)
                {
                    tmp = len;
                }

                err = m_lwIP.tcp.tcp_write(m_TPcb, new pointer(buf, pos), (ushort)tmp, 0);
                if (err != err_t.ERR_OK)
                {
                    return(err);
                }

                pos  += tmp;
                rest -= tmp;
                if (pos == len)
                {
                    pos = 0;
                    buf = null;
                    len = 0;
                }
            }

            m_SendPBuf = buf;
            m_SendPos  = pos;
            m_SendLen  = len;

            if ((m_SendPBuf == null) && (rest > 0))
            {
                if (m_SendTaskQueue.First != null)
                {
                    Task task = m_SendTaskQueue.First.Value;
                    m_SendTaskQueue.RemoveFirst();

                    task.ReleaseWait();
                }
            }

            return(err);
        }
Esempio n. 25
0
        public MemoryPoolFixedsize(ID mpfid, ref T_CMPF pk_cmpf, Nucleus pNucleus)
        {
            pointer Block;

            m_MpfID   = mpfid;
            m_cmpf    = pk_cmpf;
            m_Nucleus = pNucleus;

            for (int i = 0; i < pk_cmpf.blkcnt; i++)
            {
                Block = new pointer(pk_cmpf.addr, i * pk_cmpf.blksz);
                pointer.memset(Block, 0, pk_cmpf.blksz);
                m_MpfQueue.AddLast(Block);
            }
        }
Esempio n. 26
0
        public static int memcmp(pointer p1, pointer p2, int len)
        {
            int pos1 = p1.m_Offset, pos2 = p2.m_Offset;
            int end = pos1 + len;

            for (; pos1 < end; pos1++, pos2++)
            {
                int diff = p2.m_Data[pos2] - p1.m_Data[pos1];
                if (diff != 0)
                {
                    return(diff);
                }
            }
            return(0);
        }
Esempio n. 27
0
 public static void stats_display_proto(stats_proto proto, pointer name)
 {
     LWIP_PLATFORM_DIAG(("\n{0}\n\t", name));
     LWIP_PLATFORM_DIAG(("xmit: {0}\n\t", proto.xmit));
     LWIP_PLATFORM_DIAG(("recv: {0}\n\t", proto.recv));
     LWIP_PLATFORM_DIAG(("fw: {0}\n\t", proto.fw));
     LWIP_PLATFORM_DIAG(("drop: {0}\n\t", proto.drop));
     LWIP_PLATFORM_DIAG(("chkerr: {0}\n\t", proto.chkerr));
     LWIP_PLATFORM_DIAG(("lenerr: {0}\n\t", proto.lenerr));
     LWIP_PLATFORM_DIAG(("memerr: {0}\n\t", proto.memerr));
     LWIP_PLATFORM_DIAG(("rterr: {0}\n\t", proto.rterr));
     LWIP_PLATFORM_DIAG(("proterr: {0}\n\t", proto.proterr));
     LWIP_PLATFORM_DIAG(("opterr: {0}\n\t", proto.opterr));
     LWIP_PLATFORM_DIAG(("err: {0}\n\t", proto.err));
     LWIP_PLATFORM_DIAG(("cachehit: {0}\n", proto.cachehit));
 }
Esempio n. 28
0
        public ER ReleaseMemoryBlock(pointer blk)
        {
            if (blk == null)
            {
                return(ER.E_PAR);
            }

            //if ((int)blk != 0)
            //	return ER.E_PAR;

            System.Diagnostics.Debug.Assert((blk >= m_cmpl.addr) && (blk < m_cmpl.addr + m_cmpl.mplsz));

#if DEBUG
            _CrtMemBlockHeader.DelBlock(m_pFirstBlock, m_pLastBlock, blk);
            m_nBlockCount--;
#endif
            TMemNode Mem = TMemNode.GetNode(blk);

            if (!Free(Mem))
            {
                return(ER.E_PAR);
            }

            UpdateFreeSize();

#if DEBUG
            pointer.memset(Mem + 1, 0xDD, Mem.Size - TMemNode.length);
#endif
            for (LinkedListNode <Task> Node = m_TskQueue.First; Node != null; Node = Node.Next)
            {
                Task task = Node.Value;
                if (task.MemoryBlockSize <= m_MaxSize)
                {
                    m_TskQueue.Remove(Node);

                    if (!task.ReleaseWait())
                    {
                        return(ER.E_RLWAI);
                    }
                }
            }

            return(ER.E_OK);
        }
Esempio n. 29
0
        /*
         * Curt McDowell
         * Broadcom Corp.
         * [email protected]
         *
         * IP checksum two bytes at a time with support for
         * unaligned buffer.
         * Works for len up to and including 0x20000.
         * by Curt McDowell, Broadcom Corp. 12/08/2005
         *
         * @param dataptr points to start of data to be summed at any boundary
         * @param len length of data to be summed
         * @return host order (!) lwip checksum (non-inverted Internet sum)
         */
        private static ushort lwip_standard_chksum(pointer dataptr, ushort len)
        {
            int    pb = 0, ps = 0;
            ushort t   = 0;
            uint   sum = 0;
            int    odd = (pb & 1);

            /* Get aligned to ushort */
            if (odd != 0 && len > 0)
            {
                ((int)t)[1] = pb++;
                len--;
            }

            /* Add the bulk of the data */
            ps = (ushort)(byte[])pb;
            while (len > 1)
            {
                sum += ps++;
                len -= 2;
            }

            /* Consume left-over byte, if any */
            if (len > 0)
            {
                ((int)t)[0] = *(int)ps;
            }

            /* Add end bytes */
            sum += t;

            /* Fold 32-bit sum to 16 bits
             * calling this twice is propably faster than if statements... */
            sum = FOLD_U32T(sum);
            sum = FOLD_U32T(sum);

            /* Swap if alignment was odd */
            if (odd)
            {
                sum = SWAP_BYTES_IN_WORD(sum);
            }

            return((ushort)sum);
        }
Esempio n. 30
0
        private static int CopyToPBuf(pbuf dst, pointer src, int len)
        {
            int pos = 0, rest = len;

            for (pbuf q = dst; q != null; q = q.next)
            {
                int tmp = rest;
                if (tmp > q.len)
                {
                    tmp = q.len;
                }

                pointer.memcpy(q.payload, src + pos, tmp);

                pos  += tmp;
                rest -= tmp;
            }

            return(pos);
        }