def seterror(self, p): """Convenience method to set error annotation (or parameters) in `p`. :return: Modified packet with updated parameters/annotations. By default, if packet `p` has a `CRC32` layer, this method will set the 'crcerror' field, otherwise this method will set the 'crcerror' annotation to 1. **Overload this method as needed.** """ hascrc = CRC32.supported(p) hasanno = ANNO.supported(p) if hascrc: p[CRC32].crcerror = 1 elif hasanno: p.setanno('crcerror', 1) else: raise RuntimeError, "[PHY]: seterror() failed to find packet!"
def decode_data(self, p): """Waveform-level decoding of packet payload. :param p: Packet to decode. :return: Decoded data string. """ # check annotations assert isinstance(p, Dot11N) for a in ['cif-rxts', 'dot11n-header', 'dot11n-detect', 'dot11n-rxadded']: errmsg = "[DOT11N]: Cannot find '%s' annotation!"%(a) assert ANNO.supports(p, a), errmsg errmsg = "[DOT11N]: Packet was not added to input!" assert p.hasanno('dot11n-rxadded'), errmsg errmsg = "[DOT11N]: Packet was not detected!" assert p.getanno('dot11n-detect'), errmsg header = p.getanno('dot11n-header') errmsg = "[DOT11N]: Header decoding failed before decode_data()!" assert (header=="success"), errmsg # get parameters to check startidx Ngi = int(DOT11N_TGI*DOT11N_BANDWIDTH) prepad = int(self.MINPAD + DOT11N_TSHORT*DOT11N_BANDWIDTH) startidx = self.receiver.start_index() - prepad ## startidx = -8 # overwrite startidx ## self.receiver.set_start_index(prepad+startidx) # decode payload -> check if startidx is valid y = self.getrxinput(p) data = self.receiver.decode_data(y) # check if decoding error occurred # -> do contents of data match and does CRC pass? crcchk, error = "FAIL", True if (data == str(p.payload)): if not CRC32.haserror(data): crcchk = "OK" error = False # hamming distance between decoded data and packet p hdist = hamming_distance(data, str(p.payload) ) self.log("CRC", p.payload, crcchk=crcchk, error=error, hdist=hdist) # clean up waveform annotations self.delrxwaveform(p) # return decoding parameters param = {'data':data, 'error':error, 'nerror':hdist} # return decoded data return param
def haserror(self, p, *args, **kwargs): """Convenience method to determine if packet `p` has an error. :param args: Additional arguments passed to `CRC32.haserror()`. :param kwargs: Keyword arguments passed to `CRC32.haserror()`. :return: Boolean; true if error is found; false otherwise. By default, this method calls `CRC32.haserror()`. If no `CRC32` layer is found, or no 'crcerror' annotation is found the packet is assumed to be error-free. **Overload this method as needed to change this operation.** :note: This method ignores the CRC when `checkcrc` is set to false. """ hascrc = isinstance(p, Packet) and p.haslayer(CRC32) hasanno = ANNO.supported(p) and p.hasanno('crcerror') crcerror = (hascrc or hasanno) and CRC32.haserror(p,*args,**kwargs) if not self.checkcrc: crcerror = False # assume no error when checkcrc is false return crcerror