View Full Version : PRS-500 How to get reader's serial # through USB?


VladSukhoy
02-09-2007, 10:15 PM
Hi,
Working on multiple reader support in my mountable filesystem project..
is there a way to figure out serial number or any other persistent identifier for the reader? Serial number would be great, but pretty much anything equivalent is ok.

kovidgoyal
02-09-2007, 11:08 PM
The serial number is reported in the about page of the reader, but is not reported over the USB interface (verify with lsusb).

scotty1024
02-09-2007, 11:27 PM
You do realize you don't need a serial number right?

The libusb library automatically provides arbitration. I've mounted both my wife's and my own Sony Reader on the same Mac with out any special coding to support it.

VladSukhoy
02-09-2007, 11:39 PM
@scotty1024 Yes, I do realize that I can implement the functionality w/o serial number, nevertheless thank you, it is also possible that you understand my intent better than me..
But the idea is to implement automatic on-demand binding of prs units without any special listener application with just FUSE module itself (so that upon access the FUSE module is able to restore access to the needed device even if it was reconnected, switched its usb bus location, etc.) and also having persistent directory name for each connected device could be useful. Serial # is the natural choice in building such a name.

scotty1024
02-09-2007, 11:45 PM
Actually the reader protocol is pretty disconnect-able. I'm not really certain why they've put the big "Don't disconnect me" icon permanently up on the screen.

In my examination of the USB protocol it seems as though the units can be named.

I think it makes more sense to an Average Joe to have his Sony show up as "Average Joe" than "Sony 3456108". Sort of like an iPod. :)

kovidgoyal
02-09-2007, 11:56 PM
I think the button is for people who get anxiety attacks when disconnecting USB devices. Interesting, can you provide a packet stream for naming the device?

VladSukhoy
02-10-2007, 12:21 AM
any insight on how to obtain that serial from About page?
I noticed stuff like /Data/tmp/serial.img and also /Data/tmp/info/serial.. Looks like this is it, but.. here is md5 of the first one from my reader:
MD5 (serial.img) = 644471de540300d942c874f4240f16e1
and the second one:
MD5 (serial) = 3e72e87134c816a791cf064d3d5ac3e5

VladSukhoy
02-10-2007, 12:22 AM
I wonder if you guys have different checksums - if so then I can use that as unique id, and get over it..

kovidgoyal
02-10-2007, 12:32 AM
d777f0fd8c4368d8f1007b6890b20727 serial.img
666dd21918e73a6c753a99983dd216c0 serial

VladSukhoy
02-10-2007, 12:34 AM
starts with 666 ;)
thx, this should be ok for now.

scotty1024
02-10-2007, 03:50 AM
I think the button is for people who get anxiety attacks when disconnecting USB devices. Interesting, can you provide a packet stream for naming the device?

THe button is for people used to dealing with block protocols, where the host operating system has to do a block mounting of the filesystem and thus has to write out super block data to unmount the filesystem prior to it being un-plugged.

The Sony of course uses a high level VFS based protocol and doesn't deal in anything as crude as blocks of raw disk data. :)

I've decoded the Sony Heart Beat.

They do this once per second to make sure the Sony Reader is still there (or perhaps poll to see if the Reader has anything to say?):

0x40 0x80 : 0x00 0x01 0x00 0x00 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0xc0 0x81 : 0x00 0x10 0x00 0x00 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x0c 0x00 0x00 0x00
0x00 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
BULKR 0x81 : 0x02 0x00 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x08 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x40 0x80 : 0x00 0x10 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x10 0x00 0x00 0x00
0x02 0x00 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0xc0 0x81 : 0x00 0x10 0x00 0x00 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x0c 0x00 0x00 0x00
0x00 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00

scotty1024
02-10-2007, 04:03 AM
Eject button sends...

0x40 0x80 : 0x01 0x00 0x00 0x00 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x04 0x00 0x00 0x00
0x00 0x00 0x00 0x00
0xc0 0x81 : 0x00 0x10 0x00 0x00 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x0c 0x00 0x00 0x00
0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00


They stop polling the device and the "Don't disconnect me" icon tries to disappear on the Reader display.

Thats the standard "End of Session", so I think the real question is "What do they send to make the 'Don't disconnect me' icon show up?"

kovidgoyal
02-10-2007, 04:38 AM
In my experience the reader never spontaneously has anything to say. The protocol seems to be entirely host driven. I also don't understand why they'd need to poll the reader. The USB system on the host should inform them if the device is disconnected.

Just goes to show that the heart really is good for nothing ;-)


The Sony of course uses a high level VFS based protocol and doesn't deal in anything as crude as blocks of raw disk data. :)

I've decoded the Sony Heart Beat.

They do this once per second to make sure the Sony Reader is still there (or perhaps poll to see if the Reader has anything to say?):

0x40 0x80 : 0x00 0x01 0x00 0x00 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0xc0 0x81 : 0x00 0x10 0x00 0x00 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x0c 0x00 0x00 0x00
0x00 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
BULKR 0x81 : 0x02 0x00 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x08 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x40 0x80 : 0x00 0x10 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x10 0x00 0x00 0x00
0x02 0x00 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0xc0 0x81 : 0x00 0x10 0x00 0x00 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x0c 0x00 0x00 0x00
0x00 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00

scotty1024
02-10-2007, 04:55 AM
I agree you'd think disconnect could be a USB event to them so that's why I suspect DRM conversation perhaps?

Anyway, this is a change in the new firmware I think, this is the unlock device packet being sent by the new CONNECT software:

06 01 00 00 01 00 00 00 00 00 00 00 08 00 00 00 ................
2D 31 00 00 00 00 00 00 -1.....

You will note it is now 8 bytes of payload. Apparently the Reader still supports the older 4 byte model.

scotty1024
02-10-2007, 05:04 AM
Hmm looks like Igorsky may have gotten one wrong...

0x40 0x80 : 0x01 0x00 0x00 0x00 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x04 0x00 0x00 0x00
0x01 0x00 0x00 0x00
0xc0 0x81 : 0x00 0x10 0x00 0x00 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x0c 0x00 0x00 0x00
0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00


So I'm thinking command number 1 is really SessionBeginEnd not ReqEndSession with the payload of DWORD 0 for end and 1 for start.

I'm going to try this and see if that turns on the "Don't disconnect me" icon.

scotty1024
02-10-2007, 06:22 AM
In my experience the reader never spontaneously has anything to say.

...

Just goes to show that the heart really is good for nothing ;-)

I just caught this off one of the heart beat's....

Result in bulk transfer was:
02 00 01 00 00 00 00 00 00 00 00 00 08 00 00 00 ................
00 00 02 01 00 00 00 00 .......


Right after that CONNECT issued this:
53 00 00 00 01 00 00 00 00 00 00 00 07 00 00 00 S...............
03 00 00 00 62 3A 2f ....b:/

That was during the initial startup after plugging the Reader into CONNECT.

Hmm, did the Reader suddenly announce "I've got a SD card!"???

I'll have to try this again with MS and nothing...

kovidgoyal
02-10-2007, 02:05 PM
EDIT: Looking at my code, I always sent 8bytes as the key, never 4

Hmm the screen lock code is still 4 characters in length, so this seems to be pretty pointless.


Anyway, this is a change in the new firmware I think, this is the unlock device packet being sent by the new CONNECT software:

06 01 00 00 01 00 00 00 00 00 00 00 08 00 00 00 ................
2D 31 00 00 00 00 00 00 -1.....

You will note it is now 8 bytes of payload. Apparently the Reader still supports the older 4 byte model.

kovidgoyal
02-10-2007, 02:24 PM
You are correct that does cause the do not disconnect to show up. Interestingly, sending the end session changes the text to 'USB Connected' but not the icon. A SONY bug?

Hmm looks like Igorsky may have gotten one wrong...

0x40 0x80 : 0x01 0x00 0x00 0x00 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x04 0x00 0x00 0x00
0x01 0x00 0x00 0x00
0xc0 0x81 : 0x00 0x10 0x00 0x00 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x0c 0x00 0x00 0x00
0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00


So I'm thinking command number 1 is really SessionBeginEnd not ReqEndSession with the payload of DWORD 0 for end and 1 for start.

I'm going to try this and see if that turns on the "Don't disconnect me" icon.

scotty1024
02-10-2007, 03:13 PM
EDIT: Looking at my code, I always sent 8bytes as the key, never 4

Hmm the screen lock code is still 4 characters in length, so this seems to be pretty pointless.

The --log-packets says 4 and the source code I have says 4...


class UnlockDevice(ShortCommand):
""" Unlock the device """
NUMBER = 0x106 #: Command number
def __init__(self, key=0x312d):
ShortCommand.__init__(self, \
number=UnlockDevice.NUMBER, type=0x01, command=key)

class ShortCommand(Command):

""" A L{Command} whoose data section is 4 bytes long """

SIZE = 20 #: Packet size in bytes
# Usually carries additional information
command = field(start=16, fmt=DWORD)

def __init__(self, number=0x00, type=0x00, command=0x00):
"""
@param number: L{Command.number}
@param type: L{Command.type}
@param command: L{ShortCommand.command}
"""
Command.__init__(self, ShortCommand.SIZE)
self.number = number
self.type = type
self.length = 4
self.command = command


I believe the hard coded "self.length = 4" seals the deal.


res = self.send_validated_command(SetBulkSize(size=0x028 000))
if res.code != 0:
raise ProtocolError("Unable to set bulk size.")
self.send_validated_command(UnlockDevice(key=0x312 d))

kovidgoyal
02-10-2007, 04:09 PM
I'm not sure what vintage your copy of the code is, but revision 209 https://libprs500.kovidgoyal.net/changeset/209 (when I implemented device unlocking) had the following structure for UnlockDevice commands. May have been 4 before that.

class UnlockDevice(Command):
""" Unlock the device """
NUMBER = 0x106 #: Command number
key = stringfield(8, start=16) #: The key defaults to -1

def __init__(self, key='-1\0\0\0\0\0\0'):
Command.__init__(self, 24)
self.number = UnlockDevice.NUMBER
self.type = 0x01
self.length = 8
self.key = key