maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   How to build a harmattan pre-init runnable component? (https://talk.maemo.org/showthread.php?t=86425)

juiceme 2012-08-31 19:56

How to build a harmattan pre-init runnable component?
 
I do have a bit special requirement for an utility;

I am now experimenting on encrypting the whole home directory on N9, to counter the relaxed security of the device caused by running in open mode. When I am in open mode I want same (or better) security as in closed mode, but on my own terms! I want to protect my own data, not to be protected from the system :D

I have managed to install encfs on the device, and am planning to set up home directory encryption. However, the challenge is to get the passphrase from user in preinit phase, when device is running in sinle user mode.

I am planning on mounting the encfs home just before OS selection (as I am runing nitdroid dual boot) so that both meego and android partitions can be encrypted.

The input that can easily be obtained from user at that phase is just keypresses; volume keys and power key. What I would like to do is build an utility that presents the user a virtual keypad for passphrase entry. However, I am unsure how to do it?

Is there a way of building for example a qt application that has all the needed component libraries linked statically to it, so that there is no need for external dependencies and it can be run stand-alone from the preinit script?

I thought of building some extra functionality to it, in addition of just passphrase entry via virtual keyboard; For example, it could show device owner contact information when incorrect passphrase is typed so that changes of getting lost device back would increase.

juiceme 2012-08-31 20:52

Re: How to build a harmattan pre-init runnable component?
 
Aarrgh, now I suddenly realised the unpleasant truth...
The darn box is not yet running X at preinit stage, right?

So, propably qt is out of scope here, then.
Does anybody have any good suggestions on how to handle it?
Are there any libraries that handle raw input and output like on the device console? If not, do I need to read raw position events off some device or somerhing like that?

wook_sf 2012-08-31 21:10

Re: How to build a harmattan pre-init runnable component?
 
Quote:

Originally Posted by juiceme (Post 1258764)
Aarrgh, now I suddenly realised the unpleasant truth...
The darn box is not yet running X at preinit stage, right?

So, propably qt is out of scope here, then.
Does anybody have any good suggestions on how to handle it?
Are there any libraries that handle raw input and output like on the device console? If not, do I need to read raw position events off some device or somerhing like that?

afaik you can try to load some of drivers and cat events in /dev/input/
maybe?
or you can look evkey.c source: https://gitorious.org/android-n900/m.../evkey/evkey.c and do it like in there ;)

Hurrian 2012-08-31 21:54

Re: How to build a harmattan pre-init runnable component?
 
I'm guessing you'd be entering numbers using the volume and power buttons. Up to increment until it rolls around to 0, down to move cursor, power to enter.

Take a look at sillyboot for a pre-init component.

juiceme 2012-08-31 22:24

Re: How to build a harmattan pre-init runnable component?
 
Using evkey and just three buttons.... Well even that came into my mind but it is REALLY cumbersome to do it that way, I rather try to make it a decent UI even as it will be lots of more work.
Think about it for a moment, if you have a passphrase of maybe 30 letters and numbers it is next to impossible to enter that without making mistakes... No, keyboard is the way to go!

How I thought about implementing it now;

Yes, I need to get touch input, a steam of coordinates for the keypresses, For that there sure needs to be a driver, and in preinit I can modprobe it up and mknod the needed device.

For "keyboard" just an image suffices. There is no need really for visual confirmation of keypresses and that actually would be a bad thing, as it is needed for passphrase input. The image of the keyboard is just png file, shown up like in sillyboot.

For keypress confrmation I would like tactile feedback, so there needs also to be a device that can be written to to create the keypress vibrations.

wook_sf 2012-08-31 23:01

Re: How to build a harmattan pre-init runnable component?
 
it all can be done :D
you just need some time and good ideas ;)

juiceme 2012-09-02 14:30

Re: How to build a harmattan pre-init runnable component?
 
OK, so I did some tinkering and now I am able to read off coordinates from the touch screen. It turned out to be fairly easy after I found out the correct device to use, each touch will generate a burst of events, out of which I am filtering out all except absolute X and Y coordinate events. The following snippet shows how I am doing it.

Code:

  struct input_event ievent;
  int fd, xaxis, yaxis, flag=0, ret;

  if ((fdev = open("/dev/input/event3",  O_RDONLY)) < 0) {
    perror("cannot open input device");
    return -1;
  }

  while(1) {
    if((ret = read(fdev ,&ev ,sizeof(ievent))) < sizeof(ievent)) {
      printf("\nreceived only %d bytes on read", ret);
      return -1;
    }
    if(ievent.type == EV_ABS && ievent.code == ABS_X) {
      xaxis = ievent.value;
    }
    if(ievent.type == EV_ABS && ievent.code == ABS_Y) {
      yaxis = ievent.value;
      flag = 1;
    }
    if(flag) {
      flag = 0;
      printf("\ntouch = %d, %d", xaxis, yaxis);
    }
  }

Now, does anybody remember off the top of head how can I easily generate a short vibration effect for tactile feedback? I would assume it can be done by writing some structure to an output device, but what device and what kind of data?

juiceme 2012-09-02 22:19

Re: How to build a harmattan pre-init runnable component?
 
Okay, tick to another box, tactile feedback covered :)

Checking syslog I found that the vibra device is created as "/dev/input/event6" and reading the device while trying out virtual keyboard indeed threw up some codes. Writing the events back to device produce small vibration. Nice!

Code:

  int fdev, ret;
  struct input_event ievent;

  if ((fdev = open("/dev/input/event6",  O_RDWR)) < 0) {
    perror("cannot open output device");
    return -1;
  }

  ievent.type = EV_FF;
  ievent.code = 30;
  ievent.value = 1;
  if((ret = write(fdev, &ievent ,sizeof(ievent))) < sizeof(ievent)) {
    printf("\nsent only %d bytes on write");
    return -1;
  }

Now, originally I thought of loading up .png of a keyboard image as a visual guide to the typing using first "/usr/bin/show_png" to show the image, and then launching my "silly_kbd" utility to capture touch input.
However, I need to have shift/caps-lock functionality, so what I need to do is to change bitmaps on the screen while running my utility.

There are propably at least 3 ways of doing this, which are of varying complexity...
  • If I can get source code of show_png I could stitch that in my utility, easiest but I am not sure if it is non-free Nokia code?
  • Can I launch external program via "system()" call or something so I can call the utility from inside my own utility... This is doable but not really optimal
  • I could exit from my utility with an EC that the calling shell script knows that it needs to change the background image and relaunch the kbd utility... not really nice because I would need to handle the already inputted characters somehow...

Any thoughts on this?

coderus 2012-09-03 04:16

Re: How to build a harmattan pre-init runnable component?
 
4. you can turn your code into evtap and vibra command-line tools. it will be very handy for peoples. and write main code in another app, then just use evkey evtap and vibra tools (and show_png of corse) then need. also (maybe?) some tool for writing text in portait orientation? (landscape text with T2S is good, but i prefer portait)

juiceme 2012-09-03 08:40

Re: How to build a harmattan pre-init runnable component?
 
Quote:

Originally Posted by coderus (Post 1260010)
4. you can turn your code into evtap and vibra command-line tools. it will be very handy for peoples. and write main code in another app, then just use evkey evtap and vibra tools (and show_png of corse) then need. also (maybe?) some tool for writing text in portait orientation? (landscape text with T2S is good, but i prefer portait)

Well, actually I already thought about making a simple touch/tap interface change to sillyboot :)

See, when my son borrowed my N9 to play Angry Birds Space on nitdroid he instinctively tried to tap on the android icon in the booting phase instead of using the volume keys to change the default boot OS.

Hence I tried it, and it is quite simple to read a touch on either upper or lower part of the screen to select the desired image...


All times are GMT. The time now is 12:11.

vBulletin® Version 3.8.8