简体   繁体   中英

How to implement ACTION (move/rename, set permissions) operation in J2ME Bluetooth OBEX?

Bluetooth FTP specification says I need to use ACTION operation, here's a page

But the ClentSession provides only GET and PUT operations, and nothing mentioned in javadocs.

here's how the create file operation looks, it's pretty easy

    public void create() throws IOException {
        HeaderSet hs = cs.createHeaderSet();
        hs.setHeader(HeaderSet.NAME, file);
        op = cs.put(hs);
        OutputStream os = op.openOutputStream();
        os.close();
        op.close();
    }

Question 1: How do I implement ACTION operation with custom headers to perform move/rename and set permissions? It should be possible without JSR82 OBEX API. Please help me to do this.

Question 2: Did I understand how to set permissions? According to OBEX_Errata Compiled For 1.3.pdf (thanks alanjmcf!)

1

2

So, to set read-only, I should do the following:

    int a = 0;

    //byte 0 //zero
    //byte 1 //user
    //byte 2 //group
    //byte 3 //other

    //set read for user
    a |= (1 << 7); //8th bit - byte 1, bit 0 -> set to 1
    // a = 10000000

    //for group
    a |= (1 << 15); //16th bit - byte 2, bit 0 -> set to 1
    // a = 1000000010000000

    //for other
    a |= (1 << 23); //24th bit - byte 3, bit 0 -> set to 1
    // a = 100000001000000010000000

    //or simply
    private static final int READ = 8421504 //1000,0000,1000,0000,1000,0000
    int value = 0 | READ;

    //========== calculate write constant =========
    a = 0;
    a |= (1 << 8); //write user
    a |= (1 << 16); //write group
    a |= (1 << 24); //write other
    // a = 1000000010000000100000000
    private static final int WRITE = 16843008 // 1,0000,0001,0000,0001,0000,0000

    //========= calculate delete constant ==========
    a = 0;
    a |= (1 << 9); //delete user
    a |= (1 << 17); //delete group
    a |= (1 << 25); //delete other
    //a = 10000000100000001000000000
    private static final DELETE = 33686016; //10,0000,0010,0000,0010,0000,0000

    //========= calculate modify constant ==========
    a = 0;
    a |= (1 << (7 + 7)); //modify user
    a |= (1 << (15 + 7)); //modify group
    a |= (1 << (23 + 7)); //modify other
    //a = 1000000010000000100000000000000
    private static final MODIFY = 1077952512; // 100,0000,0100,0000,0100,0000,0000,0000


    // now, if i want to set read-write-delete-modify, I will do the following:
    int rwdm = 0 | READ | WRITE | DELETE | MODIFY;
    // and put the value to the header... am I right?

if right, the only problem remains the question 1: how do I make ACTION operation and how to set the headers.

Note that the text you quote from the Bluetooth FTP specification mentions three headers: ActionId, Name, DestName. So you need to add one NAME header and one DestName header. Jsr-82 apparently doesn't define the const for that (new) header so quoting from the OBEX specification:

MODIFICATION
2.1 OBEX Headers

HI identifier | Header name | Description  
0x94            Action Id     Specifies the action to be performed (used in ACTION operation)  
0x15            DestName      The destination object name (used in certain ACTION operations)  
0xD6            Permissions   4 byte bit mask for setting permissions  
0x17 to 0x2F    Reserved for future use.  This range includes all combinations of the upper 2 bits

So create the following etc. (My Java's a bit rusty)

static final int DEST_NAME = 0x15;

And use that in your code.

[ADD] All the operations (actions) that are actions use the ACTION operation! :-,) That is use OBEX opcode ACTION instead of PUT or GET etc. The value of opcode ACTION is 0x86 .

I'm reading this from "OBEX_Errata Compiled For 1.3.pdf". The IrDA did charge for specifications but seem to now provide them on request ( http://www.irda.org ). Ask for a copy of the latest OBEX specs (1.5 IIRC). I've done so myself but not yet got a response. Or you could maybe try googling for say "move/rename object action" to get that '1.3 Errata' PDF.

Anyway, if Java prevents you from using new Opcodes (only allowing GET and PUT) and also prevents you from using new HeaderId values then you can't proceed anyway. :-( *(There's no reason for them to do that as HeaderId encodes the data type it contains).

After having another look at the Java API I can't see any way of sending an arbitrary command over ClientSession. You'd have to manually build the packets, connect to the OBEX service and then send and receive packets over that connection. It isn't too difficult to build the packets...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM