I am currently working on embedded linux framebuffers. I know how to display the available resolutions of my system by typing:
cat /sys/class/graphics/fb0/modes
This gives me a list of resolutions, for instance:
U:720x576p-50
D:1920x1080p-50
D:1280x720p-50
D:1920x1080i-60
D:1920x1080i-50
U:1440x900p-60
S:1280x1024p-60
V:1024x768p-60
V:800x600p-60
V:640x480p-60
D:1280x720p-60
D:1920x1080p-60
I would like to know what does the first character of each lines mean (S, U, V or D).
Is there a standard/documentation listing all the possible characters?
From the linux kernel source function mode_string()
char m = 'U';
if (mode->flag & FB_MODE_IS_DETAILED)
m = 'D';
if (mode->flag & FB_MODE_IS_VESA)
m = 'V';
if (mode->flag & FB_MODE_IS_STANDARD)
m = 'S';
so it's U unknown, D detailed, V vesa, S standard.
Related
I have an application that uses a database with data stored in big-endian order. To access this data portably across hardware platforms, I use 4 macros defined in a config.h module:
word(p) - gets a big-endian 16 bit value at pointer p as a native 16-bit value.
putword(p, w) - stores a native 16-bit variable (w) to pointer p as 16-bit big-endian.
dword(p) and putdword(p, d) do the same for 32-bit values
This all works fine, but the macros on a little-endian machine use the brute-force 'shift and mask' approach.
Anyway, it looks like there are builtin_bswap16 and builtin_bswap32 functions on linux that may do this more efficiently (as inline assembler code?). So what's the right way to code my word/putword macros so that they use these builtin functions on an X86_64 linux machine? Would coding my macros as htons/l function calls do the same thing as efficiently - and is it necessary to enable compiler optimiation to get any of these solutions to work? I'd rather not optimize if it renders gdb useless.
Hmmm. I wrote a trivial test program using no special include files and simply calling the __builtin_swap... functions directly (see the 'fast...' macros below). It all just works. When I disassemble the code in gdb, I see that the fast... macros do in 4-5 assembler instructions what takes up to 27 instructions for the worst case 'dword' macro. Pretty neat improvement for almost no effort.
typedef unsigned char uchar;
typedef unsigned short ushort;
typedef unsigned int uint;
#define word(a) (ushort) ( (*((uchar *)(a)) << 8) | \
(*((uchar *)(a) + 1)) )
#define putword(a,w) *((char *)(a)) = (char) (((ushort)((w) >> 8)) & 0x00ff), \
*((char *)(a)+1) = (char) (((ushort)((w) >> 0)) & 0x00ff)
#define dword(a) (uint) ( ((uint)(word(a)) << 16) | \
((uint)(word(((uchar *)(a) + 2)))) )
#define putdword(a,d) *((char *)(a)) = (char) (((uint)((d) >> 24)) & 0x00ff), \
*((char *)(a)+1) = (char) (((uint)((d) >> 16)) & 0x00ff), \
*((char *)(a)+2) = (char) (((uint)((d) >> 8)) & 0x00ff), \
*((char *)(a)+3) = (char) (((uint)((d) >> 0)) & 0x00ff)
#define fastword(a) (ushort) __builtin_bswap16(* ((ushort *) a));
#define fastputword(a, w) *((ushort *) a) = __builtin_bswap16((ushort)w);
#define fastdword(a) (uint) __builtin_bswap32(* ((uint *) a));
#define fastputdword(a, d) *((uint *) a) = __builtin_bswap32((uint)d);
int main()
{
unsigned short s1, s2, s3;
unsigned int i1, i2, i3;
s1 = 0x1234;
putword(&s2, s1);
s3 = word(&s2);
i1 = 0x12345678;
putdword(&i2, i1);
i3 = dword(&i2);
printf("s1=%x, s2=%x, s3=%x, i1=%x, i2=%x, i3=%x\n", s1, s2, s3, i1, i2, i3);
s1 = 0x1234;
fastputword(&s2, s1);
s3 = fastword(&s2);
i1 = 0x12345678;
fastputdword(&i2, i1);
i3 = fastdword(&i2);
printf("s1=%x, s2=%x, s3=%x, i1=%x, i2=%x, i3=%x\n", s1, s2, s3, i1, i2, i3);
}
I would just use htons, htonl and friends. They're a lot more portable, and it's very likely that the authors of any given libc will have implemented them as inline functions or macros that invoke __builtin intrinsics or inline asm or whatever, resulting in what should be a nearly-optimal implementation for that specific machine. See what is generated in godbolt's setup, which I think is some flavor of Linux/glibc.
You do need to compile with optimizations for them to be inlined, otherwise it generates an ordinary function call. But even -Og gets them inlined and should not mess up your debugging as much. Anyway, if you're compiling without optimizations altogether, your entire program will be so inefficient that the extra couple instructions to call htons must surely be the least of your worries.
I'm working recursive file search and got it to work with simple permissions, but I can't determinate how to get the owner (owner id) or the group (group id) of an folder or file. I've discovered how to get the current permissions of an file or folder. I get an uint_32 so about 9 bits of this are used to save the permission. But where and how are the timestamp is saved? and the owner? On my research I've read that the linux kernel allowing more than 4 billion users on an system. Obviously this isn't in the uint_32 that I'm getting.
I'm working in rust and would not fear to write a C module.
But now here is my main.rs:
use std::fs::*;
use std::os::unix::fs::MetadataExt;
use std::os::unix::fs::PermissionsExt;
use std::mem::transmute;
fn main(){
let meta = metadata("./test.txt");
if meta.is_ok(){
let m:u32 = meta.unwrap().permissions().mode();
//let bytes: [u8; 4] = unsafe { transmute(m.to_be()) };//etv. used later
print!("{}",if (m & (0x1<<9)) >= 1 {"d"}else{"-"});
print!("{}",if (m & (0x1<<8)) >= 1 {"r"}else{"-"});
print!("{}",if (m & (0x1<<7)) >= 1 {"w"}else{"-"});
print!("{}",if (m & (0x1<<6)) >= 1 {"x"}else{"-"});
print!("{}",if (m & (0x1<<5)) >= 1 {"r"}else{"-"});
print!("{}",if (m & (0x1<<4)) >= 1 {"w"}else{"-"});
print!("{}",if (m & (0x1<<3)) >= 1 {"x"}else{"-"});
print!("{}",if (m & (0x1<<2)) >= 1 {"r"}else{"-"});
print!("{}",if (m & (0x1<<1)) >= 1 {"w"}else{"-"});
println!("{}",if (m & 0x1) >= 1 {"x"}else{"-"});
println!("{:b}",m);
}
}
Do not hesitate to modify my code if you think so.
I'm doing this for fun and to learn more about the code underneath the horizon.
std::os::linux::fs::MetadataExt (or os::unix) provides relevant platform-specific functions. Reference. Looks like you need meta.std_uid(), meta.st_gid(), etc. By the way, it is much better to write your code like this:
if let Ok(meta) = metadata("./test.txt") {
println!("{}", meta.st_gid());
// ...
}
I'm working in rust and would not fear to write a C module
Rust has excellent FFI for such cases. For example, you can add libc crate with libc bindings and just call libc::stat function with familiar API.
Owner is meta.unwrap().uid() and group is meta.unwrap().gid(). They are u32 each, which is what Linux uses.
To get the actual names, use libc::getpwuid_r and libc::getgrgid_r. See also getpwuid(3) and getgrgid(3).
I trying to use SRP algorithm but I have some questions:
Is that a good choice to use for registration and authorization SRP algorithm with SSL/TLS? And for all other transmission using just SSL/TLS?
I will use C# Sockets for implementation.
How to generate g, k, N? Is it safe to use these like app constants?
Is that SRP algorithm right?
//M-modulus, g-generator, k-multiplier, I-username, p-password, s-salt, v-pass verifier
Registration:
Client: s = randomString(); x = Hash(s, p); v = g^x %N;
sendToServer(I, s, v);
Server: save(I, s, v);
Authorization:
Client: a = random(); A = g^a %N;
sendToServer(I, A);
Server: if(A != 0) { b=random(); B = k*v + g^b %N;}
sendToClient(B, s);
u = Hash(A, B);
if(u == 0) abortConnection();
Client: if(B == 0) abortConnection();
u = Hash(A, B);
if(u == 0) abortConnection();
x = Hash(s, p);
S = ((B - k*(g^x %N)) ^ (a + u*x)) %N;
K = Hash(S);
Mc = Hash( Hash(N) XOR Hash(g), Hash(I), s, A, B, K);
sendToServer(M);
Server: S = ((A*(v^u %N)) ^ B) %N; K = Hash(S);
Ms = Hash( Hash(N) XOR Hash(g), Hash(I), s, A, B, K);
if(Mc == Ms) {Rs = Hash(A, M, K); sendToClient(Rs);}
Client: Rc = Hash(A, M, K);
if(Rc == Rs) ALL_OK();
I would be very careful when implementing any security protocol on your own. It is very hard to get it right and most often by implementing complex secure protocol you actually compromise the security of the system if you don't get it right (e.g. wrong memory management, vulnerabilities to timing attacks, etc).
The general advise is to use audited, trusted (open-source) and maintained library to do crypto stuff. These libraries usually offer better performance as well, as they use specialized HW cryptography instructions (e.g. AES is supported very well in modern hardware, making it fast and not vulnerable to timing attacks).
So in the light of my answer, have a look at the library http://bouncycastle.org/ which should provide implementation of the SRP protocol.
Moreover, you should really consider the use case. Are you developing super secure mail server for millions of users, or do you just want to secure your home server with holiday photos? In the first case it is probably worth having very robust and secure system with state-of-art security algorithms. In the latter case, it isn't - good password and SSL will do :-).
OpenSSL has TLS-SRP.
For the values you are looking for, read RFC 5054.
N, g, and k do not need to be secret.
Poorly chosen N and g can compromise the security of the
cryptographic calculations, so you should either know what you're
doing, or pick the values recommended in the RFC.
k, is calculated from N and g, so once you pick those, you can get k.
If you are interested in implementing the details of SRP, Google has code available in C - Google csrp code.
I found a problem with floating point arithmetic in OpenCL. This is my kernel:
__kernel void MyKernel(__global const float4* _pInput, __global float4* _pOutput)
{
int IndexOfRow = get_global_id(0);
int NumberOfRows = get_global_size(0);
int IndexOfColumn = get_global_id(1);
int NumberOfColumns = get_global_size(1);
...
_pOutput[0] = 1.9f * 100.0f; // constant float return value
}
After the kernel execution and download of the output buffer the result is always 100 on different clients using an ssh connection. If I execute the program locally the result is 190. It seems that the digits after the decimal point are cut off.
The operating system is a Open Suse Linux with AMD OpenCL 1.2.
What's the problem?
I just found the solution. It depends on your ENV setting for LANG. It has to be en_US.UTF-8. You can check it with env|grep LANG.
That’s probably a JIT compiler bug. In Germany floating points are written with an „,“ instead of „.“.
I'm trying to communicate with differential drive mobile robot via matlab functions and .mex files. I can succesfully move the robot with command:
ref = serial('COM1');
set(ref,'BaudRate', 9600);
fopen(ref);
fprintf(ref,'C,1000,1000');
out = fscanf(ref)
fclose(ref)
delete(ref)
However, the function that I made which includes fprintf does not work:
function r = Move(ref,left,right)
fprintf(ref,'C,left,right');
out = fscanf(ref)
I'am aware that the problem is different string used in command fprintf (i.e. 'C,1000,1000' is not equal to 'C,left,right'), but I can't resolve this problem. Sorry if this is too trivial.
The ANSWER is (see comments below):
function r = Move(ref,left,right)
fprintf(ref,sprintf('C,%d,%d', left, right));
out = fscanf(ref);
You can try the following:
function r = Move(ref,left,right)
fprintf(ref,'C,%d,%d', left, right);
out = fscanf(ref)