aboutsummaryrefslogtreecommitdiffstats
path: root/package/libs/libnl-tiny/src/include/linux/genetlink.h
blob: b834ef6d59fa459ca793a004c311fe363e5a68fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef __LINUX_GENERIC_NETLINK_H
#define __LINUX_GENERIC_NETLINK_H

#include <linux/types.h>
#include <linux/netlink.h>

#define GENL_NAMSIZ	16	/* length of family name */

#define GENL_MIN_ID	NLMSG_MIN_TYPE
#define GENL_MAX_ID	1023

struct genlmsghdr {
	__u8	cmd;
	__u8	version;
	__u16	reserved;
};

#define GENL_HDRLEN	NLMSG_ALIGN(sizeof(struct genlmsghdr))

#define GENL_ADMIN_PERM		0x01
#define GENL_CMD_CAP_DO		0x02
#define GENL_CMD_CAP_DUMP	0x04
#define GENL_CMD_CAP_HASPOL	0x08

/*
 * List of reserved static generic netlink identifiers:
 */
#define GENL_ID_GENERATE	0
#define GENL_ID_CTRL		NLMSG_MIN_TYPE

/**************************************************************************
 * Controller
 **************************************************************************/

enum {
	CTRL_CMD_UNSPEC,
	CTRL_CMD_NEWFAMILY,
	CTRL_CMD_DELFAMILY,
	CTRL_CMD_GETFAMILY,
	CTRL_CMD_NEWOPS,
	CTRL_CMD_DELOPS,
	CTRL_CMD_GETOPS,
	CTRL_CMD_NEWMCAST_GRP,
	CTRL_CMD_DELMCAST_GRP,
	CTRL_CMD_GETMCAST_GRP, /* unused */
	__CTRL_CMD_MAX,
};

#define CTRL_CMD_MAX (__CTRL_CMD_MAX - 1)

enum {
	CTRL_ATTR_UNSPEC,
	CTRL_ATTR_FAMILY_ID,
	CTRL_ATTR_FAMILY_NAME,
	CTRL_ATTR_VERSION,
	CTRL_ATTR_HDRSIZE,
	CTRL_ATTR_MAXATTR,
	CTRL_ATTR_OPS,
	CTRL_ATTR_MCAST_GROUPS,
	__CTRL_ATTR_MAX,
};

#define CTRL_ATTR_MAX (__CTRL_ATTR_MAX - 1)

enum {
	CTRL_ATTR_OP_UNSPEC,
	CTRL_ATTR_OP_ID,
	CTRL_ATTR_OP_FLAGS,
	__CTRL_ATTR_OP_MAX,
};

#define CTRL_ATTR_OP_MAX (__CTRL_ATTR_OP_MAX - 1)

enum {
	CTRL_ATTR_MCAST_GRP_UNSPEC,
	CTRL_ATTR_MCAST_GRP_NAME,
	CTRL_ATTR_MCAST_GRP_ID,
	__CTRL_ATTR_MCAST_GRP_MAX,
};

#define CTRL_ATTR_MCAST_GRP_MAX (__CTRL_ATTR_MCAST_GRP_MAX - 1)

#endif	/* __LINUX_GENERIC_NETLINK_H */
3' href='#n393'>393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
/******************************************************************************
 *	fbtest - fbtest.c
 *	test program for the tuxbox-framebuffer device
 *	tests all GTX/eNX supported modes
 *                                                                            
 *	(c) 2003 Carsten Juttner (carjay@gmx.net)
 *
 * 	This program is free software; you can redistribute it and/or modify
 * 	it under the terms of the GNU General Public License as published by
 * 	The Free Software Foundation; either version 2 of the License, or
 * 	(at your option) any later version.
 *
 * 	This program is distributed in the hope that it will be useful,
 * 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 * 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * 	GNU General Public License for more details.
 *
 * 	You should have received a copy of the GNU General Public License
 * 	along with this program; if not, write to the Free Software
 * 	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *  									      
 ******************************************************************************
 * $Id: fbtest.c,v 1.5 2005/01/14 23:14:41 carjay Exp $
 ******************************************************************************/

// TODO: - should restore the colour map and mode to what it was before
//	 - is colour map handled correctly?

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <fcntl.h>

#include <linux/fb.h>

#include <error.h>

#define FBDEV "/dev/fb0"

struct vidsize{
	int width;
	int height;
};
static
const struct vidsize vidsizetable[]={	// all supported sizes
	{720,576},{720,480},{720,288},{720,240},
	{640,576},{640,480},{640,288},{640,240},
	{360,576},{360,480},{360,288},{360,240},
	{320,576},{320,480},{320,288},{320,240}
};
#define VIDSIZENUM (sizeof(vidsizetable)/sizeof(struct vidsize))

enum pixenum{	// keep in sync with pixname !
	CLUT4=0,
	CLUT8,
	RGB565,
	ARGB1555,
	ARGB
};
const char *pixname[] = {
	"CLUT4",
	"CLUT8",
	"RGB565",
	"ARGB1555",
	"ARGB"
};

struct pixelformat{
	char *name;
	struct fb_bitfield red;
	struct fb_bitfield green;
	struct fb_bitfield blue;
	struct fb_bitfield transp;
	char bpp;
	char pixenum;
};

static		// so far these are all modes supported by the eNX (only partially by GTX)
const struct pixelformat pixelformattable[] = {
	{ .name = "CLUT4 ARGB8888", 	// CLUT4 (ARGB8888)
		.bpp = 4, .pixenum = CLUT4,
		.red = 	 { .offset = 0, .length=8, .msb_right =0 },
		.green = { .offset = 0, .length=8, .msb_right =0 },
		.blue =  { .offset = 0, .length=8, .msb_right =0 },
		.transp=  { .offset = 0, .length=8, .msb_right =0 }
	},
	{ .name = "CLUT4 ARGB1555", 	// CLUT4 (ARGB1555)
		.bpp = 4, .pixenum = CLUT4,
		.red = 	 { .offset = 0, .length=5, .msb_right =0 },
		.green = { .offset = 0, .length=5, .msb_right =0 },
		.blue =  { .offset = 0, .length=5, .msb_right =0 },
		.transp=  { .offset = 0, .length=1, .msb_right =0 }
	},
	{ .name = "CLUT8 ARGB8888",	// CLUT8 (ARGB8888)
		.bpp = 8, .pixenum = CLUT8,
		.red = 	 { .offset = 0, .length=8, .msb_right =0 },
		.green = { .offset = 0, .length=8, .msb_right =0 },
		.blue =  { .offset = 0, .length=8, .msb_right =0 },
		.transp=  { .offset = 0, .length=8, .msb_right =0 }
	},
	{ .name = "CLUT8 ARGB1555",	// CLUT8 (ARGB1555)
		.bpp = 8, .pixenum = CLUT8,
		.red = 	 { .offset = 0, .length=5, .msb_right =0 },
		.green = { .offset = 0, .length=5, .msb_right =0 },
		.blue =  { .offset = 0, .length=5, .msb_right =0 },
		.transp=  { .offset = 0, .length=1, .msb_right =0 }
	},
	{ .name = "ARGB1555", 	// ARGB1555
		.bpp = 16, .pixenum = ARGB1555,
		.red = 	 { .offset = 10, .length=5, .msb_right =0 },
		.green = { .offset = 5,  .length=5, .msb_right =0 },
		.blue =  { .offset = 0,  .length=5, .msb_right =0 },
		.transp=  { .offset = 15, .length=1, .msb_right =0 }
	},
	{ .name = "RGB565", 		// RGB565
		.bpp = 16, .pixenum = RGB565,
		.red = 	 { .offset = 11, .length=5, .msb_right =0 },
		.green = { .offset = 5,  .length=6, .msb_right =0 },
		.blue =  { .offset = 0,  .length=5, .msb_right =0 },
		.transp=  { .offset = 0,  .length=0, .msb_right =0 }
	},
	{ .name = "ARGB",	// 32 f*cking bits, the real McCoy :)
		.bpp = 32, .pixenum = ARGB,
		.red = 	 { .offset = 16, .length=8, .msb_right =0 },
		.green = { .offset = 8,  .length=8, .msb_right =0 },
		.blue =  { .offset = 0,  .length=8, .msb_right =0 },
		.transp=  { .offset = 24, .length=8, .msb_right =0 }
	}
};
#define PIXELFORMATNUM (sizeof(pixelformattable)/sizeof(struct pixelformat))

struct colour {
	__u16 r;
	__u16 g;
	__u16 b;
	__u16 a;
};
static
struct colour colourtable[] = {
	{.r =0xffff, .g = 0xffff, .b=0xffff, .a=0xffff},	// fully transparent white
	{.r =0xffff, .g = 0x0000, .b=0x0000, .a=0x0000},	// red
	{.r =0x0000, .g = 0xffff, .b=0x0000, .a=0x0000},	// green
	{.r =0x0000, .g = 0x0000, .b=0xffff, .a=0x0000},	// blue
	{.r =0x0000, .g = 0x0000, .b=0x0000, .a=0x0000}		// black
};
#define COLOURNUM (sizeof(colourtable)/sizeof(struct colour))

struct rect{
	int x;
	int y;
	int width;
	int height;
	const struct colour *col;
};
struct pixel{		// up to 32 bits of pixel information
	char byte[4];
};

void col2pixel (struct pixel *pix, const struct pixelformat *pixf, const struct colour *col){
	switch (pixf->pixenum){
		case RGB565:
			pix->byte[0]=(col->r&0xf8)|(col->g&0xfc)>>5;
			pix->byte[1]=(col->g&0xfc)<<3|(col->b&0xf8)>>3;
			break;
		case ARGB1555:
			pix->byte[0]=(col->a&0x80)|(col->r&0xf8)>>1|(col->g&0xf8)>>6;
			pix->byte[1]=(col->g&0xf8)<<2|(col->b&0xf8)>>3;
			break;
		case ARGB:
			pix->byte[0]=col->a;
			pix->byte[1]=col->r;
			pix->byte[2]=col->g;
			pix->byte[3]=col->b;
			break;
		default:
			printf ("unknown pixelformat\n");
			exit(1);
	}
}

int setmode(int fbd, const struct pixelformat *pixf,const struct vidsize *vids){
	struct fb_var_screeninfo var;
	int stat;
	stat = ioctl (fbd, FBIOGET_VSCREENINFO,&var);
	if (stat<0) return -2;
	
	var.xres= vids->width;
	var.xres_virtual = vids->width;
	var.yres= vids->height;
	var.yres_virtual = vids->height;
	
	var.bits_per_pixel = pixf->bpp;
	var.red = pixf->red;
	var.green = pixf->green;
	var.blue = pixf->blue;
	var.transp = pixf->transp;

	stat = ioctl (fbd, FBIOPUT_VSCREENINFO,&var);
	if (stat<0) return -1;
	return 0;
}

// unefficient implementation, do NOT use it for your next ego shooter, please :)
// for 4-Bit only rectangles with even width are supported
// CLUT-modes use value of red component as index
void drawrect(void *videoram, struct rect *r, const struct pixelformat *pixf, const struct vidsize *vids){
	int x,y,corwidth, bpp = 0, tocopy = 1;
	struct pixel pix;
	unsigned char *pmem = videoram;
	corwidth = r->width;	// actually only "corrected" for 4 Bit

	if (pixf->pixenum!=CLUT4&&pixf->pixenum!=CLUT8){
		switch (pixf->pixenum){
			case ARGB1555:
			case RGB565:
				bpp = 16;
				tocopy = 2;
				break;
			case ARGB:
				bpp = 32;
				tocopy = 4;
				break;
			default:
				printf ("drawrect: unknown pixelformat(%d) bpp:%d\n",pixf->pixenum,pixf->bpp);
				exit(1);
		}
		col2pixel(&pix,pixf,r->col);
	} else {
		switch (pixf->pixenum){	// CLUT = Colour LookUp Table (palette)
			case CLUT4:	// take red value as index in this case
				pix.byte[0]=(r->col->r)<<4|(r->col->r&0xf);	// slightly cryptic... "rect->colour->red"
				corwidth>>=1;	// we copy bytes
				bpp=4;
				tocopy=1;
				break;
			case CLUT8:
				pix.byte[0]=(r->col->r&0xff);
				bpp=8;
				tocopy=1;
				break;
		}
	}
	pmem=videoram+((((r->y*vids->width)+r->x)*bpp)>>3);
	for (y=0;y<r->height;y++){
		int offset = 0;
		for (x=0;x<corwidth;x++){
			memcpy (pmem+offset,pix.byte,tocopy);
			offset+=tocopy;
		}
		pmem +=((vids->width*bpp)>>3);	// skip one whole line, actually should be taken from "fix-info"
	}
}
			
// create quick little test image, 4 colours from table
void draw4field(void *videoram, const struct pixelformat *pixf, const struct vidsize *vids){
	struct rect r;
	struct colour c;
	int height, width;
	c.r = 1;	// only used for the indexed modes, r is taken as index
	height = vids->height;
	width = vids->width;

	r.height = height>>1;
	r.width = width>>1;
	r.x = 0;	r.y = 0;
	if (pixf->pixenum==CLUT4||pixf->pixenum==CLUT8) r.col = &c;
	else r.col = &colourtable[1];
	drawrect (videoram, &r, pixf, vids);

	r.x = width/2;	r.y = 0;
	if (pixf->pixenum==CLUT4||pixf->pixenum==CLUT8) c.r = 2;
	else r.col = &colourtable[2];
	drawrect (videoram, &r, pixf, vids);

	r.x = 0;	r.y = height/2;
	if (pixf->pixenum==CLUT4||pixf->pixenum==CLUT8) c.r = 3;
	else r.col = &colourtable[3];
	drawrect (videoram, &r, pixf, vids);

	r.x = width/2;	r.y = height/2;
	if (pixf->pixenum==CLUT4||pixf->pixenum==CLUT8) c.r = 0;
	else r.col = &colourtable[0];
	drawrect (videoram, &r, pixf, vids);
}

void usage(char *name){
 	printf ("Usage: %s [options]\n"
		"Options: -f<pixelformat>\n"
		"            where format is one of:\n"
		"              CLUT4,CLUT8,ARGB1555,RGB565,ARGB\n"
		"         -s<width>x<heigth>\n"
		"            where width is either 720,640,360,320\n"
		"                  and height is either 288,240,480,576\n"
		"         -n\n"
		"            disables clearing the framebuffer after drawing\n"
		"            the testimage. This can be useful to keep the last\n"
		"            drawn image onscreen.\n"
		"\nExample: %s -fRGB322\n",name,name);
	exit(0);
}

int main (int argc,char **argv){
	struct fb_fix_screeninfo fix;
	struct fb_var_screeninfo var;
	struct fb_cmap cmap;
	struct rect r;
	int fbd;
	unsigned char *pfb;
	int stat;
	int optchar,fmode=-1,smode=-1,clear=1;
	int i_cmap,i_size,i_pix;
	extern char *optarg;
	
	if (argc!=0&&argc>4) usage(argv[0]);
	while ( (optchar = getopt (argc,argv,"f:s:n"))!= -1){
		int i,height,width;
		switch (optchar){
			case 'f':
				for (i=0;i<(sizeof(pixname)/sizeof(char*));i++){
					if (!strncmp (optarg,pixname[i],strlen(pixname[i]))){
						fmode=i;
						printf ("displaying only %s-modes\n",pixname[i]);
						break;
					}
				}
				if (fmode==-1){
					printf ("unknown pixelformat\n");
					exit(0);
				}
				break;
			case 's':
				if (sscanf (optarg,"%dx%d",&width,&height)!=2){
					printf ("parsing size failed\n");
					exit(0);
				} else {
					printf ("requested size %dx%d\n",width,height);
					for (i=0;i<VIDSIZENUM;i++){
						if (vidsizetable[i].width == width &&
							vidsizetable[i].height == height){
							smode = i;
							break;
						}
					}
					if (smode==-1){
						printf ("this size is not supported\n");
						exit(0);
					}
				}
				break;
			case 'n':
				clear = 0;
				printf ("clearing framebuffer after drawing is disabled\n");
				break;
			case '?':
				usage (argv[0]);
		}
	}
	
	fbd = open (FBDEV, O_RDWR);
	if (fbd<0){
		perror ("Error opening framebuffer device");
		return 1;
	}
	stat = ioctl (fbd, FBIOGET_FSCREENINFO,&fix);
	if (stat<0){
		perror ("Error getting fix screeninfo");
		return 1;
	}
	stat = ioctl (fbd, FBIOGET_VSCREENINFO,&var);
	if (stat<0){
		perror ("Error getting var screeninfo");
		return 1;
	}
	stat = ioctl (fbd, FBIOPUT_VSCREENINFO,&var);
	if (stat<0){
		perror ("Error setting mode");
		return 1;
	}
	pfb = mmap (0, fix.smem_len, PROT_READ|PROT_WRITE, MAP_SHARED, fbd, 0);
	if (pfb == MAP_FAILED){
		perror ("Error mmap'ing framebuffer device");
		return 1;
	}

	// iterate over all modes
	for (i_pix=0;i_pix<PIXELFORMATNUM;i_pix++){
		if (fmode!=-1 && pixelformattable[i_pix].pixenum != fmode) continue;
		printf ("testing: %s",pixelformattable[i_pix].name);
		printf (" for sizes: \n");
		for (i_size=0;i_size<VIDSIZENUM;i_size++){
			if (smode!=-1 && i_size!=smode) continue;
			printf ("%dx%d ",vidsizetable[i_size].width,vidsizetable[i_size].height);
			fflush(stdout);
			if ((i_size%4)==3) printf ("\n");
			
			// try to set mode
			stat = setmode(fbd,&pixelformattable[i_pix],&vidsizetable[i_size]);
			if (stat==-2) perror ("fbtest: could not get fb_var-screeninfo from fb-device");
			else if (stat==-1){
				printf ("\nCould not set mode %s (%dx%d), possible reasons:\n"
					"- you have a GTX (soz m8)\n"
					"- your configuration does not have enough graphics RAM\n"
					"- you found a bug\n"
					"choose your poison accordingly...\n",
					pixelformattable[i_pix].name,vidsizetable[i_size].width,vidsizetable[i_size].height);
					continue;
			}
			// fill cmap;
			cmap.len = 1;
			if ((pixelformattable[i_pix].bpp==4)||
				((pixelformattable[i_pix].bpp==8)&&(pixelformattable[i_pix].red.length!=3))){
				for (i_cmap=0;i_cmap<COLOURNUM;i_cmap++){
					cmap.start=i_cmap;
					cmap.red=&colourtable[i_cmap].r;
					cmap.green=&colourtable[i_cmap].g;
					cmap.blue=&colourtable[i_cmap].b;
					cmap.transp=&colourtable[i_cmap].a;
					stat = ioctl (fbd, FBIOPUTCMAP, &cmap);
					if (stat<0) printf ("setting colourmap failed\n");
				}
			}
			// create the test image
			draw4field(pfb,&pixelformattable[i_pix],&vidsizetable[i_size]);
			usleep (500000);
			// clear screen
			if (clear){
				r.x=r.y=0;r.width = vidsizetable[i_size].width; r.height = vidsizetable[i_size].height;
				r.col = &colourtable[4];
				drawrect(pfb,&r,&pixelformattable[i_pix],&vidsizetable[i_size]);
			}
		}
		printf ("\n");
	}

	stat = munmap (pfb,fix.smem_len);
	if (stat<0){
		perror ("Error munmap'ing framebuffer device");
		return 1;
	}
	close (fbd);
	return 0;
}