static ssize_t spromdump_read_file(struct file *file, char __user *userbuf,
				 size_t count, loff_t *ppos)
{
	const size_t len = REALLY_BIG_BUFFER_SIZE;

	struct bcm43xx_private *bcm = file->private_data;
	char *buf = really_big_buffer;
	size_t pos = 0;
	ssize_t res;
	unsigned long flags;

	down(&big_buffer_sem);
	bcm43xx_lock_mmio(bcm, flags);
	if (!bcm->initialized) {
		fappend("Board not initialized.\n");
		goto out;
	}

	/* This is where the information is written to the "sprom_dump" file */
	fappend("boardflags: 0x%04x\n", bcm->sprom.boardflags);

out:
	bcm43xx_unlock_mmio(bcm, flags);
	res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
	up(&big_buffer_sem);
	return res;
}
static ssize_t tsf_read_file(struct file *file, char __user *userbuf,
			     size_t count, loff_t *ppos)
{
	const size_t len = REALLY_BIG_BUFFER_SIZE;

	struct bcm43xx_private *bcm = file->private_data;
	char *buf = really_big_buffer;
	size_t pos = 0;
	ssize_t res;
	unsigned long flags;
	u64 tsf;

	down(&big_buffer_sem);
	bcm43xx_lock_mmio(bcm, flags);
	if (!bcm->initialized) {
		fappend("Board not initialized.\n");
		goto out;
	}
	bcm43xx_tsf_read(bcm, &tsf);
	fappend("0x%08x%08x\n",
		(unsigned int)((tsf & 0xFFFFFFFF00000000ULL) >> 32),
		(unsigned int)(tsf & 0xFFFFFFFFULL));

out:
	bcm43xx_unlock_mmio(bcm, flags);
	res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
	up(&big_buffer_sem);
	return res;
}
static ssize_t txstat_read_file(struct b43legacy_wldev *dev, char *buf, size_t bufsize)
{
	struct b43legacy_txstatus_log *log = &dev->dfsentry->txstatlog;
	ssize_t count = 0;
	unsigned long flags;
	int i, idx;
	struct b43legacy_txstatus *stat;

	spin_lock_irqsave(&log->lock, flags);
	if (log->end < 0) {
		fappend("Nothing transmitted, yet\n");
		goto out_unlock;
	}
	fappend("b43legacy TX status reports:\n\n"
		"index | cookie | seq | phy_stat | frame_count | "
		"rts_count | supp_reason | pm_indicated | "
		"intermediate | for_ampdu | acked\n" "---\n");
	i = log->end + 1;
	idx = 0;
	while (1) {
		if (i == B43legacy_NR_LOGGED_TXSTATUS)
			i = 0;
		stat = &(log->log[i]);
		if (stat->cookie) {
			fappend("%03d | "
				"0x%04X | 0x%04X | 0x%02X | "
				"0x%X | 0x%X | "
				"%u | %u | "
				"%u | %u | %u\n",
				idx,
				stat->cookie, stat->seq, stat->phy_stat,
				stat->frame_count, stat->rts_count,
				stat->supp_reason, stat->pm_indicated,
				stat->intermediate, stat->for_ampdu,
				stat->acked);
			idx++;
		}
		if (i == log->end)
			break;
		i++;
	}
out_unlock:
	spin_unlock_irqrestore(&log->lock, flags);

	return count;
}
static ssize_t drvinfo_read_file(struct file *file, char __user *userbuf,
				 size_t count, loff_t *ppos)
{
	const size_t len = REALLY_BIG_BUFFER_SIZE;

	char *buf = really_big_buffer;
	size_t pos = 0;
	ssize_t res;

	down(&big_buffer_sem);

	/* This is where the information is written to the "driver" file */
	fappend(KBUILD_MODNAME " driver\n");
	fappend("Compiled at: %s %s\n", __DATE__, __TIME__);

	res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
	up(&big_buffer_sem);
	return res;
}
Esempio n. 5
0
long fappend_file(const char *path, const char *fname)
{
	FILE *f;
	int r = -1;

	if (f_exists(fname) && (f = fopen(path, "a")) != NULL) {
		r = fappend(f, fname);
		fclose(f);
	}
	return r;
}
/* wl->irq_lock is locked */
static ssize_t ucode_regs_read_file(struct b43legacy_wldev *dev, char *buf, size_t bufsize)
{
	ssize_t count = 0;
	int i;

	for (i = 0; i < 64; i++) {
		fappend("r%d = 0x%04x\n", i,
			b43legacy_shm_read16(dev, B43legacy_SHM_WIRELESS, i));
	}

	return count;
}
Esempio n. 7
0
void misc_errors() {
    // Relative Error to Consensus
    float FCnorm = G.n2();
    float REC = 0;
    for(int i=0; i<N; i++) REC += G.l2(node[i].C_rec);
    REC /= (N*FCnorm);

    // Pair-Wise Error
    float PWE = 0;
    for(int i=0; i<N; i++) for(int j=0; j<N; j++) PWE += node[i].C_rec.l2(node[j].C_rec);
    PWE /= N*N;

    fappend("data/stats/PWE.txt", fmt("%f\n", PWE));
}
Esempio n. 8
0
static void dlgsetlist(void) {

	LISTARRAY	flist;
	FLISTH		flh;
	FLINFO		fli;
	BOOL		append;
	FLIST		fl;
	ITEMEXPRM	prm;

	menudlg_itemreset(DID_FLIST);
	menudlg_settext(DID_FOLDER, file_getname(filesel.path));
	listarray_destroy(filesel.flist);
	flist = listarray_new(sizeof(_FLIST), 64);
	filesel.flist = flist;
	filesel.fbase = NULL;
	flh = file_list1st(filesel.path, &fli);
	if (flh != FLISTH_INVALID) {
		do {
			append = FALSE;
			if (fli.attr & 0x10) {
				append = TRUE;
			}
			else if (!(fli.attr & 0x08)) {
				append = checkext(fli.path, filesel.ext);
			}
			if (append) {
				if (fappend(flist, &fli) != SUCCESS) {
					break;
				}
			}
		} while(file_listnext(flh, &fli,filesel.path) == SUCCESS);
		file_listclose(flh);
	}
	prm.pos = 0;
	fl = filesel.fbase;
	while(fl) {
		menudlg_itemappend(DID_FLIST, NULL);
		prm.icon = (fl->isdir)?MICON_FOLDER:MICON_FILE;
		prm.str = fl->name;
		menudlg_itemsetex(DID_FLIST, &prm);
		fl = fl->next;
		prm.pos++;
	}
}
Esempio n. 9
0
void dump_degrees() {
    for(int i=0; i<N; i++) fappend("data/stats/degrees.txt", fmt("%u\n", node[i].nbNeighbors));
}
Esempio n. 10
0
int create_trx_header(char** filenames, char* output){
	int sizes[NUM_OFFSETS];
	int nzeros;
	struct stat filestat;
	struct trx_header header;
	int offset = TRX_HEADER_SIZE;
	header.magic = MAGIC;
	header.flags = 0;
	header.version = 1;
	for(int i = 0; i< NUM_OFFSETS; i++){
		if(stat(filenames[i],&filestat) != 0){
			perror(filenames[i]);
			return -1;
		}
		//align last offset to sector size (512)
		if (i == NUM_OFFSETS - 1){
			int nsectors = offset / 0x200;
			int nrest = offset % 0x200;
			if(nrest > 0){
				nrest = offset;
				offset = (nsectors + 1) * 0x200;
				nzeros = offset - nrest;
			}
		}
		header.offsets[i] = offset;
		offset += filestat.st_size;
	}
	header.file_length = offset;

	//Temporary
	if(write_trx_header(output, &header, 0) < 0){
		return -1;
	}

	char* padding = malloc(sizeof(char) * (strlen(output)+strlen(".zeros") + 1));
	strcpy(padding,output);
	strcat(padding,".zeros");

	if(write_zero_padding(padding,nzeros) < 0){
		return -1;
	}

	crc32_total = 0;

	uint32_t crc;
	off_t size;
	int fd;

	if((fd  = open(output, O_RDONLY)) < 0){
		perror("can't open temp TRX file");
		return -1;
	}
	printf("crc32 for %s\n", output);
	crc32(fd, &crc, &size);
	close(fd);

	for(int i = 0; i < NUM_OFFSETS; i++){
		if(i == NUM_OFFSETS -1){
			if((fd  = open(padding, O_RDONLY)) < 0){
				perror("can't open file");
				return -1;
			}
			crc32(fd, &crc, &size);
			close(fd);
		}

		if((fd  = open(filenames[i], O_RDONLY)) < 0){
			perror("can't open file");
			return -1;
		}

		printf("crc32 for %s\n", filenames[i]);
		crc32(fd, &crc, &size);
		close(fd);
	}

	header.crc32 = ~crc32_total;

	if(write_trx_header(output, &header, 1) < 0){
		return -1;
	}

	for(int i = 0; i < NUM_OFFSETS; i++){
		if(i == NUM_OFFSETS -1){
			if(fappend(padding, output) < 0){
				return -1;
			}
		}
		if(fappend(filenames[i], output) < 0){
			return -1;
		}
	}

	print_trx(output);
	return 0;
}
Esempio n. 11
0
void create_passwd(void)
{
	char s[512];
	char *p;
	char salt[32];
	FILE *f;
	mode_t m;
#ifdef TCONFIG_SAMBASRV	//!!TB
	char *smbd_user;
#endif

	strcpy(salt, "$1$");
	f_read("/dev/urandom", s, 6);
	base64_encode(s, salt + 3, 6);
	salt[3 + 8] = 0;
	p = salt;
	while (*p) {
		if (*p == '+') *p = '.';
		++p;
	}
	if (((p = nvram_get("http_passwd")) == NULL) || (*p == 0)) p = "admin";

#ifdef TCONFIG_SAMBASRV	//!!TB
	if (((smbd_user = nvram_get("smbd_user")) == NULL) || (*smbd_user == 0) || !strcmp(smbd_user, "root"))
		smbd_user = "******";
#endif

	m = umask(0777);
	if ((f = fopen("/etc/shadow", "w")) != NULL) {
		p = crypt(p, salt);
		fprintf(f, "root:%s:0:0:99999:7:0:0:\n"
				   "nobody:*:0:0:99999:7:0:0:\n", p);
#if TOMATO_SL
		// todo		zzz
		fprintf(f, "admin:*:0:0:99999:7:0:0:\n");
#endif
#ifdef TCONFIG_SAMBASRV	//!!TB
		fprintf(f, "%s:*:0:0:99999:7:0:0:\n", smbd_user);
#endif

		fappend(f, "/etc/shadow.custom");
		fclose(f);
	}
	umask(m);
	chmod("/etc/shadow", 0600);

#ifdef TCONFIG_SAMBASRV	//!!TB
	sprintf(s, 
		"root:x:0:0:root:/root:/bin/sh\n"
		"%s:x:100:100:nas:/dev/null:/dev/null\n"
		"nobody:x:65534:65534:nobody:/dev/null:/dev/null\n",
		smbd_user);
	f_write_string("/etc/passwd", s, 0, 0644);
#else	//!!TB
	f_write_string("/etc/passwd",
		"root:x:0:0:root:/root:/bin/sh\n"
#if TOMATO_SL
		// todo		zzz
		"admin:x:100:100:nas:/dev/null:/dev/null\n"
#endif
		"nobody:x:65534:65534:nobody:/dev/null:/dev/null\n",
		0, 0644);
#endif	//!!TB
	fappend_file("/etc/passwd", "/etc/passwd.custom");

	f_write_string("/etc/gshadow",
		"root:*:0:\n"
//#if TOMATO_SL
#ifdef TCONFIG_SAMBASRV	//!!TB
		"nas:*:100:\n"
#endif
		"nobody:*:65534:\n",
		0, 0600);
	fappend_file("/etc/gshadow", "/etc/gshadow.custom");

	f_write_string("/etc/group",
		"root:x:0:\n"
//#if TOMATO_SL
#ifdef TCONFIG_SAMBASRV	//!!TB
		"nas:x:100:\n"
#endif
		"nobody:x:65534:\n",
		0, 0644);
	fappend_file("/etc/group", "/etc/group.custom");
}
Esempio n. 12
0
static ssize_t devinfo_read_file(struct file *file, char __user *userbuf,
				 size_t count, loff_t *ppos)
{
	const size_t len = REALLY_BIG_BUFFER_SIZE;

	struct bcm43xx_private *bcm = file->private_data;
	char *buf = really_big_buffer;
	size_t pos = 0;
	ssize_t res;
	struct net_device *net_dev;
	struct pci_dev *pci_dev;
	unsigned long flags;
	u16 tmp16;
	int i;

	down(&big_buffer_sem);

	bcm43xx_lock_mmio(bcm, flags);
	if (!bcm->initialized) {
		fappend("Board not initialized.\n");
		goto out;
	}
	net_dev = bcm->net_dev;
	pci_dev = bcm->pci_dev;

	/* This is where the information is written to the "devinfo" file */
	fappend("*** %s devinfo ***\n", net_dev->name);
	fappend("vendor:           0x%04x   device:           0x%04x\n",
		pci_dev->vendor, pci_dev->device);
	fappend("subsystem_vendor: 0x%04x   subsystem_device: 0x%04x\n",
		pci_dev->subsystem_vendor, pci_dev->subsystem_device);
	fappend("IRQ: %d\n", bcm->irq);
	fappend("mmio_addr: 0x%p   mmio_len: %u\n", bcm->mmio_addr, bcm->mmio_len);
	fappend("chip_id: 0x%04x   chip_rev: 0x%02x\n", bcm->chip_id, bcm->chip_rev);
	if ((bcm->core_80211[0].rev >= 3) && (bcm43xx_read32(bcm, 0x0158) & (1 << 16)))
		fappend("Radio disabled by hardware!\n");
	if ((bcm->core_80211[0].rev < 3) && !(bcm43xx_read16(bcm, 0x049A) & (1 << 4)))
		fappend("Radio disabled by hardware!\n");
	fappend("board_vendor: 0x%04x   board_type: 0x%04x\n", bcm->board_vendor,
	        bcm->board_type);

	fappend("\nCores:\n");
#define fappend_core(name, info) fappend("core \"" name "\" %s, %s, id: 0x%04x, "	\
					 "rev: 0x%02x, index: 0x%02x\n",		\
					 (info).available				\
						? "available" : "nonavailable",		\
					 (info).enabled					\
						? "enabled" : "disabled",		\
					 (info).id, (info).rev, (info).index)
	fappend_core("CHIPCOMMON", bcm->core_chipcommon);
	fappend_core("PCI", bcm->core_pci);
	fappend_core("first 80211", bcm->core_80211[0]);
	fappend_core("second 80211", bcm->core_80211[1]);
#undef fappend_core
	tmp16 = bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_CONTROL);
	fappend("LEDs: ");
	for (i = 0; i < BCM43xx_NR_LEDS; i++)
		fappend("%d ", !!(tmp16 & (1 << i)));
	fappend("\n");

out:
	bcm43xx_unlock_mmio(bcm, flags);
	res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
	up(&big_buffer_sem);
	return res;
}
Esempio n. 13
0
static ssize_t txstat_read_file(struct file *file, char __user *userbuf,
				size_t count, loff_t *ppos)
{
	const size_t len = REALLY_BIG_BUFFER_SIZE;

	struct bcm43xx_private *bcm = file->private_data;
	char *buf = really_big_buffer;
	size_t pos = 0;
	ssize_t res;
	unsigned long flags;
	struct bcm43xx_dfsentry *e;
	struct bcm43xx_xmitstatus *status;
	int i, cnt, j = 0;

	down(&big_buffer_sem);
	bcm43xx_lock(bcm, flags);

	fappend("Last %d logged xmitstatus blobs (Latest first):\n\n",
		BCM43xx_NR_LOGGED_XMITSTATUS);
	e = bcm->dfsentry;
	if (e->xmitstatus_printing == 0) {
		/* At the beginning, make a copy of all data to avoid
		 * concurrency, as this function is called multiple
		 * times for big logs. Without copying, the data might
		 * change between reads. This would result in total trash.
		 */
		e->xmitstatus_printing = 1;
		e->saved_xmitstatus_ptr = e->xmitstatus_ptr;
		e->saved_xmitstatus_cnt = e->xmitstatus_cnt;
		memcpy(e->xmitstatus_print_buffer, e->xmitstatus_buffer,
		       BCM43xx_NR_LOGGED_XMITSTATUS * sizeof(*(e->xmitstatus_buffer)));
	}
	i = e->saved_xmitstatus_ptr - 1;
	if (i < 0)
		i = BCM43xx_NR_LOGGED_XMITSTATUS - 1;
	cnt = e->saved_xmitstatus_cnt;
	while (cnt) {
		status = e->xmitstatus_print_buffer + i;
		fappend("0x%02x:   cookie: 0x%04x,  flags: 0x%02x,  "
			"cnt1: 0x%02x,  cnt2: 0x%02x,  seq: 0x%04x,  "
			"unk: 0x%04x\n", j,
			status->cookie, status->flags,
			status->cnt1, status->cnt2, status->seq,
			status->unknown);
		j++;
		cnt--;
		i--;
		if (i < 0)
			i = BCM43xx_NR_LOGGED_XMITSTATUS - 1;
	}

	bcm43xx_unlock(bcm, flags);
	res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
	bcm43xx_lock(bcm, flags);
	if (*ppos == pos) {
		/* Done. Drop the copied data. */
		e->xmitstatus_printing = 0;
	}
	bcm43xx_unlock(bcm, flags);
	up(&big_buffer_sem);
	return res;
}