Posts

Linux Bluetooth Pairing Device Using BlueZ5.X C Way

The traditional way to connect a device using bluetoothctl tool provided by BlueZ is as follows: Run the bluetoothctl tool from command line $ bluetoothctl [NEW] Controller 00:19:0E:0C:BE:40 tango-charlie [default] Turn ON Pairing agent: [bluetooth]# agent on Agent registered Start Scanning: [bluetooth]# scan on Discovery started [CHG] Controller 00:19:0E:0C:BE:40 Discovering: yes [NEW] Device 00:23:3A:AF:B1:20 00-23-3A-AF-B1-20 [CHG] Device D4:CA:6E:71:F2:A9 RSSI: -57 [NEW] Device A0:10:81:EE:D7:59 Galaxy S8 [CHG] Device A0:10:81:EE:D7:59 RSSI: -57 Stop Scanning: [bluetooth]# scan off [CHG] Device A0:10:81:EE:D7:59 RSSI is nil [CHG] Device 5C:51:4F:E0:EF:4C RSSI is nil [CHG] Controller 00:19:0E:0C:BE:40 Discovering: no Discovery stopped Pair To Bluetooth Device: [bluetooth]# pair A0:10:81:EE:D7:59 Attempting to pair with A0:10:81:EE:D7:59 [CHG] Device A0:10:81:EE:D7:59 Connected: yes Request confirmation [agent] Confirm passkey 110310 (yes/no): yes...

Linux mmap Based File Write

Breif on mmap: mmap() creates a new mapping in the virtual address space of the calling process. The starting address for the new mapping is specified in addr.  The length argument specifies the length ofthe mapping. You can find more info about mmap [1] There are lots of examples on web which do a entire file copy and its quite easy. One of my colleague wanted a faster file writes, he tried fwrite/write but it was too slow for him and I suggested to use mmaping the file and writing the contents to the file. Unfortunately google didn’t help him out, so just pasting the code so that someone else might get benefit from it. OK here goes the code: #include <stdio.h> #include <fcntl.h> #include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <sys/mman.h> #include <errno.h> struct buffer { #define MAX_BUFFER_SIZE 1000  char ptr[MAX_BUFFER_SIZE]; /* array */  int size; /* size of data in buffer */ }; ...

Checkpatch From Linux

Brief: checkpatch.pl is pearl script for detecting coding style errors in Linux source. Since Linux kernel is a huge source with approximately 3431 directories, 48619 files so you can imagine the amount of code in it. So to get the coding style correct (uniform) across the complete source of Linux chekpatch.pl script is used. Usage: A> With a valid patch (by valid patch i mean it is created git-format patch command) $ ./scripts/checkpatch.pl  < path to patch file> For Example: $ ./scripts/checkpatch.pl  *.patch Would run the script for all the patches in current directory. B> With file (By the name you might feel it only tests patches no you can also run this on files) $ ./scripts/checkpatch.pl --terse --file  <path to file> Options: --terse:  Specifies to report warining/error per line --file/ -f: Specifies regular source file. For Example: $ ./scripts/checkpatch.pl --terse --file  arch/arm/common/bL_switcher.c arch/arm...