コード例 #1
0
def encode(input_octets, rate_index):
    service_bits = np.zeros(16, int)
    data_bits = util.shiftout(input_octets, 8)
    data_bits = np.r_[service_bits, data_bits, crc.FCS(data_bits)]
    signal_subcarriers = subcarriersFromBits(plcp_bits(wifi_802_11_rates[rate_index], input_octets.size+4), wifi_802_11_rates[0], 0)
    data_subcarriers = subcarriersFromBits(data_bits, wifi_802_11_rates[rate_index], 0x5d)
    return ofdm.encode(signal_subcarriers, data_subcarriers)
コード例 #2
0
ファイル: crc.py プロジェクト: nikhilYadala/blurt
def lut_bootstrap(b, new_L):
    global L, _lut, M, s, M_L, m
    M = b.size-1
    if L is None:
        fn = lambda a: util.shiftin(remainder1(a, b)[::-1], M)[0]
    else:
        fn = lambda a: remainder5(a, True)
    lut = np.empty(1<<new_L, int)
    for i in xrange(lut.size):
        lut[i] = fn(np.r_[util.shiftout(np.r_[i], new_L)[::-1], np.zeros(M, int)])
    _lut = lut
    L = new_L
    s = M-L
    M_L = M/L
    m = (1<<M)-1
コード例 #3
0
def FCS(calculationFields):
    k = calculationFields.size
    return 1 & ~remainder(
        np.r_[np.ones(32, int), np.zeros(k, int)]
        ^ np.r_[calculationFields, np.zeros(32, int)], G)


def checkFCS(frame):
    k = frame.size
    x = remainder(
        np.r_[np.ones(32, int), np.zeros(k, int)]
        ^ np.r_[frame, np.zeros(32, int)], G)
    return all(x == correct_remainder)


remainder = lambda a, b: remainder5(a)

# The FCS field is transmitted commencing with the coefficient of the highest-order term.
# polynomial from x^32 down to x^0: 0b100000100110000010001110110110111
CRC32_802_11_FCS_G = 0b100000100110000010001110110110111
CRC32_802_11_FCS_remainder = 0b11000111000001001101110101111011
G = util.shiftout(np.r_[CRC32_802_11_FCS_G], 33)[::-1]
correct_remainder = util.shiftout(np.r_[CRC32_802_11_FCS_remainder], 32)[::-1]

L = None
fn = 'crc_lut_16'
if not lut_load(fn):
    lut_bootstrap(G, 8)
    lut_bootstrap(G, 16)
    lut_dump(fn)
コード例 #4
0
def plcp_bits(rate, octets):
    plcp_rate = util.rev(rate.encoding, 4)
    plcp = plcp_rate | (octets << 5)
    parity = (util.mul(plcp, 0x1FFFF) >> 16) & 1
    plcp |= parity << 17
    return util.shiftout(np.array([plcp]), 18)
コード例 #5
0
ファイル: crc.py プロジェクト: homelee/blurt
        with open(fn, 'rb') as f:
            _lut, M, L, s, M_L, m = pickle.load(f)
        return True
    except:
        return False

def FCS(calculationFields):
    k = calculationFields.size
    return 1 & ~remainder(np.r_[np.ones(32, int), np.zeros(k, int)] ^ np.r_[calculationFields, np.zeros(32, int)], G)

def checkFCS(frame):
    k = frame.size
    x = remainder(np.r_[np.ones(32, int), np.zeros(k, int)] ^ np.r_[frame, np.zeros(32, int)], G)
    return all(x == correct_remainder)

remainder = lambda a, b: remainder5(a)

# The FCS field is transmitted commencing with the coefficient of the highest-order term.
# polynomial from x^32 down to x^0: 0b100000100110000010001110110110111
CRC32_802_11_FCS_G = 0b100000100110000010001110110110111
CRC32_802_11_FCS_remainder = 0b11000111000001001101110101111011
G = util.shiftout(np.r_[CRC32_802_11_FCS_G], 33)[::-1]
correct_remainder = util.shiftout(np.r_[CRC32_802_11_FCS_remainder], 32)[::-1]

L = None
fn = 'crc_lut_16'
if not lut_load(fn):
    lut_bootstrap(G, 8)
    lut_bootstrap(G, 16)
    lut_dump(fn)