destiny_addr_mode

    This function depending on the arguments returns the amount of bits to be
    used by the destiny address.

    Keyword arguments:
    pkt -- packet object instance
484843
def destiny_addr_mode(pkt):
    
    if pkt.m == 0 and pkt.dac == 0:
        if pkt.dam == 0x0:
            return 16
        elif pkt.dam == 0x1:
            return 8
        elif pkt.dam == 0x2:
            return 2
        else:
            return 0
    elif pkt.m == 0 and pkt.dac == 1:
        if pkt.dam == 0x0:
            raise Exception('reserved')
        elif pkt.dam == 0x1:
            return 8
        elif pkt.dam == 0x2:
            return 2
        else:
            return 0
    elif pkt.m == 1 and pkt.dac == 0:
        if pkt.dam == 0x0:
            return 16
        elif pkt.dam == 0x1:
            return 6
        elif pkt.dam == 0x2:
            return 4
        elif pkt.dam == 0x3:
            return 1
    elif pkt.m == 1 and pkt.dac == 1:
        if pkt.dam == 0x0:
            return 6
        elif pkt.dam == 0x1:
            raise Exception('reserved')
        elif pkt.dam == 0x2:
            raise Exception('reserved')
        elif pkt.dam == 0x3:
            raise Exception('reserved')
627527
def btc_make_p2wpkh_address( pubkey_hex ):
    
    pubkey_hex = keylib.key_formatting.compress(pubkey_hex)
    hash160_bin = hashing.bin_hash160(pubkey_hex.decode('hex'))
    return segwit_addr_encode(hash160_bin)
1279653
def packets(self):
        

        if not self.get_object_by_type('cappacket'):
            for index in range(0, self.read_stats()['packets']):
                XenaCapturePacket(parent=self, index='{}/{}'.format(self.index, index))
        return {p.id: p for p in self.get_objects_by_type('cappacket')}
3565
def post_build(self, pkt, pay):
        
        if conf.contribs['CAN']['swap-bytes']:
            return CAN.inv_endianness(pkt) + pay
        return pkt + pay
997408
def _low_level_dispatch(pcapdev, devname, pktqueue):
        '''
        
        '''
        while LLNetReal.running:
            # a non-zero timeout value is ok here; this is an
            # independent thread that handles input for this
            # one pcap device.  it throws any packets received
            # into the shared queue (which is read by the actual
            # user code)
            pktinfo = pcapdev.recv_packet(timeout=0.2)
            if pktinfo is None:
                continue
            pktqueue.put( (devname,pcapdev.dlt,pktinfo) )

        log_debug("Receiver thread for {} exiting".format(devname))
        stats = pcapdev.stats()
        log_debug("Final device statistics {}: {} received, {} dropped, {} dropped/if".format(devname, stats.ps_recv, stats.ps_drop, stats.ps_ifdrop))
849704
def get_sector_info(self, addr):
        
        assert self.region is not None
        if not self.region.contains_address(addr):
            return None

        info = SectorInfo()
        info.erase_weight = self.region.erase_sector_weight
        info.size = self.region.blocksize
        info.base_addr = addr - (addr % info.size)
        return info
1276207
def process_packet(self, pkt):
        """"""

        # check if this could be a valid packet before parsing
        # this reduces the CPU load significantly
        if not ( \
            ((self.mode & ScannerMode.MODE_IBEACON) and (pkt[19:23] == b"\x4c\x00\x02\x15")) or \
            ((self.mode & ScannerMode.MODE_EDDYSTONE) and (pkt[19:21] == b"\xaa\xfe")) or \
            ((self.mode & ScannerMode.MODE_ESTIMOTE) and (pkt[19:21] == b"\x9a\xfe"))):
            return

        bt_addr = bt_addr_to_string(pkt[7:13])
        rssi = bin_to_int(pkt[-1])
        # strip bluetooth address and parse packet
        packet = parse_packet(pkt[14:-1])

        # return if packet was not an beacon advertisement
        if not packet:
            return

        # we need to remeber which eddystone beacon has which bt address
        # because the TLM and URL frames do not contain the namespace and instance
        self.save_bt_addr(packet, bt_addr)
        # properties holds the identifying information for a beacon
        # e.g. instance and namespace for eddystone; uuid, major, minor for iBeacon
        properties = self.get_properties(packet, bt_addr)

        if self.device_filter is None and self.packet_filter is None:
            # no filters selected
            self.callback(bt_addr, rssi, packet, properties)

        elif self.device_filter is None:
            # filter by packet type
            if is_one_of(packet, self.packet_filter):
                self.callback(bt_addr, rssi, packet, properties)
        else:
            # filter by device and packet type
            if self.packet_filter and not is_one_of(packet, self.packet_filter):
                # return if packet filter does not match
                return

            # iterate over filters and call .matches() on each
            for filtr in self.device_filter:
                if isinstance(filtr, BtAddrFilter):
                    if filtr.matches({'bt_addr':bt_addr}):
                        self.callback(bt_addr, rssi, packet, properties)
                        return

                elif filtr.matches(properties):
                    self.callback(bt_addr, rssi, packet, properties)
                    return
1332029
def pkt2uptime(pkt, HZ=100):
    """"""
    if not isinstance(pkt, Packet):
        raise TypeError("Not a TCP packet")
    if isinstance(pkt, NoPayload):
        raise TypeError("Not a TCP packet")
    if not isinstance(pkt, TCP):
        return pkt2uptime(pkt.payload)
    for opt in pkt.options:
        if opt[0] == "Timestamp":
            # t = pkt.time - opt[1][0] * 1.0/HZ
            # return time.ctime(t)
            t = opt[1][0] / HZ
            return t
    raise TypeError("No timestamp option")
1213199
def on_packet_received(self, pkt):
        
        if not pkt:
            return
        if self.store:
            self.lst.append(pkt)
        if self.prn:
            result = self.prn(pkt)
            if result is not None:
                print(result)
1270457
def validate(self, pkt, messages=None):
        
        valid = True

        for f in self.fields:
            try:
                value = getattr(pkt, f.name)
            except AttributeError:
                valid = False
                if messages is not None:
                    msg = "Telemetry field mismatch for packet '%s'.  "
                    msg += "Unable to retrieve value for %s in Packet."
                    values = self.name, f.name
                    messages.append(msg % values)
                break

            if f.validate(value, messages) is False:
                valid = False

        return valid
983744
def get(key, default=-1):
        """"""
        if isinstance(key, int):
            return Packet(key)
        if key not in Packet._member_map_:
            extend_enum(Packet, key, default)
        return Packet[key]
275478
def i2repr(self, pkt, x):
        """"""
        if len(hex(self.i2m(pkt, x))) < 7:  # short address
            return hex(self.i2m(pkt, x))
        else:  # long address
            x = "%016x" % self.i2m(pkt, x)
            return ":".join(["%s%s" % (x[i], x[i + 1]) for i in range(0, len(x), 2)])
368757
public static int pxToDp(Context context, int px) {
    DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
    return (int) ((px / displayMetrics.density) + 0.5);
  }
715527
def encode_packet(packet: dict) -> str:
    
    if packet['protocol'] == 'rfdebug':
        return '10;RFDEBUG=' + packet['command'] + ';'
    elif packet['protocol'] == 'rfudebug':
        return '10;RFDEBUG=' + packet['command'] + ';'
    else:
        return SWITCH_COMMAND_TEMPLATE.format(
            node=PacketHeader.master.value,
            **packet
        )
1099693
def parse_TKIP_hdr(pkt):
    """"""
    # Note: FCS bit is not handled
    assert pkt.FCfield.protected

    # 802.11i - 8.3.2.2
    tkip_layer = pkt[Dot11TKIP]
    payload = tkip_layer.data

    # IV
    if not tkip_layer.ext_iv:
        # 802.11i p. 46
        raise ValueError("Extended IV must be set for TKIP")
    TSC0 = tkip_layer.TSC0
    TSC1 = tkip_layer.TSC1
    WEPseed = tkip_layer.WEPSeed

    # Extended IV
    TSC2 = tkip_layer.TSC2
    TSC3 = tkip_layer.TSC3
    TSC4 = tkip_layer.TSC4
    TSC5 = tkip_layer.TSC5

    # 802.11i p. 46
    assert (TSC1 | 0x20) & 0x7f == WEPseed

    TA = [orb(e) for e in mac2str(pkt.addr2)]
    TSC = [TSC0, TSC1, TSC2, TSC3, TSC4, TSC5]

    return TSC, TA, payload
727493
def _is_tp(pkt):
        """"""

        tp = [SOMEIP.TYPE_TP_REQUEST, SOMEIP.TYPE_TP_REQUEST_NO_RET,
              SOMEIP.TYPE_TP_NOTIFICATION, SOMEIP.TYPE_TP_RESPONSE,
              SOMEIP.TYPE_TP_ERROR]
        if isinstance(pkt, Packet):
            return pkt.msg_type in tp
        else:
            return pkt[15] in tp
262392
def write(self, pkt):
        
        if not self.header_present:
            self._write_header(pkt)
        if type(pkt) is bytes:
            self._write_packet(pkt)
        else:
            for p in pkt:
                self._write_packet(p)