No BSD License  

Highlights from
Home Networking Basis

Home Networking Basis

by

 

11 Aug 2003 (Updated )

M-files for chapters 2-10 and Simulink models for Ethernet and Wireless Ethernet.

hcs.m
%Variable initialization
gx=[1 1 1 0 1 0 1 0 1];
hx=[1 1 1 1 0 1 1 1];
FT=[0 0 0 0 0 0 0 0];
RSVD=[0];
PRI=[0 1 0];
SI=[0 1 0 0];
PE=[0 0 0 0 1 0 1 0];
HCS=[0 0 0 0 0 0 0 0];
FC=[FT RSVD PRI SI PE HCS];
DA=ceil(rand(1,48)*2-1);
SA=ceil(rand(1,48)*2-1);
FC2SA=[FC DA SA];
%Mathematically, the CRC value corresponding to a given frame 
%is defined by the following procedure.
%  The first 8 bits of the input bit sequence are complemented.
FC2SA(1:8)=bitcmp(FC2SA(1:8),1);
%  The 128 bits of the sequence is multiplied by x^8 and divided 
%  by G(x), producing a remainder R(x) of degree <= 7.
FC2SA=[FC2SA zeros(1,8)];
rx=FC2SA(1:8);
for i=1:128
    nm=[rx FC2SA(i+8)];
    if nm(1)==1
        rx=xor(nm(2:9),gx(2:9));
    else
        rx=nm(2:9);
    end
end
%  R(x) is multiplied by H(x) to produce N(x)
nx(1:8)=rx;
for i=1:7
    if hx(i+1)==1
        nx(i+1:i+7)=xor(rx(1:7),nx(i+1:i+7));
        nx(i+8)=rx(8);
    else
        nx(i+8)=0;
    end
end
%  N(x) is divided by G(x), producing a remainder R'(x) of degree <= 7.
rrx=nx(1:8);
for i=1:7
    nm=[rrx nx(i+8)];
    if nm(1)==1
        rrx=xor(nm(2:9),gx(2:9));
    else
        rrx=nm(2:9);
    end
end
%  The bit sequence is complemented and the result is the CRC'.
rrx=bitcmp(rrx,1);
%The 8 bits of the CRC' are placed in the HCS field so that x^7 is 
%the least-significant bit of the octet and x^0 term is the 
%most-significant bit of the octet. The bits of the CRC' are thus 
%transmitted in the order x^7, x^6, .. x^1, x^0. 

Contact us