file
stringlengths 18
26
| data
stringlengths 3
1.04M
|
---|---|
the_stack_data/126372.c | #include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>
/*
#ifndef _POSIX_C_SOURCE 199309L
#define _POSIX_C_SOURCE 199309L
#endif */
#define DISC_ON 1
#define DISC_OFF 0
int __receivedSignalNo__g=DISC_ON;
static void SigHandler(int _sigNUm);
int main(int argc, char** argv)
{
pid_t n;
struct sigaction act;
struct sigaction oldact;
act.sa_handler =&SigHandler;
act.sa_flags=0;
sigaction(SIGUSR1,&act,&oldact);
/*****************************/
if(n<0)
{
puts("Fork Fails!");
return 1;
}
/*****************************/
else if(n>0)
{ /*Parent proc*/
puts("__Pong__");
kill(n,SIGUSR1);
while(1)
{
if(__receivedSignalNo__g == DISC_ON)
{
puts("__Pong__");
/*sendt child signal*/
kill(n,SIGUSR1);
__receivedSignalNo__g = DISC_OFF;
}
}
}
else
{
while(1)
{
if(__receivedSignalNo__g == DISC_ON)
{
puts("__Ping__");
sleep(1);
/*sendt child signal*/
kill(getppid(),SIGUSR1);
__receivedSignalNo__g = DISC_OFF;
}
}
}
return 0;
}
/******************************************************************************/
static void SigHandler(int _sigNUm)
{
/*set father globals discretes*/
__receivedSignalNo__g = DISC_ON;
}
/******************************************************************************/
|
the_stack_data/101434.c | /*
* math/__divdi3.c
*
* This file is part of JunOS C Library.
*
* Copyright (C) 2016, Liu Xiaofeng <[email protected]>
* Licensed under MIT, http://opensource.org/licenses/MIT.
*/
#include <stdint.h>
int64_t __divdi3(int64_t a, int64_t b)
{
int64_t ret = 0;
int sign1 = 0, sign2 = 0;
if (a < 0) {
sign1 = 1;
a = -a;
}
if (b < 0) {
sign2 = 1;
b = -b;
}
if (b == 0)
return (int64_t) -1;
while (a > b) {
a = a - b;
ret++;
}
return (sign1 ^ sign2) ? -ret : ret;
}
|
the_stack_data/366120.c | /* Inclusión de archivos */
#include <stdio.h>
void holamundo(void) /* Función donde se ejecuta la lógica del programa */
{
printf("Hola Mundo\n"); /* imprime la cadena */
return; /* sale de la función */
}
int main(void) /* Función principal del programa */
{
holamundo(); /* llamada a la función holamundo */
return 0; /* sale del programa con código 0 (correcto) */
} |
the_stack_data/50136779.c | #include <stdio.h>
#include <stdlib.h>
#define TRUE 1
#define FALSE 0
struct node {
int data;
struct node *next;
};
/* points to the head node */
struct node *head = NULL;
void insert_at_head(void);
void delete(void);
void contains(void);
int main()
{
char option;
int quit = FALSE;
while (quit == FALSE) {
printf("Enter an option: ");
scanf(" %c", &option);
while(getchar() != '\n')
;
switch (option) {
case 'i': insert_at_head();
break;
case 'q': quit = TRUE;
break;
default: printf("Not a valid option\n");
}
printf("\n");
}
printf("Exiting.\n");
return 0;
}
/* insert: insert an integer value into the head of list, not ordered */
void insert_at_head(void)
{
struct node *new_node;
new_node = malloc(sizeof(struct node));
/* if space cannot be allocated for node, print message */
if (new_node == NULL) {
printf("Could not allocate space for new list member\n");
return;
}
printf("Enter an whole number to store in the list: ");
scanf("%d", &new_node->data);
if (head == NULL) {
head = new_node;
head->next = NULL;
} else {
new_node->next = head;
head = new_node;
}
printf("<%d> inserted at %p\n", head->data, &head);
}
|
the_stack_data/104827790.c | typedef struct {
int a;
int b;
union {
int x;
char y;
};
union {
int s;
int t;
};
} foo_t;
int bar(foo_t arg) {
return arg.s;
}
extern int printf(const char* f, ...);
extern int atoi(const char* s);
int main() {
foo_t f;
f.t = 3;
printf("%d\n", bar(f));
} |
the_stack_data/45311.c | #include <stdio.h>
int calc(int a, int b) {
int c = a + b;
printf("c=%d\n", c);
return c;
}
|
the_stack_data/62457.c | // b. Copy the contents of the file to another.
#include<stdio.h>
int main()
{
FILE *fp1,*fp2;
char ch;
fp1=fopen("C-Assignments/a.txt","r");
fp2=fopen("C-Assignments/b.txt","w");
printf("file-1 and file-2 are opened\n");
while((ch=fgetc(fp1))!=EOF)
{
fprintf(fp2,"%c",ch);
}
printf("\nFiles contents are successfully copied");
fclose(fp1);
fclose(fp2);
printf("\nfile-1 and file-2 are closed");
} |
the_stack_data/232954884.c | /* PR middle-end/79788 */
/* { dg-do compile } */
/* { dg-options "-ftrapv" } */
void bar (void);
void
foo (long long int p, long long int q)
{
if (p >= 1234567891234567891234567891234567812 + q) /* { dg-warning "integer constant is too large for its type" } */
bar ();
}
|
the_stack_data/107953168.c | #include <stdint.h>
const uint8_t __emoji_u1F629[6456] = {
0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x03,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc7, 0x91, 0x4b, 0x09, 0xd6, 0x93, 0x3d, 0x1e, 0xe1, 0x96, 0x34, 0x2a, 0xe1, 0x96, 0x34, 0x2a, 0xd8, 0x93, 0x3c, 0x1e, 0xc8, 0x90, 0x48, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcb, 0x8c, 0x3e, 0x0a, 0xed, 0x96, 0x20, 0x51, 0xf6, 0xa2, 0x1b, 0x9b, 0xf9, 0xac, 0x1b, 0xd5, 0xfc, 0xb4, 0x1a, 0xf6, 0xfe, 0xbb, 0x19, 0xff, 0xff, 0xc0, 0x1a, 0xff, 0xff, 0xc0, 0x19, 0xff, 0xfe, 0xbb, 0x1a, 0xff, 0xfc, 0xb4, 0x1a, 0xf7, 0xf9, 0xab, 0x1a, 0xd7, 0xf6, 0xa2, 0x1a, 0x9d, 0xee, 0x95, 0x1f, 0x54, 0xd0, 0x8b, 0x37, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0x8a, 0x26, 0x1a, 0xf4, 0x98, 0x15, 0x8b, 0xfb, 0xa8, 0x13, 0xed, 0xff, 0xbc, 0x13, 0xff, 0xff, 0xcc, 0x15, 0xff, 0xff, 0xda, 0x20, 0xff, 0xff, 0xe5, 0x41, 0xff, 0xff, 0xec, 0x5f, 0xff, 0xff, 0xef, 0x6e, 0xff, 0xff, 0xef, 0x6f, 0xff, 0xff, 0xec, 0x62, 0xff, 0xff, 0xe5, 0x45, 0xff, 0xff, 0xda, 0x23, 0xff, 0xff, 0xcc, 0x15, 0xff, 0xff, 0xbc, 0x13, 0xff, 0xfb, 0xa8, 0x12, 0xef, 0xf4, 0x98, 0x14, 0x90, 0xdb, 0x8a, 0x27, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x84, 0x37, 0x06, 0xf0, 0x92, 0x13, 0x7b, 0xfc, 0xa5, 0x0e, 0xf3, 0xff, 0xbd, 0x0f, 0xff, 0xff, 0xd3, 0x1d, 0xff, 0xff, 0xe9, 0x65, 0xff, 0xff, 0xf7, 0xa9, 0xff, 0xff, 0xfc, 0xd9, 0xff, 0xff, 0xfd, 0xe5, 0xff, 0xff, 0xfd, 0xe5, 0xff, 0xff, 0xfd, 0xe6, 0xff, 0xff, 0xfd, 0xe6, 0xff, 0xff, 0xfd, 0xe5, 0xff, 0xff, 0xfd, 0xe4, 0xff, 0xff, 0xfd, 0xdc, 0xff, 0xff, 0xf8, 0xb3, 0xff, 0xff, 0xeb, 0x70, 0xff, 0xff, 0xd4, 0x25, 0xff, 0xff, 0xbd, 0x0e, 0xff, 0xfc, 0xa5, 0x0d, 0xf5, 0xf0, 0x91, 0x13, 0x82, 0xc7, 0x84, 0x36, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe1, 0x86, 0x1c, 0x23, 0xf6, 0x96, 0x0d, 0xcc, 0xff, 0xb2, 0x0b, 0xff, 0xff, 0xcb, 0x17, 0xff, 0xff, 0xe9, 0x70, 0xff, 0xff, 0xfb, 0xc3, 0xff, 0xff, 0xfc, 0xcf, 0xff, 0xff, 0xfc, 0xd2, 0xff, 0xfc, 0xf7, 0xca, 0xff, 0xf6, 0xed, 0xc0, 0xff, 0xff, 0xfd, 0xdb, 0xff, 0xff, 0xfd, 0xdd, 0xff, 0xff, 0xfd, 0xdd, 0xff, 0xff, 0xfd, 0xdb, 0xff, 0xf4, 0xeb, 0xbe, 0xff, 0xfb, 0xf5, 0xc7, 0xff, 0xff, 0xfc, 0xd1, 0xff, 0xff, 0xfc, 0xce, 0xff, 0xff, 0xfc, 0xc8, 0xff, 0xff, 0xed, 0x7f, 0xff, 0xff, 0xcd, 0x1f, 0xff, 0xff, 0xb2, 0x0b, 0xff, 0xf8, 0x97, 0x0c, 0xd1, 0xe1, 0x86, 0x1c, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe4, 0x85, 0x17, 0x3a, 0xfb, 0x9a, 0x09, 0xeb, 0xff, 0xb7, 0x0a, 0xff, 0xff, 0xd7, 0x3a, 0xff, 0xff, 0xf7, 0xa8, 0xff, 0xff, 0xfb, 0xbc, 0xff, 0xff, 0xfb, 0xc0, 0xff, 0xff, 0xfc, 0xc3, 0xff, 0xfe, 0xf9, 0xc4, 0xff, 0xb0, 0x8f, 0x56, 0xff, 0xb5, 0x9d, 0x76, 0xff, 0xff, 0xfc, 0xd1, 0xff, 0xff, 0xfc, 0xd2, 0xff, 0xff, 0xfc, 0xd3, 0xff, 0xff, 0xfc, 0xd1, 0xff, 0xb6, 0x9d, 0x75, 0xff, 0xa7, 0x84, 0x4c, 0xff, 0xfe, 0xf9, 0xc2, 0xff, 0xff, 0xfc, 0xc3, 0xff, 0xff, 0xfb, 0xbf, 0xff, 0xff, 0xfb, 0xbc, 0xff, 0xff, 0xf9, 0xb1, 0xff, 0xff, 0xdb, 0x4c, 0xff, 0xff, 0xb8, 0x0a, 0xff, 0xfb, 0x9b, 0x08, 0xee, 0xe5, 0x87, 0x16, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe2, 0x83, 0x16, 0x3a, 0xfb, 0x98, 0x07, 0xf2, 0xff, 0xb7, 0x09, 0xff, 0xff, 0xdc, 0x55, 0xff, 0xff, 0xf8, 0xa9, 0xff, 0xff, 0xfa, 0xac, 0xff, 0xff, 0xfb, 0xaf, 0xff, 0xff, 0xfb, 0xb3, 0xff, 0xff, 0xfa, 0xb5, 0xff, 0xd7, 0xbe, 0x75, 0xff, 0x6e, 0x39, 0x09, 0xff, 0xeb, 0xe3, 0xaf, 0xff, 0xff, 0xfc, 0xc3, 0xff, 0xff, 0xfc, 0xc5, 0xff, 0xff, 0xfc, 0xc4, 0xff, 0xff, 0xfb, 0xc3, 0xff, 0xeb, 0xe3, 0xae, 0xff, 0x6d, 0x38, 0x08, 0xff, 0xd2, 0xb8, 0x6f, 0xff, 0xfe, 0xfa, 0xb4, 0xff, 0xff, 0xfb, 0xb2, 0xff, 0xff, 0xfa, 0xaf, 0xff, 0xff, 0xfa, 0xac, 0xff, 0xff, 0xf8, 0xaa, 0xff, 0xff, 0xe1, 0x6a, 0xff, 0xff, 0xb8, 0x0b, 0xff, 0xfb, 0x9a, 0x07, 0xf6, 0xe4, 0x84, 0x14, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0x7e, 0x19, 0x23, 0xfa, 0x93, 0x06, 0xeb, 0xff, 0xb3, 0x08, 0xff, 0xff, 0xd9, 0x55, 0xff, 0xff, 0xf2, 0x9a, 0xff, 0xff, 0xf8, 0x9b, 0xff, 0xff, 0xfa, 0x9e, 0xff, 0xff, 0xfa, 0xa1, 0xff, 0xfe, 0xf9, 0xa3, 0xff, 0xdd, 0xc5, 0x6f, 0xff, 0x78, 0x44, 0x0b, 0xff, 0xad, 0x8b, 0x50, 0xff, 0xff, 0xfc, 0xb4, 0xff, 0xff, 0xfb, 0xb4, 0xff, 0xff, 0xfb, 0xb5, 0xff, 0xff, 0xfb, 0xb5, 0xff, 0xff, 0xfb, 0xb3, 0xff, 0xff, 0xfc, 0xb4, 0xff, 0xad, 0x8a, 0x4f, 0xff, 0x78, 0x42, 0x09, 0xff, 0xda, 0xc1, 0x6c, 0xff, 0xfe, 0xf8, 0xa2, 0xff, 0xff, 0xfa, 0xa1, 0xff, 0xff, 0xfa, 0x9e, 0xff, 0xff, 0xf8, 0x9b, 0xff, 0xff, 0xf2, 0x99, 0xff, 0xff, 0xdf, 0x69, 0xff, 0xff, 0xb4, 0x0a, 0xff, 0xfb, 0x94, 0x07, 0xef, 0xdd, 0x80, 0x19, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbc, 0x7f, 0x39, 0x06, 0xf5, 0x8b, 0x09, 0xcc, 0xff, 0xab, 0x07, 0xff, 0xff, 0xcf, 0x3f, 0xff, 0xff, 0xec, 0x89, 0xff, 0xff, 0xf2, 0x8b, 0xff, 0xff, 0xf7, 0x8d, 0xff, 0xff, 0xf9, 0x90, 0xff, 0xfc, 0xf3, 0x8b, 0xff, 0xcb, 0xac, 0x50, 0xff, 0x77, 0x42, 0x09, 0xff, 0x95, 0x68, 0x29, 0xff, 0xfa, 0xf5, 0xa0, 0xff, 0xff, 0xfa, 0xa1, 0xff, 0xff, 0xfa, 0xa3, 0xff, 0xff, 0xfa, 0xa4, 0xff, 0xff, 0xfa, 0xa4, 0xff, 0xff, 0xfa, 0xa3, 0xff, 0xff, 0xfa, 0xa1, 0xff, 0xf8, 0xf4, 0x9f, 0xff, 0x95, 0x66, 0x26, 0xff, 0x78, 0x42, 0x08, 0xff, 0xc9, 0xaa, 0x4e, 0xff, 0xfc, 0xf3, 0x8a, 0xff, 0xff, 0xf9, 0x90, 0xff, 0xff, 0xf7, 0x8d, 0xff, 0xff, 0xf2, 0x8b, 0xff, 0xff, 0xeb, 0x88, 0xff, 0xff, 0xd5, 0x52, 0xff, 0xff, 0xac, 0x07, 0xff, 0xf6, 0x8c, 0x08, 0xd3, 0xc2, 0x7f, 0x31, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe9, 0x82, 0x0e, 0x7b, 0xff, 0x9e, 0x06, 0xff, 0xff, 0xbf, 0x20, 0xff, 0xff, 0xe3, 0x76, 0xff, 0xff, 0xea, 0x7a, 0xff, 0xff, 0xf0, 0x7d, 0xff, 0xfe, 0xf3, 0x7e, 0xff, 0xe4, 0xcd, 0x5d, 0xff, 0x98, 0x6b, 0x20, 0xff, 0x73, 0x3b, 0x03, 0xff, 0x9e, 0x74, 0x2e, 0xff, 0xf6, 0xf0, 0x8c, 0xff, 0xff, 0xf9, 0x8e, 0xff, 0xff, 0xf9, 0x90, 0xff, 0xff, 0xf9, 0x92, 0xff, 0xff, 0xf9, 0x92, 0xff, 0xff, 0xf9, 0x92, 0xff, 0xff, 0xf9, 0x92, 0xff, 0xff, 0xf9, 0x90, 0xff, 0xff, 0xf9, 0x8d, 0xff, 0xf5, 0xef, 0x8c, 0xff, 0x9e, 0x72, 0x2c, 0xff, 0x74, 0x3b, 0x04, 0xff, 0x97, 0x69, 0x1e, 0xff, 0xe2, 0xca, 0x5a, 0xff, 0xfe, 0xf3, 0x7e, 0xff, 0xff, 0xef, 0x7d, 0xff, 0xff, 0xeb, 0x7a, 0xff, 0xff, 0xe3, 0x77, 0xff, 0xff, 0xc4, 0x2f, 0xff, 0xff, 0x9f, 0x05, 0xff, 0xea, 0x83, 0x0c, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc9, 0x79, 0x20, 0x1a, 0xf7, 0x8d, 0x05, 0xf4, 0xff, 0xad, 0x09, 0xff, 0xff, 0xd5, 0x57, 0xff, 0xff, 0xe2, 0x69, 0xff, 0xff, 0xe7, 0x6c, 0xff, 0xff, 0xed, 0x6f, 0xff, 0xff, 0xf2, 0x71, 0xff, 0x97, 0x74, 0x2e, 0xff, 0x97, 0x6f, 0x2a, 0xff, 0xcf, 0xba, 0x5b, 0xff, 0xfd, 0xf9, 0x80, 0xff, 0xff, 0xf8, 0x7c, 0xff, 0xff, 0xf8, 0x7d, 0xff, 0xff, 0xf7, 0x7f, 0xff, 0xff, 0xf8, 0x81, 0xff, 0xff, 0xf8, 0x82, 0xff, 0xff, 0xf8, 0x82, 0xff, 0xff, 0xf8, 0x81, 0xff, 0xff, 0xf8, 0x7f, 0xff, 0xff, 0xf8, 0x7d, 0xff, 0xff, 0xf8, 0x7b, 0xff, 0xfd, 0xf8, 0x80, 0xff, 0xcc, 0xb6, 0x58, 0xff, 0x96, 0x6c, 0x27, 0xff, 0x90, 0x69, 0x29, 0xff, 0xfe, 0xf1, 0x70, 0xff, 0xff, 0xec, 0x6f, 0xff, 0xff, 0xe8, 0x6c, 0xff, 0xff, 0xe2, 0x6a, 0xff, 0xff, 0xd8, 0x61, 0xff, 0xff, 0xaf, 0x0f, 0xff, 0xf8, 0x8e, 0x05, 0xf7, 0xd1, 0x7c, 0x1e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe6, 0x7f, 0x0b, 0x8b, 0xfe, 0x9b, 0x06, 0xff, 0xff, 0xbd, 0x28, 0xff, 0xff, 0xd8, 0x5a, 0xff, 0xff, 0xde, 0x5c, 0xff, 0xff, 0xe4, 0x5f, 0xff, 0xff, 0xe9, 0x61, 0xff, 0xff, 0xee, 0x64, 0xff, 0xff, 0xf4, 0x6b, 0xff, 0xff, 0xf7, 0x6d, 0xff, 0xff, 0xf7, 0x68, 0xff, 0xff, 0xf7, 0x6a, 0xff, 0xff, 0xf7, 0x6b, 0xff, 0xf5, 0xe5, 0x5f, 0xff, 0xbe, 0x9e, 0x39, 0xff, 0xff, 0xf6, 0x6f, 0xff, 0xff, 0xf7, 0x71, 0xff, 0xff, 0xf7, 0x71, 0xff, 0xff, 0xf6, 0x6f, 0xff, 0xbd, 0x9e, 0x3a, 0xff, 0xf1, 0xe0, 0x5b, 0xff, 0xff, 0xf7, 0x6b, 0xff, 0xff, 0xf7, 0x6a, 0xff, 0xff, 0xf6, 0x69, 0xff, 0xff, 0xf6, 0x6d, 0xff, 0xff, 0xf4, 0x6c, 0xff, 0xff, 0xee, 0x63, 0xff, 0xff, 0xe9, 0x61, 0xff, 0xff, 0xe4, 0x5f, 0xff, 0xff, 0xde, 0x5d, 0xff, 0xff, 0xd8, 0x5a, 0xff, 0xff, 0xc2, 0x35, 0xff, 0xfe, 0x9c, 0x06, 0xff, 0xe8, 0x80, 0x0a, 0x95, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb8, 0x7c, 0x37, 0x0a, 0xef, 0x86, 0x06, 0xed, 0xff, 0xa4, 0x09, 0xff, 0xff, 0xc8, 0x41, 0xff, 0xff, 0xd4, 0x4e, 0xff, 0xff, 0xdb, 0x51, 0xff, 0xff, 0xe0, 0x53, 0xff, 0xff, 0xe5, 0x55, 0xff, 0xff, 0xea, 0x57, 0xff, 0xff, 0xed, 0x58, 0xff, 0xff, 0xf0, 0x59, 0xff, 0xff, 0xf2, 0x5a, 0xff, 0xff, 0xf4, 0x5c, 0xff, 0xf7, 0xe7, 0x51, 0xff, 0x96, 0x69, 0x18, 0xff, 0x90, 0x69, 0x1f, 0xff, 0xff, 0xf7, 0x61, 0xff, 0xff, 0xf6, 0x61, 0xff, 0xff, 0xf6, 0x61, 0xff, 0xff, 0xf7, 0x61, 0xff, 0x93, 0x6d, 0x21, 0xff, 0x8f, 0x62, 0x16, 0xff, 0xf7, 0xe6, 0x52, 0xff, 0xff, 0xf3, 0x5b, 0xff, 0xff, 0xf1, 0x5b, 0xff, 0xff, 0xef, 0x59, 0xff, 0xff, 0xec, 0x59, 0xff, 0xff, 0xe9, 0x56, 0xff, 0xff, 0xe5, 0x55, 0xff, 0xff, 0xe0, 0x52, 0xff, 0xff, 0xdb, 0x51, 0xff, 0xff, 0xd4, 0x4e, 0xff, 0xff, 0xcb, 0x47, 0xff, 0xff, 0xa6, 0x0d, 0xff, 0xf1, 0x87, 0x06, 0xf2, 0xc0, 0x7d, 0x33, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0x79, 0x13, 0x50, 0xf6, 0x8e, 0x04, 0xff, 0xff, 0xad, 0x17, 0xff, 0xff, 0xc8, 0x3f, 0xff, 0xff, 0xd1, 0x44, 0xff, 0xff, 0xd6, 0x47, 0xff, 0xff, 0xdc, 0x48, 0xff, 0xff, 0xe1, 0x4a, 0xff, 0xff, 0xe6, 0x4c, 0xff, 0xff, 0xe9, 0x4d, 0xff, 0xff, 0xec, 0x4e, 0xff, 0xfd, 0xe9, 0x4c, 0xff, 0xe1, 0xc2, 0x36, 0xff, 0x8d, 0x5b, 0x0e, 0xff, 0x7b, 0x42, 0x04, 0xff, 0xc5, 0xad, 0x38, 0xff, 0xff, 0xf6, 0x53, 0xff, 0xff, 0xf5, 0x54, 0xff, 0xff, 0xf5, 0x53, 0xff, 0xff, 0xf5, 0x54, 0xff, 0xc8, 0xb1, 0x39, 0xff, 0x7c, 0x43, 0x04, 0xff, 0x8c, 0x5a, 0x0f, 0xff, 0xe0, 0xc0, 0x35, 0xff, 0xfd, 0xe8, 0x4b, 0xff, 0xff, 0xeb, 0x4d, 0xff, 0xff, 0xe8, 0x4c, 0xff, 0xff, 0xe5, 0x4b, 0xff, 0xff, 0xe1, 0x49, 0xff, 0xff, 0xdc, 0x48, 0xff, 0xff, 0xd7, 0x47, 0xff, 0xff, 0xd1, 0x44, 0xff, 0xff, 0xc8, 0x3f, 0xff, 0xff, 0xb0, 0x1f, 0xff, 0xf7, 0x90, 0x05, 0xff, 0xdb, 0x79, 0x11, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe1, 0x7b, 0x0a, 0x99, 0xf6, 0x94, 0x06, 0xff, 0xfe, 0xb2, 0x21, 0xff, 0xff, 0xc4, 0x35, 0xff, 0xff, 0xcc, 0x3a, 0xff, 0xff, 0xd2, 0x3d, 0xff, 0xfd, 0xd5, 0x3d, 0xff, 0xcc, 0x9d, 0x25, 0xff, 0xdc, 0xb0, 0x2a, 0xff, 0xdb, 0xb2, 0x2a, 0xff, 0xc2, 0x96, 0x21, 0xff, 0x96, 0x63, 0x0f, 0xff, 0x76, 0x3f, 0x04, 0xff, 0x89, 0x4f, 0x05, 0xff, 0x97, 0x65, 0x11, 0xff, 0xfa, 0xef, 0x4b, 0xff, 0xff, 0xf0, 0x48, 0xff, 0xff, 0xf1, 0x47, 0xff, 0xff, 0xf1, 0x47, 0xff, 0xff, 0xf0, 0x48, 0xff, 0xfb, 0xf0, 0x4c, 0xff, 0x9a, 0x6a, 0x13, 0xff, 0x8a, 0x4f, 0x05, 0xff, 0x77, 0x3f, 0x04, 0xff, 0x93, 0x60, 0x0f, 0xff, 0xc0, 0x93, 0x20, 0xff, 0xda, 0xaf, 0x29, 0xff, 0xdc, 0xb0, 0x2a, 0xff, 0xc9, 0x99, 0x24, 0xff, 0xfa, 0xd2, 0x3b, 0xff, 0xff, 0xd3, 0x3d, 0xff, 0xff, 0xcd, 0x3a, 0xff, 0xff, 0xc5, 0x36, 0xff, 0xfe, 0xb5, 0x27, 0xff, 0xf6, 0x95, 0x07, 0xff, 0xe2, 0x7c, 0x0a, 0xa4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe1, 0x7d, 0x08, 0xd4, 0xf5, 0x97, 0x07, 0xff, 0xfe, 0xb3, 0x23, 0xff, 0xff, 0xc1, 0x2e, 0xff, 0xff, 0xc8, 0x33, 0xff, 0xff, 0xcf, 0x35, 0xff, 0xff, 0xd6, 0x38, 0xff, 0xa5, 0x82, 0x23, 0xff, 0x6b, 0x34, 0x03, 0xff, 0x72, 0x3b, 0x04, 0xff, 0x7c, 0x43, 0x04, 0xff, 0x8a, 0x4f, 0x05, 0xff, 0x93, 0x56, 0x05, 0xff, 0x9c, 0x68, 0x10, 0xff, 0xed, 0xdd, 0x40, 0xff, 0xff, 0xeb, 0x3e, 0xff, 0xff, 0xeb, 0x3f, 0xff, 0xff, 0xec, 0x3e, 0xff, 0xff, 0xec, 0x3f, 0xff, 0xff, 0xec, 0x3f, 0xff, 0xff, 0xeb, 0x3e, 0xff, 0xf0, 0xe1, 0x41, 0xff, 0x9e, 0x6b, 0x12, 0xff, 0x93, 0x56, 0x05, 0xff, 0x8b, 0x50, 0x05, 0xff, 0x7d, 0x44, 0x04, 0xff, 0x73, 0x3b, 0x04, 0xff, 0x6c, 0x35, 0x03, 0xff, 0x9b, 0x77, 0x1f, 0xff, 0xfe, 0xd6, 0x38, 0xff, 0xff, 0xcf, 0x35, 0xff, 0xff, 0xc8, 0x33, 0xff, 0xff, 0xc2, 0x2e, 0xff, 0xfe, 0xb5, 0x27, 0xff, 0xf5, 0x99, 0x08, 0xff, 0xe2, 0x7d, 0x08, 0xde, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xb2, 0x7e, 0x40, 0x08, 0xe2, 0x7d, 0x06, 0xf6, 0xf3, 0x99, 0x09, 0xff, 0xfc, 0xb1, 0x1e, 0xff, 0xff, 0xbd, 0x28, 0xff, 0xff, 0xc4, 0x2d, 0xff, 0xff, 0xcb, 0x2e, 0xff, 0xff, 0xd0, 0x30, 0xff, 0xff, 0xda, 0x36, 0xff, 0xde, 0xc4, 0x35, 0xff, 0xb3, 0x8e, 0x22, 0xff, 0xa7, 0x78, 0x17, 0xff, 0xb0, 0x86, 0x1d, 0xff, 0xcf, 0xb4, 0x2f, 0xff, 0xfa, 0xe9, 0x3e, 0xff, 0xff, 0xe7, 0x37, 0xff, 0xff, 0xe7, 0x37, 0xff, 0xff, 0xe7, 0x37, 0xff, 0xff, 0xe7, 0x37, 0xff, 0xff, 0xe7, 0x37, 0xff, 0xff, 0xe7, 0x37, 0xff, 0xff, 0xe7, 0x36, 0xff, 0xff, 0xe7, 0x37, 0xff, 0xfa, 0xea, 0x3e, 0xff, 0xd0, 0xb5, 0x30, 0xff, 0xb0, 0x86, 0x1d, 0xff, 0xa6, 0x77, 0x16, 0xff, 0xb4, 0x8f, 0x22, 0xff, 0xdc, 0xc2, 0x34, 0xff, 0xff, 0xdb, 0x36, 0xff, 0xff, 0xd0, 0x30, 0xff, 0xff, 0xcb, 0x2e, 0xff, 0xff, 0xc5, 0x2c, 0xff, 0xff, 0xbe, 0x29, 0xff, 0xfd, 0xb3, 0x20, 0xff, 0xf4, 0x9b, 0x0a, 0xff, 0xe3, 0x7e, 0x05, 0xfb, 0xb8, 0x7c, 0x38, 0x0f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xbb, 0x77, 0x2d, 0x1d, 0xe1, 0x7c, 0x02, 0xff, 0xf2, 0x99, 0x09, 0xff, 0xfb, 0xaf, 0x18, 0xff, 0xfe, 0xba, 0x24, 0xff, 0xff, 0xc1, 0x28, 0xff, 0xff, 0xc7, 0x2a, 0xff, 0xff, 0xcc, 0x2b, 0xff, 0xff, 0xd0, 0x2c, 0xff, 0xff, 0xd4, 0x2d, 0xff, 0xff, 0xdb, 0x31, 0xff, 0xff, 0xe2, 0x34, 0xff, 0xff, 0xe2, 0x33, 0xff, 0xff, 0xde, 0x2f, 0xff, 0xff, 0xdf, 0x30, 0xff, 0xff, 0xe1, 0x31, 0xff, 0xff, 0xe2, 0x31, 0xff, 0xff, 0xe3, 0x31, 0xff, 0xff, 0xe3, 0x32, 0xff, 0xff, 0xe3, 0x32, 0xff, 0xff, 0xe3, 0x31, 0xff, 0xff, 0xe2, 0x31, 0xff, 0xff, 0xe1, 0x32, 0xff, 0xff, 0xdf, 0x30, 0xff, 0xff, 0xde, 0x2f, 0xff, 0xff, 0xe2, 0x33, 0xff, 0xff, 0xe3, 0x34, 0xff, 0xff, 0xdc, 0x31, 0xff, 0xff, 0xd4, 0x2d, 0xff, 0xff, 0xd1, 0x2c, 0xff, 0xff, 0xcc, 0x2b, 0xff, 0xff, 0xc7, 0x2a, 0xff, 0xff, 0xc2, 0x29, 0xff, 0xff, 0xbb, 0x25, 0xff, 0xfb, 0xb0, 0x19, 0xff, 0xf2, 0x9b, 0x0a, 0xff, 0xe2, 0x7e, 0x02, 0xff, 0xbf, 0x76, 0x27, 0x25, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xc1, 0x73, 0x22, 0x28, 0xdf, 0x7b, 0x02, 0xff, 0xf0, 0x98, 0x08, 0xff, 0xf9, 0xac, 0x13, 0xff, 0xfe, 0xb7, 0x21, 0xff, 0xff, 0xbf, 0x28, 0xff, 0xff, 0xc4, 0x29, 0xff, 0xff, 0xc9, 0x2a, 0xff, 0xff, 0xcd, 0x2b, 0xff, 0xff, 0xd1, 0x2c, 0xff, 0xff, 0xd5, 0x2d, 0xff, 0xff, 0xd7, 0x2d, 0xff, 0xff, 0xd9, 0x2d, 0xff, 0xff, 0xda, 0x2e, 0xff, 0xff, 0xdc, 0x2e, 0xff, 0xff, 0xde, 0x2e, 0xff, 0xff, 0xdf, 0x30, 0xff, 0xff, 0xe0, 0x31, 0xff, 0xff, 0xe0, 0x31, 0xff, 0xff, 0xe0, 0x31, 0xff, 0xff, 0xe0, 0x31, 0xff, 0xff, 0xdf, 0x30, 0xff, 0xff, 0xde, 0x2f, 0xff, 0xff, 0xdc, 0x2e, 0xff, 0xff, 0xda, 0x2e, 0xff, 0xff, 0xd9, 0x2d, 0xff, 0xff, 0xd7, 0x2d, 0xff, 0xff, 0xd5, 0x2d, 0xff, 0xff, 0xd1, 0x2b, 0xff, 0xff, 0xcd, 0x2b, 0xff, 0xff, 0xca, 0x2a, 0xff, 0xff, 0xc4, 0x2a, 0xff, 0xff, 0xbf, 0x28, 0xff, 0xfe, 0xb8, 0x23, 0xff, 0xfa, 0xad, 0x15, 0xff, 0xf0, 0x9a, 0x09, 0xff, 0xe1, 0x7d, 0x02, 0xff, 0xc4, 0x70, 0x1a, 0x33, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xc0, 0x72, 0x22, 0x29, 0xdd, 0x7a, 0x02, 0xff, 0xed, 0x96, 0x07, 0xff, 0xf8, 0xaa, 0x11, 0xff, 0xfd, 0xb6, 0x20, 0xff, 0xff, 0xbe, 0x29, 0xff, 0xff, 0xc3, 0x2b, 0xff, 0xff, 0xc8, 0x2c, 0xff, 0xff, 0xcb, 0x2c, 0xff, 0xff, 0xcf, 0x2d, 0xff, 0xff, 0xd2, 0x2e, 0xff, 0xff, 0xd5, 0x2f, 0xff, 0xff, 0xd6, 0x2f, 0xff, 0xff, 0xd9, 0x2f, 0xff, 0xff, 0xda, 0x30, 0xff, 0xff, 0xdb, 0x30, 0xff, 0xff, 0xdc, 0x30, 0xff, 0xfd, 0xda, 0x2f, 0xff, 0xfd, 0xd8, 0x2e, 0xff, 0xfd, 0xd9, 0x2e, 0xff, 0xfe, 0xda, 0x2f, 0xff, 0xff, 0xdc, 0x30, 0xff, 0xff, 0xdb, 0x30, 0xff, 0xff, 0xda, 0x30, 0xff, 0xff, 0xd9, 0x2f, 0xff, 0xff, 0xd7, 0x2e, 0xff, 0xff, 0xd5, 0x2f, 0xff, 0xff, 0xd2, 0x2e, 0xff, 0xff, 0xcf, 0x2d, 0xff, 0xff, 0xcb, 0x2d, 0xff, 0xff, 0xc8, 0x2c, 0xff, 0xff, 0xc4, 0x2b, 0xff, 0xff, 0xbe, 0x29, 0xff, 0xfe, 0xb6, 0x21, 0xff, 0xf9, 0xab, 0x12, 0xff, 0xee, 0x97, 0x08, 0xff, 0xde, 0x7c, 0x02, 0xff, 0xc3, 0x6f, 0x1a, 0x33, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xb3, 0x72, 0x2d, 0x1d, 0xd9, 0x77, 0x02, 0xff, 0xea, 0x92, 0x07, 0xff, 0xf6, 0xa6, 0x0e, 0xff, 0xfc, 0xb4, 0x1d, 0xff, 0xff, 0xbb, 0x29, 0xff, 0xff, 0xc1, 0x2d, 0xff, 0xff, 0xc5, 0x2e, 0xff, 0xff, 0xc9, 0x2e, 0xff, 0xff, 0xcd, 0x30, 0xff, 0xff, 0xcf, 0x2f, 0xff, 0xff, 0xd2, 0x30, 0xff, 0xff, 0xd4, 0x31, 0xff, 0xfe, 0xd5, 0x30, 0xff, 0xf7, 0xca, 0x2b, 0xff, 0xd1, 0x9e, 0x1c, 0xff, 0xa8, 0x72, 0x10, 0xff, 0x92, 0x5a, 0x0a, 0xff, 0x87, 0x50, 0x07, 0xff, 0x89, 0x51, 0x07, 0xff, 0x95, 0x5d, 0x0a, 0xff, 0xad, 0x78, 0x12, 0xff, 0xd9, 0xa6, 0x1e, 0xff, 0xf9, 0xce, 0x2c, 0xff, 0xff, 0xd5, 0x31, 0xff, 0xff, 0xd4, 0x30, 0xff, 0xff, 0xd2, 0x30, 0xff, 0xff, 0xcf, 0x2f, 0xff, 0xff, 0xcd, 0x2f, 0xff, 0xff, 0xca, 0x2e, 0xff, 0xff, 0xc5, 0x2e, 0xff, 0xff, 0xc1, 0x2d, 0xff, 0xff, 0xbc, 0x2a, 0xff, 0xfc, 0xb4, 0x1e, 0xff, 0xf7, 0xa7, 0x0e, 0xff, 0xeb, 0x94, 0x08, 0xff, 0xdb, 0x78, 0x02, 0xff, 0xbb, 0x73, 0x27, 0x25, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xb2, 0x7d, 0x3f, 0x09, 0xd4, 0x73, 0x05, 0xf6, 0xe6, 0x8d, 0x07, 0xff, 0xf3, 0xa2, 0x0c, 0xff, 0xfb, 0xb0, 0x17, 0xff, 0xfe, 0xb9, 0x26, 0xff, 0xff, 0xbe, 0x2f, 0xff, 0xff, 0xc3, 0x2f, 0xff, 0xff, 0xc7, 0x31, 0xff, 0xff, 0xcb, 0x30, 0xff, 0xff, 0xcd, 0x31, 0xff, 0xff, 0xcf, 0x32, 0xff, 0xf9, 0xc7, 0x2c, 0xff, 0xbb, 0x82, 0x16, 0xff, 0x7d, 0x47, 0x0b, 0xff, 0x8a, 0x68, 0x4a, 0xff, 0xaf, 0x9e, 0x8d, 0xff, 0xc6, 0xc0, 0xb9, 0xff, 0xd0, 0xce, 0xca, 0xff, 0xd2, 0xcf, 0xcd, 0xff, 0xc6, 0xc0, 0xba, 0xff, 0xaf, 0xa0, 0x90, 0xff, 0x8c, 0x6b, 0x4f, 0xff, 0x85, 0x4e, 0x0e, 0xff, 0xc9, 0x91, 0x1a, 0xff, 0xfc, 0xcb, 0x2e, 0xff, 0xff, 0xcf, 0x32, 0xff, 0xff, 0xcd, 0x32, 0xff, 0xff, 0xcb, 0x31, 0xff, 0xff, 0xc7, 0x30, 0xff, 0xff, 0xc3, 0x30, 0xff, 0xff, 0xbf, 0x2f, 0xff, 0xfe, 0xb9, 0x26, 0xff, 0xfb, 0xb1, 0x18, 0xff, 0xf4, 0xa4, 0x0d, 0xff, 0xe7, 0x8f, 0x08, 0xff, 0xd5, 0x74, 0x04, 0xfb, 0xb5, 0x79, 0x36, 0x10, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xce, 0x70, 0x08, 0xd5, 0xe1, 0x88, 0x06, 0xff, 0xef, 0x9d, 0x0c, 0xff, 0xf9, 0xac, 0x12, 0xff, 0xfd, 0xb4, 0x1f, 0xff, 0xff, 0xbc, 0x2c, 0xff, 0xff, 0xc1, 0x31, 0xff, 0xff, 0xc4, 0x32, 0xff, 0xff, 0xc8, 0x32, 0xff, 0xff, 0xca, 0x32, 0xff, 0xe8, 0xaf, 0x27, 0xff, 0x88, 0x4f, 0x09, 0xff, 0x89, 0x64, 0x3f, 0xff, 0xbb, 0xb8, 0xb4, 0xff, 0xc4, 0xc8, 0xcc, 0xff, 0xba, 0xbd, 0xc0, 0xff, 0xb1, 0xb3, 0xb6, 0xff, 0xac, 0xad, 0xaf, 0xff, 0xad, 0xae, 0xb0, 0xff, 0xb0, 0xb3, 0xb6, 0xff, 0xb9, 0xbd, 0xc0, 0xff, 0xc4, 0xc8, 0xcc, 0xff, 0xbc, 0xba, 0xb8, 0xff, 0x87, 0x62, 0x40, 0xff, 0x97, 0x5d, 0x0d, 0xff, 0xf2, 0xbb, 0x2b, 0xff, 0xff, 0xca, 0x33, 0xff, 0xff, 0xc8, 0x33, 0xff, 0xff, 0xc5, 0x33, 0xff, 0xff, 0xc1, 0x31, 0xff, 0xff, 0xbc, 0x2c, 0xff, 0xfd, 0xb5, 0x1f, 0xff, 0xfa, 0xad, 0x12, 0xff, 0xf0, 0x9f, 0x0d, 0xff, 0xe2, 0x89, 0x07, 0xff, 0xcf, 0x71, 0x08, 0xdf, 0xb3, 0x7d, 0x3d, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xca, 0x6c, 0x0a, 0x9b, 0xdb, 0x80, 0x06, 0xff, 0xea, 0x97, 0x0b, 0xff, 0xf5, 0xa7, 0x10, 0xff, 0xfc, 0xb1, 0x18, 0xff, 0xfe, 0xb7, 0x24, 0xff, 0xff, 0xbd, 0x2f, 0xff, 0xff, 0xc1, 0x33, 0xff, 0xff, 0xc4, 0x35, 0xff, 0xe3, 0xa7, 0x26, 0xff, 0x7d, 0x43, 0x06, 0xff, 0x91, 0x72, 0x50, 0xff, 0xa3, 0xa2, 0xa1, 0xff, 0x90, 0x80, 0x6e, 0xff, 0x86, 0x65, 0x3f, 0xff, 0x88, 0x5a, 0x21, 0xff, 0x8c, 0x56, 0x12, 0xff, 0x8e, 0x55, 0x0b, 0xff, 0x8f, 0x56, 0x0b, 0xff, 0x8c, 0x56, 0x12, 0xff, 0x88, 0x5a, 0x20, 0xff, 0x86, 0x64, 0x3d, 0xff, 0x90, 0x7f, 0x6d, 0xff, 0xa3, 0xa1, 0xa1, 0xff, 0x8e, 0x72, 0x52, 0xff, 0x87, 0x4d, 0x09, 0xff, 0xf0, 0xb4, 0x2b, 0xff, 0xff, 0xc5, 0x35, 0xff, 0xff, 0xc1, 0x33, 0xff, 0xff, 0xbd, 0x2f, 0xff, 0xfe, 0xb8, 0x25, 0xff, 0xfc, 0xb1, 0x18, 0xff, 0xf6, 0xa7, 0x10, 0xff, 0xeb, 0x98, 0x0c, 0xff, 0xdc, 0x81, 0x06, 0xff, 0xcb, 0x6d, 0x09, 0xa5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0x6b, 0x11, 0x52, 0xd4, 0x77, 0x04, 0xff, 0xe4, 0x8f, 0x0a, 0xff, 0xf0, 0xa1, 0x0f, 0xff, 0xf9, 0xac, 0x13, 0xff, 0xfd, 0xb4, 0x1c, 0xff, 0xfe, 0xb9, 0x28, 0xff, 0xff, 0xbe, 0x31, 0xff, 0xf2, 0xb1, 0x2d, 0xff, 0x83, 0x4a, 0x08, 0xff, 0x90, 0x54, 0x06, 0xff, 0x94, 0x5d, 0x12, 0xff, 0x92, 0x57, 0x09, 0xff, 0x9c, 0x5e, 0x05, 0xff, 0xa2, 0x64, 0x07, 0xff, 0xa5, 0x66, 0x07, 0xff, 0xa5, 0x66, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa5, 0x66, 0x07, 0xff, 0xa5, 0x66, 0x07, 0xff, 0xa3, 0x64, 0x07, 0xff, 0x9c, 0x5e, 0x05, 0xff, 0x92, 0x57, 0x09, 0xff, 0x92, 0x5c, 0x13, 0xff, 0x8b, 0x50, 0x06, 0xff, 0x90, 0x56, 0x0c, 0xff, 0xfa, 0xb9, 0x31, 0xff, 0xff, 0xbe, 0x31, 0xff, 0xfe, 0xb9, 0x28, 0xff, 0xfd, 0xb4, 0x1d, 0xff, 0xfa, 0xac, 0x13, 0xff, 0xf1, 0xa2, 0x0f, 0xff, 0xe5, 0x90, 0x0a, 0xff, 0xd5, 0x78, 0x04, 0xff, 0xc4, 0x6a, 0x10, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb4, 0x78, 0x36, 0x0b, 0xcd, 0x6f, 0x05, 0xee, 0xdc, 0x85, 0x07, 0xff, 0xea, 0x99, 0x0e, 0xff, 0xf4, 0xa6, 0x12, 0xff, 0xfb, 0xae, 0x15, 0xff, 0xfe, 0xb5, 0x1f, 0xff, 0xfe, 0xb8, 0x29, 0xff, 0xa4, 0x65, 0x12, 0xff, 0x8c, 0x51, 0x05, 0xff, 0xa3, 0x64, 0x07, 0xff, 0xa5, 0x66, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa5, 0x66, 0x07, 0xff, 0xa1, 0x63, 0x07, 0xff, 0x85, 0x4b, 0x05, 0xff, 0xba, 0x79, 0x18, 0xff, 0xfe, 0xb9, 0x2a, 0xff, 0xfe, 0xb5, 0x1f, 0xff, 0xfc, 0xaf, 0x16, 0xff, 0xf5, 0xa7, 0x12, 0xff, 0xea, 0x9a, 0x0e, 0xff, 0xdd, 0x86, 0x08, 0xff, 0xce, 0x6f, 0x05, 0xf3, 0xb5, 0x75, 0x2f, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0x6a, 0x0b, 0x8e, 0xd4, 0x79, 0x05, 0xff, 0xe1, 0x8e, 0x0b, 0xff, 0xee, 0x9f, 0x10, 0xff, 0xf7, 0xa9, 0x14, 0xff, 0xfc, 0xb0, 0x16, 0xff, 0xe7, 0x9d, 0x19, 0xff, 0x7f, 0x45, 0x05, 0xff, 0x9f, 0x61, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0x9c, 0x5f, 0x07, 0xff, 0x83, 0x48, 0x06, 0xff, 0xf5, 0xa9, 0x1c, 0xff, 0xfd, 0xb0, 0x17, 0xff, 0xf7, 0xa9, 0x14, 0xff, 0xee, 0x9f, 0x11, 0xff, 0xe3, 0x90, 0x0c, 0xff, 0xd5, 0x7b, 0x06, 0xff, 0xc8, 0x6b, 0x0a, 0x98, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xba, 0x6f, 0x20, 0x1c, 0xcd, 0x6e, 0x04, 0xf5, 0xd8, 0x82, 0x08, 0xff, 0xe5, 0x94, 0x0d, 0xff, 0xf0, 0xa2, 0x12, 0xff, 0xf7, 0xaa, 0x15, 0xff, 0xb6, 0x71, 0x0c, 0xff, 0x91, 0x55, 0x06, 0xff, 0xa5, 0x66, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa5, 0x66, 0x07, 0xff, 0xa5, 0x66, 0x07, 0xff, 0xa5, 0x66, 0x07, 0xff, 0xa5, 0x66, 0x07, 0xff, 0xa5, 0x66, 0x07, 0xff, 0xa5, 0x66, 0x07, 0xff, 0xa5, 0x66, 0x07, 0xff, 0xa5, 0x66, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa6, 0x67, 0x07, 0xff, 0xa4, 0x65, 0x07, 0xff, 0x8b, 0x50, 0x05, 0xff, 0xca, 0x82, 0x0e, 0xff, 0xf8, 0xaa, 0x15, 0xff, 0xf1, 0xa2, 0x13, 0xff, 0xe6, 0x96, 0x0e, 0xff, 0xd9, 0x83, 0x08, 0xff, 0xce, 0x6f, 0x04, 0xf8, 0xbe, 0x6e, 0x1d, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x69, 0x0c, 0x80, 0xd1, 0x75, 0x04, 0xff, 0xdb, 0x88, 0x0a, 0xff, 0xe7, 0x98, 0x10, 0xff, 0xf0, 0xa2, 0x13, 0xff, 0x9c, 0x5c, 0x08, 0xff, 0x9c, 0x5e, 0x06, 0xff, 0xa5, 0x66, 0x07, 0xff, 0xa3, 0x64, 0x07, 0xff, 0xa1, 0x63, 0x06, 0xff, 0x9e, 0x60, 0x06, 0xff, 0x9a, 0x5b, 0x05, 0xff, 0x99, 0x5c, 0x06, 0xff, 0x9a, 0x5d, 0x07, 0xff, 0x99, 0x5d, 0x08, 0xff, 0x9c, 0x60, 0x0a, 0xff, 0x9b, 0x5f, 0x09, 0xff, 0x99, 0x5d, 0x07, 0xff, 0x9a, 0x5d, 0x07, 0xff, 0x99, 0x5c, 0x06, 0xff, 0x9b, 0x5c, 0x05, 0xff, 0x9e, 0x60, 0x06, 0xff, 0xa1, 0x63, 0x06, 0xff, 0xa4, 0x65, 0x07, 0xff, 0xa5, 0x66, 0x07, 0xff, 0x98, 0x5b, 0x06, 0xff, 0xad, 0x69, 0x0b, 0xff, 0xf1, 0xa3, 0x14, 0xff, 0xe8, 0x99, 0x10, 0xff, 0xdc, 0x89, 0x0b, 0xff, 0xd2, 0x76, 0x05, 0xff, 0xc8, 0x6a, 0x0b, 0x8a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcf, 0x83, 0x1c, 0x08, 0xc9, 0x6b, 0x06, 0xd0, 0xd4, 0x7a, 0x06, 0xff, 0xdd, 0x8b, 0x0b, 0xff, 0xea, 0x9a, 0x11, 0xff, 0x93, 0x55, 0x07, 0xff, 0x94, 0x58, 0x06, 0xff, 0xa5, 0x6b, 0x0e, 0xff, 0xb9, 0x82, 0x18, 0xff, 0xca, 0x95, 0x1e, 0xff, 0xdb, 0xa6, 0x26, 0xff, 0xea, 0xb5, 0x2e, 0xff, 0xf4, 0xc0, 0x34, 0xff, 0xf9, 0xc4, 0x37, 0xff, 0xfa, 0xc7, 0x39, 0xff, 0xfc, 0xc7, 0x3a, 0xff, 0xfb, 0xc7, 0x3a, 0xff, 0xf9, 0xc6, 0x39, 0xff, 0xf8, 0xc3, 0x38, 0xff, 0xf3, 0xbf, 0x34, 0xff, 0xe9, 0xb5, 0x2e, 0xff, 0xd9, 0xa4, 0x26, 0xff, 0xc8, 0x92, 0x1e, 0xff, 0xb5, 0x7e, 0x17, 0xff, 0xa2, 0x68, 0x0d, 0xff, 0x91, 0x55, 0x05, 0xff, 0xa6, 0x64, 0x0a, 0xff, 0xe9, 0x9a, 0x11, 0xff, 0xde, 0x8c, 0x0c, 0xff, 0xd5, 0x7c, 0x06, 0xff, 0xcb, 0x6b, 0x06, 0xd7, 0xc7, 0x7b, 0x1e, 0x0b, 0xff, 0xa0, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xa0, 0x00, 0x01, 0xc6, 0x6f, 0x12, 0x27, 0xcc, 0x6d, 0x04, 0xee, 0xd5, 0x7d, 0x07, 0xff, 0xdf, 0x8c, 0x0c, 0xff, 0xdc, 0x94, 0x19, 0xff, 0xea, 0xa6, 0x21, 0xff, 0xf7, 0xaf, 0x1f, 0xff, 0xf9, 0xac, 0x19, 0xff, 0xfc, 0xac, 0x18, 0xff, 0xfe, 0xae, 0x18, 0xff, 0xff, 0xb0, 0x1a, 0xff, 0xfe, 0xb2, 0x1e, 0xff, 0xff, 0xb4, 0x21, 0xff, 0xff, 0xb4, 0x22, 0xff, 0xfe, 0xb4, 0x22, 0xff, 0xff, 0xb4, 0x22, 0xff, 0xff, 0xb4, 0x22, 0xff, 0xff, 0xb4, 0x21, 0xff, 0xff, 0xb2, 0x1e, 0xff, 0xfe, 0xb0, 0x1a, 0xff, 0xfe, 0xae, 0x18, 0xff, 0xfb, 0xad, 0x18, 0xff, 0xf9, 0xae, 0x1a, 0xff, 0xf8, 0xb0, 0x20, 0xff, 0xe7, 0xa5, 0x21, 0xff, 0xde, 0x95, 0x18, 0xff, 0xdf, 0x8d, 0x0d, 0xff, 0xd6, 0x7e, 0x07, 0xff, 0xcd, 0x6d, 0x05, 0xf2, 0xc6, 0x6e, 0x11, 0x2e, 0xff, 0xa0, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xa0, 0x00, 0x01, 0xff, 0xa0, 0x00, 0x02, 0xc4, 0x6c, 0x0f, 0x3f, 0xcc, 0x6e, 0x05, 0xf5, 0xd6, 0x7d, 0x07, 0xff, 0xdd, 0x8a, 0x0b, 0xff, 0xe5, 0x95, 0x10, 0xff, 0xec, 0x9d, 0x12, 0xff, 0xf2, 0xa2, 0x14, 0xff, 0xf7, 0xa6, 0x16, 0xff, 0xfa, 0xa9, 0x16, 0xff, 0xfb, 0xab, 0x17, 0xff, 0xfd, 0xac, 0x16, 0xff, 0xfe, 0xad, 0x17, 0xff, 0xfe, 0xad, 0x18, 0xff, 0xfe, 0xae, 0x18, 0xff, 0xfe, 0xae, 0x19, 0xff, 0xfe, 0xad, 0x18, 0xff, 0xfe, 0xad, 0x17, 0xff, 0xfd, 0xac, 0x16, 0xff, 0xfc, 0xab, 0x17, 0xff, 0xfa, 0xa9, 0x16, 0xff, 0xf7, 0xa6, 0x15, 0xff, 0xf3, 0xa3, 0x14, 0xff, 0xed, 0x9e, 0x13, 0xff, 0xe6, 0x95, 0x10, 0xff, 0xde, 0x8b, 0x0c, 0xff, 0xd7, 0x7e, 0x07, 0xff, 0xce, 0x6f, 0x04, 0xf8, 0xc6, 0x6b, 0x0d, 0x47, 0xff, 0xa0, 0x00, 0x02, 0xff, 0xa0, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xa0, 0x00, 0x01, 0xff, 0xa0, 0x00, 0x02, 0xc4, 0x6b, 0x0f, 0x40, 0xcc, 0x6d, 0x04, 0xee, 0xd5, 0x7b, 0x06, 0xff, 0xdd, 0x87, 0x0a, 0xff, 0xe3, 0x91, 0x0e, 0xff, 0xe9, 0x99, 0x11, 0xff, 0xee, 0x9e, 0x12, 0xff, 0xf3, 0xa2, 0x14, 0xff, 0xf6, 0xa4, 0x15, 0xff, 0xf8, 0xa6, 0x16, 0xff, 0xf9, 0xa8, 0x16, 0xff, 0xfa, 0xa8, 0x16, 0xff, 0xfa, 0xa9, 0x16, 0xff, 0xfa, 0xa9, 0x16, 0xff, 0xfa, 0xa8, 0x16, 0xff, 0xf9, 0xa8, 0x16, 0xff, 0xf8, 0xa7, 0x16, 0xff, 0xf6, 0xa5, 0x15, 0xff, 0xf3, 0xa2, 0x14, 0xff, 0xef, 0x9e, 0x13, 0xff, 0xea, 0x99, 0x11, 0xff, 0xe4, 0x91, 0x0e, 0xff, 0xdd, 0x88, 0x0a, 0xff, 0xd6, 0x7c, 0x06, 0xff, 0xcc, 0x6d, 0x05, 0xf1, 0xc6, 0x6c, 0x0c, 0x47, 0xff, 0xa0, 0x00, 0x03, 0xff, 0xa0, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xa0, 0x00, 0x01, 0xff, 0xa0, 0x00, 0x03, 0xc5, 0x6f, 0x11, 0x28, 0xc7, 0x6a, 0x06, 0xd1, 0xd3, 0x75, 0x04, 0xff, 0xda, 0x81, 0x08, 0xff, 0xe0, 0x8b, 0x0b, 0xff, 0xe5, 0x92, 0x0e, 0xff, 0xe9, 0x98, 0x10, 0xff, 0xed, 0x9c, 0x12, 0xff, 0xf0, 0x9e, 0x13, 0xff, 0xf2, 0xa0, 0x13, 0xff, 0xf3, 0xa1, 0x14, 0xff, 0xf3, 0xa2, 0x14, 0xff, 0xf3, 0xa2, 0x14, 0xff, 0xf3, 0xa2, 0x14, 0xff, 0xf2, 0xa0, 0x14, 0xff, 0xf0, 0x9f, 0x13, 0xff, 0xed, 0x9c, 0x12, 0xff, 0xe9, 0x98, 0x10, 0xff, 0xe5, 0x93, 0x0e, 0xff, 0xe0, 0x8c, 0x0c, 0xff, 0xdb, 0x82, 0x08, 0xff, 0xd3, 0x76, 0x04, 0xff, 0xc8, 0x6b, 0x06, 0xd6, 0xc5, 0x6e, 0x10, 0x2e, 0xff, 0xa0, 0x00, 0x03, 0xff, 0xa0, 0x00, 0x01, 0xff, 0xa0, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xa0, 0x00, 0x01, 0xff, 0xa0, 0x00, 0x03, 0xda, 0x88, 0x14, 0x0b, 0xc3, 0x68, 0x09, 0x82, 0xca, 0x6c, 0x04, 0xf5, 0xd5, 0x78, 0x05, 0xff, 0xda, 0x82, 0x08, 0xff, 0xdf, 0x89, 0x0a, 0xff, 0xe3, 0x8e, 0x0c, 0xff, 0xe6, 0x92, 0x0d, 0xff, 0xe8, 0x95, 0x0e, 0xff, 0xe9, 0x97, 0x0f, 0xff, 0xea, 0x98, 0x0f, 0xff, 0xea, 0x98, 0x0f, 0xff, 0xe9, 0x97, 0x10, 0xff, 0xe8, 0x95, 0x0f, 0xff, 0xe6, 0x93, 0x0d, 0xff, 0xe3, 0x8f, 0x0c, 0xff, 0xe0, 0x89, 0x0b, 0xff, 0xdb, 0x82, 0x08, 0xff, 0xd5, 0x79, 0x05, 0xff, 0xcb, 0x6d, 0x05, 0xf7, 0xc4, 0x69, 0x0a, 0x88, 0xd8, 0x86, 0x12, 0x0d, 0xff, 0xa0, 0x00, 0x03, 0xff, 0xa0, 0x00, 0x01, 0xff, 0xa0, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xa0, 0x00, 0x01, 0xff, 0xa0, 0x00, 0x02, 0xff, 0xa0, 0x00, 0x03, 0xc8, 0x75, 0x12, 0x20, 0xc3, 0x67, 0x08, 0x91, 0xc7, 0x6b, 0x05, 0xf0, 0xd0, 0x73, 0x04, 0xff, 0xd6, 0x7b, 0x06, 0xff, 0xda, 0x80, 0x08, 0xff, 0xdd, 0x84, 0x09, 0xff, 0xde, 0x87, 0x09, 0xff, 0xdf, 0x88, 0x0a, 0xff, 0xdf, 0x88, 0x0a, 0xff, 0xde, 0x87, 0x09, 0xff, 0xdd, 0x84, 0x09, 0xff, 0xda, 0x80, 0x08, 0xff, 0xd7, 0x7c, 0x06, 0xff, 0xd1, 0x74, 0x04, 0xff, 0xc8, 0x6b, 0x05, 0xf2, 0xc3, 0x68, 0x08, 0x96, 0xc5, 0x72, 0x13, 0x23, 0xff, 0xa1, 0x01, 0x04, 0xff, 0xa0, 0x00, 0x02, 0xff, 0xa0, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xa0, 0x00, 0x01, 0xff, 0xa0, 0x00, 0x02, 0xff, 0xa0, 0x00, 0x02, 0xff, 0xa0, 0x00, 0x03, 0xd8, 0x87, 0x14, 0x0f, 0xbd, 0x68, 0x0d, 0x57, 0xc1, 0x67, 0x08, 0x9f, 0xc5, 0x6a, 0x06, 0xd9, 0xc6, 0x6b, 0x05, 0xf8, 0xc9, 0x6c, 0x04, 0xff, 0xcb, 0x6e, 0x03, 0xff, 0xcb, 0x6e, 0x03, 0xff, 0xc9, 0x6c, 0x03, 0xff, 0xc7, 0x6b, 0x05, 0xf9, 0xc5, 0x6a, 0x06, 0xdb, 0xc1, 0x67, 0x07, 0xa2, 0xbe, 0x67, 0x0c, 0x5a, 0xd6, 0x85, 0x13, 0x10, 0xff, 0xa0, 0x00, 0x03, 0xff, 0xa0, 0x00, 0x03, 0xff, 0xa0, 0x00, 0x01, 0xff, 0xa0, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xa0, 0x00, 0x01, 0xff, 0xa0, 0x00, 0x01, 0xff, 0xa0, 0x00, 0x02, 0xff, 0xa0, 0x00, 0x03, 0xff, 0xa0, 0x00, 0x03, 0xfe, 0xa0, 0x02, 0x03, 0xe1, 0x90, 0x12, 0x0f, 0xc6, 0x7a, 0x18, 0x23, 0xbf, 0x70, 0x15, 0x30, 0xbf, 0x70, 0x16, 0x31, 0xc5, 0x79, 0x19, 0x24, 0xe0, 0x90, 0x12, 0x10, 0xfe, 0xa0, 0x02, 0x03, 0xff, 0xa0, 0x00, 0x04, 0xff, 0xa0, 0x00, 0x03, 0xff, 0xa0, 0x00, 0x02, 0xff, 0xa0, 0x00, 0x01, 0xff, 0xa0, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xff, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xa0, 0x00, 0x01, 0xff, 0xa0, 0x00, 0x01, 0xff, 0xa0, 0x00, 0x02, 0xff, 0xa0, 0x00, 0x02, 0xff, 0xa0, 0x00, 0x03, 0xff, 0xa0, 0x00, 0x03, 0xff, 0xa0, 0x00, 0x03, 0xff, 0xa0, 0x00, 0x03, 0xff, 0xa0, 0x00, 0x02, 0xff, 0xa0, 0x00, 0x02, 0xff, 0xa0, 0x00, 0x01, 0xff, 0xa0, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
|
the_stack_data/83299.c | #include <sqlite3ext.h>
SQLITE_EXTENSION_INIT1
int setup_functiontable(sqlite3 *db);
int sqlite3_luafunctions_init(sqlite3 *db, char **pzErrMsg,
sqlite3_api_routines *pApi)
{
SQLITE_EXTENSION_INIT2(pApi);
int rc = SQLITE_OK;
setup_functiontable(db);
return rc;
}
|
the_stack_data/48573977.c | #include <stdint.h>
extern int main(void);
// Following symbols are defined by the linker.
// Start address for the initialization values of the .data section.
extern uint32_t _sidata;
// Start address for the .data section
extern uint32_t _sdata;
// End address for the .data section
extern uint32_t _edata;
// Start address for the .bss section
extern uint32_t _sbss;
// End address for the .bss section
extern uint32_t _ebss;
// End address for stack
extern uint32_t _estack;
// Prevent inlining to avoid persisting any variables on stack
__attribute__((noinline)) static void prv_cinit(void) {
// Initialize data and bss
// Copy the data segment initializers from flash to SRAM
for (uint32_t *dst = &_sdata, *src = &_sidata; dst < &_edata;) {
*(dst++) = *(src++);
}
// Zero fill the bss segment.
for (uint32_t *dst = &_sbss; dst < &_ebss;) {
*(dst++) = 0;
}
}
void Reset_Handler(void) {
prv_cinit();
// Call the application's entry point.
main();
// should be unreachable
while (1) { }
}
// DefaultIntHandler is used for unpopulated interrupts
static void DefaultIntHandler(void) {
__asm__("bkpt");
// Go into an infinite loop.
while (1)
;
}
static void NMI_Handler(void) {
DefaultIntHandler();
}
static void HardFault_Handler(void) {
DefaultIntHandler();
}
void ExternalInt0_Handler(void);
void SVC_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);
#define EXTERNAL_INT_BASE 16 // NVIC Interrupt 0 starts here
// A minimal vector table for a Cortex M.
__attribute__((section(".isr_vector"))) void (*const g_pfnVectors[])(void) = {
[0] = (void *)(&_estack), // initial stack pointer
[1] = Reset_Handler,
[2] = NMI_Handler,
[3] = HardFault_Handler,
[4] = DefaultIntHandler,
[5] = DefaultIntHandler,
[6] = DefaultIntHandler,
[7] = 0,
[8] = 0,
[9] = 0,
[10] = 0,
[11] = SVC_Handler,
[12] = 0,
[13] = 0,
[14] = PendSV_Handler,
[15] = SysTick_Handler,
// NVIC Interrupts
[EXTERNAL_INT_BASE + 0] = ExternalInt0_Handler,
};
|
the_stack_data/115765531.c | /*
Palindromo - Ricorsione:
Scrivere una funzione ricorsiva che ritorni true se la stringa di caratteri è
palindroma e false in caso non lo sia. La funzione deve ingnorare gli spazi
e la punteggiatura.
*/
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
bool isPalindrome(char *stringa, int dimensione);
bool control(char *stringa);
int main(void)
{
char stringa[] = "iààoi";
int dimensione = strlen(stringa);
printf( control(stringa) ? "PALINDROMA" : "NON PALINDROMA" );
puts("");
return 0;
}
bool control(char *stringa)
{
char *str = (char *) calloc (strlen(stringa), sizeof(char));
int c2 = 0;
int cnt = 0;
for(cnt = 0; cnt < strlen(stringa); cnt++)
{
if(stringa[cnt] >= 'a' && stringa[cnt] <= 'z')
{
str[c2] = stringa[cnt];
c2++;
}
}
str[c2] = '\0';
str = (char *) realloc(str, c2 + 1);
printf("\nPRIMA : %s\n", stringa);
printf("DOPO : %s\n", str);
return isPalindrome(str, c2);
}
bool isPalindrome(char *stringa, int dimensione)
{
if(dimensione < 2 )
{
return true;
}
if(stringa[0] == stringa[dimensione - 1]){
isPalindrome(stringa + 1, dimensione - 2);
}
else
{
return false;
}
} |
the_stack_data/122016113.c | /* example.c -- usage example of the zlib compression library
* Copyright (C) 1995-2004 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* @(#) $Id: example.c,v 1.2 2006-02-06 22:01:28 marcus Exp $ */
#include <stdio.h>
#include "zlib.h"
#ifdef STDC
# include <string.h>
# include <stdlib.h>
#endif
#if defined(VMS) || defined(RISCOS)
# define TESTFILE "foo-gz"
#else
# define TESTFILE "foo.gz"
#endif
#define CHECK_ERR(err, msg) { \
if (err != Z_OK) { \
fprintf(stderr, "%s error: %d\n", msg, err); \
exit(1); \
} \
}
const char hello[] = "hello, hello!";
/* "hello world" would be more standard, but the repeated "hello"
* stresses the compression code better, sorry...
*/
const char dictionary[] = "hello";
uLong dictId; /* Adler32 value of the dictionary */
void test_compress OF((Byte *compr, uLong comprLen,
Byte *uncompr, uLong uncomprLen));
void test_gzio OF((const char *fname,
Byte *uncompr, uLong uncomprLen));
void test_deflate OF((Byte *compr, uLong comprLen));
void test_inflate OF((Byte *compr, uLong comprLen,
Byte *uncompr, uLong uncomprLen));
void test_large_deflate OF((Byte *compr, uLong comprLen,
Byte *uncompr, uLong uncomprLen));
void test_large_inflate OF((Byte *compr, uLong comprLen,
Byte *uncompr, uLong uncomprLen));
void test_flush OF((Byte *compr, uLong *comprLen));
void test_sync OF((Byte *compr, uLong comprLen,
Byte *uncompr, uLong uncomprLen));
void test_dict_deflate OF((Byte *compr, uLong comprLen));
void test_dict_inflate OF((Byte *compr, uLong comprLen,
Byte *uncompr, uLong uncomprLen));
int main OF((int argc, char *argv[]));
/* ===========================================================================
* Test compress() and uncompress()
*/
void test_compress(compr, comprLen, uncompr, uncomprLen)
Byte *compr, *uncompr;
uLong comprLen, uncomprLen;
{
int err;
uLong len = (uLong)strlen(hello)+1;
err = compress(compr, &comprLen, (const Bytef*)hello, len);
CHECK_ERR(err, "compress");
strcpy((char*)uncompr, "garbage");
err = uncompress(uncompr, &uncomprLen, compr, comprLen);
CHECK_ERR(err, "uncompress");
if (strcmp((char*)uncompr, hello)) {
fprintf(stderr, "bad uncompress\n");
exit(1);
} else {
printf("uncompress(): %s\n", (char *)uncompr);
}
}
/* ===========================================================================
* Test read/write of .gz files
*/
void test_gzio(fname, uncompr, uncomprLen)
const char *fname; /* compressed file name */
Byte *uncompr;
uLong uncomprLen;
{
#ifdef NO_GZCOMPRESS
fprintf(stderr, "NO_GZCOMPRESS -- gz* functions cannot compress\n");
#else
int err;
int len = (int)strlen(hello)+1;
gzFile file;
z_off_t pos;
file = gzopen(fname, "wb");
if (file == NULL) {
fprintf(stderr, "gzopen error\n");
exit(1);
}
gzputc(file, 'h');
if (gzputs(file, "ello") != 4) {
fprintf(stderr, "gzputs err: %s\n", gzerror(file, &err));
exit(1);
}
if (gzprintf(file, ", %s!", "hello") != 8) {
fprintf(stderr, "gzprintf err: %s\n", gzerror(file, &err));
exit(1);
}
gzseek(file, 1L, SEEK_CUR); /* add one zero byte */
gzclose(file);
file = gzopen(fname, "rb");
if (file == NULL) {
fprintf(stderr, "gzopen error\n");
exit(1);
}
strcpy((char*)uncompr, "garbage");
if (gzread(file, uncompr, (unsigned)uncomprLen) != len) {
fprintf(stderr, "gzread err: %s\n", gzerror(file, &err));
exit(1);
}
if (strcmp((char*)uncompr, hello)) {
fprintf(stderr, "bad gzread: %s\n", (char*)uncompr);
exit(1);
} else {
printf("gzread(): %s\n", (char*)uncompr);
}
pos = gzseek(file, -8L, SEEK_CUR);
if (pos != 6 || gztell(file) != pos) {
fprintf(stderr, "gzseek error, pos=%ld, gztell=%ld\n",
(long)pos, (long)gztell(file));
exit(1);
}
if (gzgetc(file) != ' ') {
fprintf(stderr, "gzgetc error\n");
exit(1);
}
if (gzungetc(' ', file) != ' ') {
fprintf(stderr, "gzungetc error\n");
exit(1);
}
gzgets(file, (char*)uncompr, (int)uncomprLen);
if (strlen((char*)uncompr) != 7) { /* " hello!" */
fprintf(stderr, "gzgets err after gzseek: %s\n", gzerror(file, &err));
exit(1);
}
if (strcmp((char*)uncompr, hello + 6)) {
fprintf(stderr, "bad gzgets after gzseek\n");
exit(1);
} else {
printf("gzgets() after gzseek: %s\n", (char*)uncompr);
}
gzclose(file);
#endif
}
/* ===========================================================================
* Test deflate() with small buffers
*/
void test_deflate(compr, comprLen)
Byte *compr;
uLong comprLen;
{
z_stream c_stream; /* compression stream */
int err;
uLong len = (uLong)strlen(hello)+1;
c_stream.zalloc = (alloc_func)0;
c_stream.zfree = (free_func)0;
c_stream.opaque = (voidpf)0;
err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
CHECK_ERR(err, "deflateInit");
c_stream.next_in = (Bytef*)hello;
c_stream.next_out = compr;
while (c_stream.total_in != len && c_stream.total_out < comprLen) {
c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
err = deflate(&c_stream, Z_NO_FLUSH);
CHECK_ERR(err, "deflate");
}
/* Finish the stream, still forcing small buffers: */
for (;;) {
c_stream.avail_out = 1;
err = deflate(&c_stream, Z_FINISH);
if (err == Z_STREAM_END) break;
CHECK_ERR(err, "deflate");
}
err = deflateEnd(&c_stream);
CHECK_ERR(err, "deflateEnd");
}
/* ===========================================================================
* Test inflate() with small buffers
*/
void test_inflate(compr, comprLen, uncompr, uncomprLen)
Byte *compr, *uncompr;
uLong comprLen, uncomprLen;
{
int err;
z_stream d_stream; /* decompression stream */
strcpy((char*)uncompr, "garbage");
d_stream.zalloc = (alloc_func)0;
d_stream.zfree = (free_func)0;
d_stream.opaque = (voidpf)0;
d_stream.next_in = compr;
d_stream.avail_in = 0;
d_stream.next_out = uncompr;
err = inflateInit(&d_stream);
CHECK_ERR(err, "inflateInit");
while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen) {
d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */
err = inflate(&d_stream, Z_NO_FLUSH);
if (err == Z_STREAM_END) break;
CHECK_ERR(err, "inflate");
}
err = inflateEnd(&d_stream);
CHECK_ERR(err, "inflateEnd");
if (strcmp((char*)uncompr, hello)) {
fprintf(stderr, "bad inflate\n");
exit(1);
} else {
printf("inflate(): %s\n", (char *)uncompr);
}
}
/* ===========================================================================
* Test deflate() with large buffers and dynamic change of compression level
*/
void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
Byte *compr, *uncompr;
uLong comprLen, uncomprLen;
{
z_stream c_stream; /* compression stream */
int err;
c_stream.zalloc = (alloc_func)0;
c_stream.zfree = (free_func)0;
c_stream.opaque = (voidpf)0;
err = deflateInit(&c_stream, Z_BEST_SPEED);
CHECK_ERR(err, "deflateInit");
c_stream.next_out = compr;
c_stream.avail_out = (uInt)comprLen;
/* At this point, uncompr is still mostly zeroes, so it should compress
* very well:
*/
c_stream.next_in = uncompr;
c_stream.avail_in = (uInt)uncomprLen;
err = deflate(&c_stream, Z_NO_FLUSH);
CHECK_ERR(err, "deflate");
if (c_stream.avail_in != 0) {
fprintf(stderr, "deflate not greedy\n");
exit(1);
}
/* Feed in already compressed data and switch to no compression: */
deflateParams(&c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY);
c_stream.next_in = compr;
c_stream.avail_in = (uInt)comprLen/2;
err = deflate(&c_stream, Z_NO_FLUSH);
CHECK_ERR(err, "deflate");
/* Switch back to compressing mode: */
deflateParams(&c_stream, Z_BEST_COMPRESSION, Z_FILTERED);
c_stream.next_in = uncompr;
c_stream.avail_in = (uInt)uncomprLen;
err = deflate(&c_stream, Z_NO_FLUSH);
CHECK_ERR(err, "deflate");
err = deflate(&c_stream, Z_FINISH);
if (err != Z_STREAM_END) {
fprintf(stderr, "deflate should report Z_STREAM_END\n");
exit(1);
}
err = deflateEnd(&c_stream);
CHECK_ERR(err, "deflateEnd");
}
/* ===========================================================================
* Test inflate() with large buffers
*/
void test_large_inflate(compr, comprLen, uncompr, uncomprLen)
Byte *compr, *uncompr;
uLong comprLen, uncomprLen;
{
int err;
z_stream d_stream; /* decompression stream */
strcpy((char*)uncompr, "garbage");
d_stream.zalloc = (alloc_func)0;
d_stream.zfree = (free_func)0;
d_stream.opaque = (voidpf)0;
d_stream.next_in = compr;
d_stream.avail_in = (uInt)comprLen;
err = inflateInit(&d_stream);
CHECK_ERR(err, "inflateInit");
for (;;) {
d_stream.next_out = uncompr; /* discard the output */
d_stream.avail_out = (uInt)uncomprLen;
err = inflate(&d_stream, Z_NO_FLUSH);
if (err == Z_STREAM_END) break;
CHECK_ERR(err, "large inflate");
}
err = inflateEnd(&d_stream);
CHECK_ERR(err, "inflateEnd");
if (d_stream.total_out != 2*uncomprLen + comprLen/2) {
fprintf(stderr, "bad large inflate: %ld\n", d_stream.total_out);
exit(1);
} else {
printf("large_inflate(): OK\n");
}
}
/* ===========================================================================
* Test deflate() with full flush
*/
void test_flush(compr, comprLen)
Byte *compr;
uLong *comprLen;
{
z_stream c_stream; /* compression stream */
int err;
uInt len = (uInt)strlen(hello)+1;
c_stream.zalloc = (alloc_func)0;
c_stream.zfree = (free_func)0;
c_stream.opaque = (voidpf)0;
err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
CHECK_ERR(err, "deflateInit");
c_stream.next_in = (Bytef*)hello;
c_stream.next_out = compr;
c_stream.avail_in = 3;
c_stream.avail_out = (uInt)*comprLen;
err = deflate(&c_stream, Z_FULL_FLUSH);
CHECK_ERR(err, "deflate");
compr[3]++; /* force an error in first compressed block */
c_stream.avail_in = len - 3;
err = deflate(&c_stream, Z_FINISH);
if (err != Z_STREAM_END) {
CHECK_ERR(err, "deflate");
}
err = deflateEnd(&c_stream);
CHECK_ERR(err, "deflateEnd");
*comprLen = c_stream.total_out;
}
/* ===========================================================================
* Test inflateSync()
*/
void test_sync(compr, comprLen, uncompr, uncomprLen)
Byte *compr, *uncompr;
uLong comprLen, uncomprLen;
{
int err;
z_stream d_stream; /* decompression stream */
strcpy((char*)uncompr, "garbage");
d_stream.zalloc = (alloc_func)0;
d_stream.zfree = (free_func)0;
d_stream.opaque = (voidpf)0;
d_stream.next_in = compr;
d_stream.avail_in = 2; /* just read the zlib header */
err = inflateInit(&d_stream);
CHECK_ERR(err, "inflateInit");
d_stream.next_out = uncompr;
d_stream.avail_out = (uInt)uncomprLen;
inflate(&d_stream, Z_NO_FLUSH);
CHECK_ERR(err, "inflate");
d_stream.avail_in = (uInt)comprLen-2; /* read all compressed data */
err = inflateSync(&d_stream); /* but skip the damaged part */
CHECK_ERR(err, "inflateSync");
err = inflate(&d_stream, Z_FINISH);
if (err != Z_DATA_ERROR) {
fprintf(stderr, "inflate should report DATA_ERROR\n");
/* Because of incorrect adler32 */
exit(1);
}
err = inflateEnd(&d_stream);
CHECK_ERR(err, "inflateEnd");
printf("after inflateSync(): hel%s\n", (char *)uncompr);
}
/* ===========================================================================
* Test deflate() with preset dictionary
*/
void test_dict_deflate(compr, comprLen)
Byte *compr;
uLong comprLen;
{
z_stream c_stream; /* compression stream */
int err;
c_stream.zalloc = (alloc_func)0;
c_stream.zfree = (free_func)0;
c_stream.opaque = (voidpf)0;
err = deflateInit(&c_stream, Z_BEST_COMPRESSION);
CHECK_ERR(err, "deflateInit");
err = deflateSetDictionary(&c_stream,
(const Bytef*)dictionary, sizeof(dictionary));
CHECK_ERR(err, "deflateSetDictionary");
dictId = c_stream.adler;
c_stream.next_out = compr;
c_stream.avail_out = (uInt)comprLen;
c_stream.next_in = (Bytef*)hello;
c_stream.avail_in = (uInt)strlen(hello)+1;
err = deflate(&c_stream, Z_FINISH);
if (err != Z_STREAM_END) {
fprintf(stderr, "deflate should report Z_STREAM_END\n");
exit(1);
}
err = deflateEnd(&c_stream);
CHECK_ERR(err, "deflateEnd");
}
/* ===========================================================================
* Test inflate() with a preset dictionary
*/
void test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
Byte *compr, *uncompr;
uLong comprLen, uncomprLen;
{
int err;
z_stream d_stream; /* decompression stream */
strcpy((char*)uncompr, "garbage");
d_stream.zalloc = (alloc_func)0;
d_stream.zfree = (free_func)0;
d_stream.opaque = (voidpf)0;
d_stream.next_in = compr;
d_stream.avail_in = (uInt)comprLen;
err = inflateInit(&d_stream);
CHECK_ERR(err, "inflateInit");
d_stream.next_out = uncompr;
d_stream.avail_out = (uInt)uncomprLen;
for (;;) {
err = inflate(&d_stream, Z_NO_FLUSH);
if (err == Z_STREAM_END) break;
if (err == Z_NEED_DICT) {
if (d_stream.adler != dictId) {
fprintf(stderr, "unexpected dictionary");
exit(1);
}
err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary,
sizeof(dictionary));
}
CHECK_ERR(err, "inflate with dict");
}
err = inflateEnd(&d_stream);
CHECK_ERR(err, "inflateEnd");
if (strcmp((char*)uncompr, hello)) {
fprintf(stderr, "bad inflate with dict\n");
exit(1);
} else {
printf("inflate with dictionary: %s\n", (char *)uncompr);
}
}
/* ===========================================================================
* Usage: example [output.gz [input.gz]]
*/
int main(argc, argv)
int argc;
char *argv[];
{
Byte *compr, *uncompr;
uLong comprLen = 10000*sizeof(int); /* don't overflow on MSDOS */
uLong uncomprLen = comprLen;
static const char* myVersion = ZLIB_VERSION;
if (zlibVersion()[0] != myVersion[0]) {
fprintf(stderr, "incompatible zlib version\n");
exit(1);
} else if (strcmp(zlibVersion(), ZLIB_VERSION) != 0) {
fprintf(stderr, "warning: different zlib version\n");
}
printf("zlib version %s = 0x%04x, compile flags = 0x%lx\n",
ZLIB_VERSION, ZLIB_VERNUM, zlibCompileFlags());
compr = (Byte*)calloc((uInt)comprLen, 1);
uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
/* compr and uncompr are cleared to avoid reading uninitialized
* data and to ensure that uncompr compresses well.
*/
if (compr == Z_NULL || uncompr == Z_NULL) {
printf("out of memory\n");
exit(1);
}
test_compress(compr, comprLen, uncompr, uncomprLen);
test_gzio((argc > 1 ? argv[1] : TESTFILE),
uncompr, uncomprLen);
test_deflate(compr, comprLen);
test_inflate(compr, comprLen, uncompr, uncomprLen);
test_large_deflate(compr, comprLen, uncompr, uncomprLen);
test_large_inflate(compr, comprLen, uncompr, uncomprLen);
test_flush(compr, &comprLen);
test_sync(compr, comprLen, uncompr, uncomprLen);
comprLen = uncomprLen;
test_dict_deflate(compr, comprLen);
test_dict_inflate(compr, comprLen, uncompr, uncomprLen);
free(compr);
free(uncompr);
return 0;
}
|
the_stack_data/37638982.c | /* Origin: Franz Sirl <[email protected]> */
/* { dg-options "-fgnu89-inline" } */
extern void abort (void);
extern void exit (int);
#include <stdarg.h>
#include <limits.h>
#if __LONG_LONG_MAX__ == 9223372036854775807LL
typedef long long int INT64;
inline void
debug(int i1, int i2, int i3, int i4, int i5,
int i6, int i7, int i8, int i9, ...)
{
va_list ap;
va_start (ap, i9);
if (va_arg (ap,int) != 10)
abort ();
if (va_arg (ap,INT64) != 0x123400005678LL)
abort ();
va_end (ap);
}
int
main(void)
{
debug(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0x123400005678LL);
exit(0);
}
#else
int
main(void)
{
exit(0);
}
#endif /* long long 64 bits */
|
the_stack_data/51700856.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_div_mod.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dpearson <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/06/29 17:23:25 by dpearson #+# #+# */
/* Updated: 2017/06/29 17:23:28 by dpearson ### ########.fr */
/* */
/* ************************************************************************** */
void ft_div_mod(int a, int b, int *div, int *mod)
{
*div = (a / b);
*mod = (a % b);
}
|
the_stack_data/82111.c | #include <stdio.h>
int main(void) {
int number;
printf("Enter a number: ");
scanf("%d", &number);
switch(number) {
case 1:
printf("One.");
break;
case 2:
printf("Two.");
break;
case 3:
printf("Three.");
break;
case 4:
printf("Four.");
break;
case 5:
printf("Five.");
break;
default:
printf("Oops!");
}
return 0;
} |
the_stack_data/643223.c | /*
* Copyright © 2008 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Soft-
* ware"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, provided that the above copyright
* notice(s) and this permission notice appear in all copies of the Soft-
* ware and that both the above copyright notice(s) and this permission
* notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
* ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY
* RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN
* THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE-
* QUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFOR-
* MANCE OF THIS SOFTWARE.
*
* Except as contained in this notice, the name of a copyright holder shall
* not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization of
* the copyright holder.
*
* Authors:
* Kristian Høgsberg ([email protected])
*/
#ifdef GLX_DIRECT_RENDERING
#include <stdio.h>
#include <X11/Xlibint.h>
#include <X11/extensions/Xext.h>
#include <X11/extensions/extutil.h>
#include <X11/extensions/dri2proto.h>
#include "xf86drm.h"
#include "dri2.h"
#include "glxclient.h"
#include "GL/glxext.h"
/* Allow the build to work with an older versions of dri2proto.h and
* dri2tokens.h.
*/
#if DRI2_MINOR < 1
#undef DRI2_MINOR
#define DRI2_MINOR 1
#define X_DRI2GetBuffersWithFormat 7
#endif
static char dri2ExtensionName[] = DRI2_NAME;
static XExtensionInfo *dri2Info;
static XEXT_GENERATE_CLOSE_DISPLAY (DRI2CloseDisplay, dri2Info)
static Bool
DRI2WireToEvent(Display *dpy, XEvent *event, xEvent *wire);
static Status
DRI2EventToWire(Display *dpy, XEvent *event, xEvent *wire);
static int
DRI2Error(Display *display, xError *err, XExtCodes *codes, int *ret_code);
static /* const */ XExtensionHooks dri2ExtensionHooks = {
NULL, /* create_gc */
NULL, /* copy_gc */
NULL, /* flush_gc */
NULL, /* free_gc */
NULL, /* create_font */
NULL, /* free_font */
DRI2CloseDisplay, /* close_display */
DRI2WireToEvent, /* wire_to_event */
DRI2EventToWire, /* event_to_wire */
DRI2Error, /* error */
NULL, /* error_string */
};
static XEXT_GENERATE_FIND_DISPLAY (DRI2FindDisplay,
dri2Info,
dri2ExtensionName,
&dri2ExtensionHooks,
0, NULL)
static Bool
DRI2WireToEvent(Display *dpy, XEvent *event, xEvent *wire)
{
XExtDisplayInfo *info = DRI2FindDisplay(dpy);
XextCheckExtension(dpy, info, dri2ExtensionName, False);
switch ((wire->u.u.type & 0x7f) - info->codes->first_event) {
#ifdef X_DRI2SwapBuffers
case DRI2_BufferSwapComplete:
{
GLXBufferSwapComplete *aevent = (GLXBufferSwapComplete *)event;
xDRI2BufferSwapComplete *awire = (xDRI2BufferSwapComplete *)wire;
/* Ignore swap events if we're not looking for them */
aevent->type = dri2GetSwapEventType(dpy, awire->drawable);
if(!aevent->type)
return False;
aevent->serial = _XSetLastRequestRead(dpy, (xGenericReply *) wire);
aevent->send_event = (awire->type & 0x80) != 0;
aevent->display = dpy;
aevent->drawable = awire->drawable;
switch (awire->event_type) {
case DRI2_EXCHANGE_COMPLETE:
aevent->event_type = GLX_EXCHANGE_COMPLETE_INTEL;
break;
case DRI2_BLIT_COMPLETE:
aevent->event_type = GLX_COPY_COMPLETE_INTEL;
break;
case DRI2_FLIP_COMPLETE:
aevent->event_type = GLX_FLIP_COMPLETE_INTEL;
break;
default:
/* unknown swap completion type */
return False;
}
aevent->ust = ((CARD64)awire->ust_hi << 32) | awire->ust_lo;
aevent->msc = ((CARD64)awire->msc_hi << 32) | awire->msc_lo;
aevent->sbc = ((CARD64)awire->sbc_hi << 32) | awire->sbc_lo;
return True;
}
#endif
#ifdef DRI2_InvalidateBuffers
case DRI2_InvalidateBuffers:
{
xDRI2InvalidateBuffers *awire = (xDRI2InvalidateBuffers *)wire;
dri2InvalidateBuffers(dpy, awire->drawable);
return False;
}
#endif
default:
/* client doesn't support server event */
break;
}
return False;
}
/* We don't actually support this. It doesn't make sense for clients to
* send each other DRI2 events.
*/
static Status
DRI2EventToWire(Display *dpy, XEvent *event, xEvent *wire)
{
XExtDisplayInfo *info = DRI2FindDisplay(dpy);
XextCheckExtension(dpy, info, dri2ExtensionName, False);
switch (event->type) {
default:
/* client doesn't support server event */
break;
}
return Success;
}
static int
DRI2Error(Display *display, xError *err, XExtCodes *codes, int *ret_code)
{
if (err->majorCode == codes->major_opcode &&
err->errorCode == BadDrawable &&
err->minorCode == X_DRI2CopyRegion)
return True;
/* If the X drawable was destroyed before the GLX drawable, the
* DRI2 drawble will be gone by the time we call
* DRI2DestroyDrawable. So just ignore BadDrawable here. */
if (err->majorCode == codes->major_opcode &&
err->errorCode == BadDrawable &&
err->minorCode == X_DRI2DestroyDrawable)
return True;
/* If the server is non-local DRI2Connect will raise BadRequest.
* Swallow this so that DRI2Connect can signal this in its return code */
if (err->majorCode == codes->major_opcode &&
err->minorCode == X_DRI2Connect &&
err->errorCode == BadRequest) {
*ret_code = False;
return True;
}
return False;
}
Bool
DRI2QueryExtension(Display * dpy, int *eventBase, int *errorBase)
{
XExtDisplayInfo *info = DRI2FindDisplay(dpy);
if (XextHasExtension(info)) {
*eventBase = info->codes->first_event;
*errorBase = info->codes->first_error;
return True;
}
return False;
}
Bool
DRI2QueryVersion(Display * dpy, int *major, int *minor)
{
XExtDisplayInfo *info = DRI2FindDisplay(dpy);
xDRI2QueryVersionReply rep;
xDRI2QueryVersionReq *req;
int i, nevents;
XextCheckExtension(dpy, info, dri2ExtensionName, False);
LockDisplay(dpy);
GetReq(DRI2QueryVersion, req);
req->reqType = info->codes->major_opcode;
req->dri2ReqType = X_DRI2QueryVersion;
req->majorVersion = DRI2_MAJOR;
req->minorVersion = DRI2_MINOR;
if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
UnlockDisplay(dpy);
SyncHandle();
return False;
}
*major = rep.majorVersion;
*minor = rep.minorVersion;
UnlockDisplay(dpy);
SyncHandle();
switch (rep.minorVersion) {
case 1:
nevents = 0;
break;
case 2:
nevents = 1;
break;
case 3:
default:
nevents = 2;
break;
}
for (i = 0; i < nevents; i++) {
XESetWireToEvent (dpy, info->codes->first_event + i, DRI2WireToEvent);
XESetEventToWire (dpy, info->codes->first_event + i, DRI2EventToWire);
}
return True;
}
Bool
DRI2Connect(Display * dpy, XID window, char **driverName, char **deviceName)
{
XExtDisplayInfo *info = DRI2FindDisplay(dpy);
xDRI2ConnectReply rep;
xDRI2ConnectReq *req;
XextCheckExtension(dpy, info, dri2ExtensionName, False);
LockDisplay(dpy);
GetReq(DRI2Connect, req);
req->reqType = info->codes->major_opcode;
req->dri2ReqType = X_DRI2Connect;
req->window = window;
req->driverType = DRI2DriverDRI;
if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
UnlockDisplay(dpy);
SyncHandle();
return False;
}
if (rep.driverNameLength == 0 && rep.deviceNameLength == 0) {
UnlockDisplay(dpy);
SyncHandle();
return False;
}
*driverName = Xmalloc(rep.driverNameLength + 1);
if (*driverName == NULL) {
_XEatData(dpy,
((rep.driverNameLength + 3) & ~3) +
((rep.deviceNameLength + 3) & ~3));
UnlockDisplay(dpy);
SyncHandle();
return False;
}
_XReadPad(dpy, *driverName, rep.driverNameLength);
(*driverName)[rep.driverNameLength] = '\0';
*deviceName = Xmalloc(rep.deviceNameLength + 1);
if (*deviceName == NULL) {
Xfree(*driverName);
_XEatData(dpy, ((rep.deviceNameLength + 3) & ~3));
UnlockDisplay(dpy);
SyncHandle();
return False;
}
_XReadPad(dpy, *deviceName, rep.deviceNameLength);
(*deviceName)[rep.deviceNameLength] = '\0';
UnlockDisplay(dpy);
SyncHandle();
return True;
}
Bool
DRI2Authenticate(Display * dpy, XID window, drm_magic_t magic)
{
XExtDisplayInfo *info = DRI2FindDisplay(dpy);
xDRI2AuthenticateReq *req;
xDRI2AuthenticateReply rep;
XextCheckExtension(dpy, info, dri2ExtensionName, False);
LockDisplay(dpy);
GetReq(DRI2Authenticate, req);
req->reqType = info->codes->major_opcode;
req->dri2ReqType = X_DRI2Authenticate;
req->window = window;
req->magic = magic;
if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
UnlockDisplay(dpy);
SyncHandle();
return False;
}
UnlockDisplay(dpy);
SyncHandle();
return rep.authenticated;
}
void
DRI2CreateDrawable(Display * dpy, XID drawable)
{
XExtDisplayInfo *info = DRI2FindDisplay(dpy);
xDRI2CreateDrawableReq *req;
XextSimpleCheckExtension(dpy, info, dri2ExtensionName);
LockDisplay(dpy);
GetReq(DRI2CreateDrawable, req);
req->reqType = info->codes->major_opcode;
req->dri2ReqType = X_DRI2CreateDrawable;
req->drawable = drawable;
UnlockDisplay(dpy);
SyncHandle();
}
void
DRI2DestroyDrawable(Display * dpy, XID drawable)
{
XExtDisplayInfo *info = DRI2FindDisplay(dpy);
xDRI2DestroyDrawableReq *req;
XextSimpleCheckExtension(dpy, info, dri2ExtensionName);
XSync(dpy, False);
LockDisplay(dpy);
GetReq(DRI2DestroyDrawable, req);
req->reqType = info->codes->major_opcode;
req->dri2ReqType = X_DRI2DestroyDrawable;
req->drawable = drawable;
UnlockDisplay(dpy);
SyncHandle();
}
DRI2Buffer *
DRI2GetBuffers(Display * dpy, XID drawable,
int *width, int *height,
unsigned int *attachments, int count, int *outCount)
{
XExtDisplayInfo *info = DRI2FindDisplay(dpy);
xDRI2GetBuffersReply rep;
xDRI2GetBuffersReq *req;
DRI2Buffer *buffers;
xDRI2Buffer repBuffer;
CARD32 *p;
int i;
XextCheckExtension(dpy, info, dri2ExtensionName, False);
LockDisplay(dpy);
GetReqExtra(DRI2GetBuffers, count * 4, req);
req->reqType = info->codes->major_opcode;
req->dri2ReqType = X_DRI2GetBuffers;
req->drawable = drawable;
req->count = count;
p = (CARD32 *) & req[1];
for (i = 0; i < count; i++)
p[i] = attachments[i];
if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
UnlockDisplay(dpy);
SyncHandle();
return NULL;
}
*width = rep.width;
*height = rep.height;
*outCount = rep.count;
buffers = Xmalloc(rep.count * sizeof buffers[0]);
if (buffers == NULL) {
_XEatData(dpy, rep.count * sizeof repBuffer);
UnlockDisplay(dpy);
SyncHandle();
return NULL;
}
for (i = 0; i < rep.count; i++) {
_XReadPad(dpy, (char *) &repBuffer, sizeof repBuffer);
buffers[i].attachment = repBuffer.attachment;
buffers[i].name = repBuffer.name;
buffers[i].pitch = repBuffer.pitch;
buffers[i].cpp = repBuffer.cpp;
buffers[i].flags = repBuffer.flags;
}
UnlockDisplay(dpy);
SyncHandle();
return buffers;
}
DRI2Buffer *
DRI2GetBuffersWithFormat(Display * dpy, XID drawable,
int *width, int *height,
unsigned int *attachments, int count, int *outCount)
{
XExtDisplayInfo *info = DRI2FindDisplay(dpy);
xDRI2GetBuffersReply rep;
xDRI2GetBuffersReq *req;
DRI2Buffer *buffers;
xDRI2Buffer repBuffer;
CARD32 *p;
int i;
XextCheckExtension(dpy, info, dri2ExtensionName, False);
LockDisplay(dpy);
GetReqExtra(DRI2GetBuffers, count * (4 * 2), req);
req->reqType = info->codes->major_opcode;
req->dri2ReqType = X_DRI2GetBuffersWithFormat;
req->drawable = drawable;
req->count = count;
p = (CARD32 *) & req[1];
for (i = 0; i < (count * 2); i++)
p[i] = attachments[i];
if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
UnlockDisplay(dpy);
SyncHandle();
return NULL;
}
*width = rep.width;
*height = rep.height;
*outCount = rep.count;
buffers = Xmalloc(rep.count * sizeof buffers[0]);
if (buffers == NULL) {
_XEatData(dpy, rep.count * sizeof repBuffer);
UnlockDisplay(dpy);
SyncHandle();
return NULL;
}
for (i = 0; i < rep.count; i++) {
_XReadPad(dpy, (char *) &repBuffer, sizeof repBuffer);
buffers[i].attachment = repBuffer.attachment;
buffers[i].name = repBuffer.name;
buffers[i].pitch = repBuffer.pitch;
buffers[i].cpp = repBuffer.cpp;
buffers[i].flags = repBuffer.flags;
}
UnlockDisplay(dpy);
SyncHandle();
return buffers;
}
void
DRI2CopyRegion(Display * dpy, XID drawable, XserverRegion region,
CARD32 dest, CARD32 src)
{
XExtDisplayInfo *info = DRI2FindDisplay(dpy);
xDRI2CopyRegionReq *req;
xDRI2CopyRegionReply rep;
XextSimpleCheckExtension(dpy, info, dri2ExtensionName);
LockDisplay(dpy);
GetReq(DRI2CopyRegion, req);
req->reqType = info->codes->major_opcode;
req->dri2ReqType = X_DRI2CopyRegion;
req->drawable = drawable;
req->region = region;
req->dest = dest;
req->src = src;
_XReply(dpy, (xReply *) & rep, 0, xFalse);
UnlockDisplay(dpy);
SyncHandle();
}
#ifdef X_DRI2SwapBuffers
static void
load_swap_req(xDRI2SwapBuffersReq *req, CARD64 target, CARD64 divisor,
CARD64 remainder)
{
req->target_msc_hi = target >> 32;
req->target_msc_lo = target & 0xffffffff;
req->divisor_hi = divisor >> 32;
req->divisor_lo = divisor & 0xffffffff;
req->remainder_hi = remainder >> 32;
req->remainder_lo = remainder & 0xffffffff;
}
static CARD64
vals_to_card64(CARD32 lo, CARD32 hi)
{
return (CARD64)hi << 32 | lo;
}
void DRI2SwapBuffers(Display *dpy, XID drawable, CARD64 target_msc,
CARD64 divisor, CARD64 remainder, CARD64 *count)
{
XExtDisplayInfo *info = DRI2FindDisplay(dpy);
xDRI2SwapBuffersReq *req;
xDRI2SwapBuffersReply rep;
XextSimpleCheckExtension (dpy, info, dri2ExtensionName);
LockDisplay(dpy);
GetReq(DRI2SwapBuffers, req);
req->reqType = info->codes->major_opcode;
req->dri2ReqType = X_DRI2SwapBuffers;
req->drawable = drawable;
load_swap_req(req, target_msc, divisor, remainder);
_XReply(dpy, (xReply *)&rep, 0, xFalse);
*count = vals_to_card64(rep.swap_lo, rep.swap_hi);
UnlockDisplay(dpy);
SyncHandle();
}
#endif
#ifdef X_DRI2GetMSC
Bool DRI2GetMSC(Display *dpy, XID drawable, CARD64 *ust, CARD64 *msc,
CARD64 *sbc)
{
XExtDisplayInfo *info = DRI2FindDisplay(dpy);
xDRI2GetMSCReq *req;
xDRI2MSCReply rep;
XextCheckExtension (dpy, info, dri2ExtensionName, False);
LockDisplay(dpy);
GetReq(DRI2GetMSC, req);
req->reqType = info->codes->major_opcode;
req->dri2ReqType = X_DRI2GetMSC;
req->drawable = drawable;
if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
UnlockDisplay(dpy);
SyncHandle();
return False;
}
*ust = vals_to_card64(rep.ust_lo, rep.ust_hi);
*msc = vals_to_card64(rep.msc_lo, rep.msc_hi);
*sbc = vals_to_card64(rep.sbc_lo, rep.sbc_hi);
UnlockDisplay(dpy);
SyncHandle();
return True;
}
#endif
#ifdef X_DRI2WaitMSC
static void
load_msc_req(xDRI2WaitMSCReq *req, CARD64 target, CARD64 divisor,
CARD64 remainder)
{
req->target_msc_hi = target >> 32;
req->target_msc_lo = target & 0xffffffff;
req->divisor_hi = divisor >> 32;
req->divisor_lo = divisor & 0xffffffff;
req->remainder_hi = remainder >> 32;
req->remainder_lo = remainder & 0xffffffff;
}
Bool DRI2WaitMSC(Display *dpy, XID drawable, CARD64 target_msc, CARD64 divisor,
CARD64 remainder, CARD64 *ust, CARD64 *msc, CARD64 *sbc)
{
XExtDisplayInfo *info = DRI2FindDisplay(dpy);
xDRI2WaitMSCReq *req;
xDRI2MSCReply rep;
XextCheckExtension (dpy, info, dri2ExtensionName, False);
LockDisplay(dpy);
GetReq(DRI2WaitMSC, req);
req->reqType = info->codes->major_opcode;
req->dri2ReqType = X_DRI2WaitMSC;
req->drawable = drawable;
load_msc_req(req, target_msc, divisor, remainder);
if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
UnlockDisplay(dpy);
SyncHandle();
return False;
}
*ust = ((CARD64)rep.ust_hi << 32) | (CARD64)rep.ust_lo;
*msc = ((CARD64)rep.msc_hi << 32) | (CARD64)rep.msc_lo;
*sbc = ((CARD64)rep.sbc_hi << 32) | (CARD64)rep.sbc_lo;
UnlockDisplay(dpy);
SyncHandle();
return True;
}
#endif
#ifdef X_DRI2WaitSBC
static void
load_sbc_req(xDRI2WaitSBCReq *req, CARD64 target)
{
req->target_sbc_hi = target >> 32;
req->target_sbc_lo = target & 0xffffffff;
}
Bool DRI2WaitSBC(Display *dpy, XID drawable, CARD64 target_sbc, CARD64 *ust,
CARD64 *msc, CARD64 *sbc)
{
XExtDisplayInfo *info = DRI2FindDisplay(dpy);
xDRI2WaitSBCReq *req;
xDRI2MSCReply rep;
XextCheckExtension (dpy, info, dri2ExtensionName, False);
LockDisplay(dpy);
GetReq(DRI2WaitSBC, req);
req->reqType = info->codes->major_opcode;
req->dri2ReqType = X_DRI2WaitSBC;
req->drawable = drawable;
load_sbc_req(req, target_sbc);
if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
UnlockDisplay(dpy);
SyncHandle();
return False;
}
*ust = ((CARD64)rep.ust_hi << 32) | rep.ust_lo;
*msc = ((CARD64)rep.msc_hi << 32) | rep.msc_lo;
*sbc = ((CARD64)rep.sbc_hi << 32) | rep.sbc_lo;
UnlockDisplay(dpy);
SyncHandle();
return True;
}
#endif
#ifdef X_DRI2SwapInterval
void DRI2SwapInterval(Display *dpy, XID drawable, int interval)
{
XExtDisplayInfo *info = DRI2FindDisplay(dpy);
xDRI2SwapIntervalReq *req;
XextSimpleCheckExtension (dpy, info, dri2ExtensionName);
LockDisplay(dpy);
GetReq(DRI2SwapInterval, req);
req->reqType = info->codes->major_opcode;
req->dri2ReqType = X_DRI2SwapInterval;
req->drawable = drawable;
req->interval = interval;
UnlockDisplay(dpy);
SyncHandle();
}
#endif
#endif /* GLX_DIRECT_RENDERING */
|
the_stack_data/44099.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int reverter(int n, char *p){
if (n <= 1) return 1;
char t = p[0];
p[0] = p[n - 1];
p[n - 1] = t;
return reverter(n - 2, p + 1);
}
int main(int argc, char** argv){
char palavra[20];
printf("Digite uma palavra: ");
scanf("%s", palavra);
reverter(strlen(palavra), palavra);
printf("A palavra revertida é: %s\n", palavra);
return EXIT_SUCCESS;
} |
the_stack_data/64199917.c | /*
* Generated with test/generate_buildtest.pl, to check that such a simple
* program builds.
*/
#include <openssl/opensslconf.h>
#ifndef OPENSSL_NO_STDIO
# include <stdio.h>
#endif
#ifndef OPENSSL_NO_MD4
# include <openssl/md4.h>
#endif
int main()
{
return 0;
}
|
the_stack_data/57950275.c | /*
* Unleet Plugin - turns 1337 w0rd5 back into leet words
*/
#include <ctype.h>
void process(char **message, int len)
{
int i;
char *msg = *message;
for (i = 0; i < len; i++) {
switch (msg[i]) {
case '0':
msg[i] = 'o';
break;
case '1':
msg[i] = 'i';
break;
case '2':
msg[i] = 'z';
break;
case '3':
msg[i] = 'e';
break;
case '4':
msg[i] = 'a';
break;
case '5':
msg[i] = 's';
break;
case '6':
msg[i] = 'G';
break;
case '7':
msg[i] = 't';
break;
case '8':
msg[i] = 'b';
break;
case '9':
msg[i] = 'g';
break;
}
}
}
|
the_stack_data/70450772.c | /*
** shmdemo.c -- read and write to a shared memory segment
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#define SHM_SIZE 1024 /* make it a 1K shared memory segment */
struct st{
char name[10];
int id;
};
int main(int argc, char *argv[])
{
key_t key;
int shmid;
struct st * data;
if (argc > 3) {
fprintf(stderr, "usage: shmdemo [data_to_write]\n");
exit(1);
}
/* make the key: */
if ((key = ftok("shmdemo.c", 'R')) == -1) {
perror("ftok");
exit(1);
}
/* connect to (and possibly create) the segment: */
if ((shmid = shmget(key, SHM_SIZE, 0644 | IPC_CREAT)) == -1) {
perror("shmget");
exit(1);
}
/* attach to the segment to get a pointer to it: */
data = (struct st *)shmat(shmid, (void *)0, 0);
if (data == (struct st *)(-1)) {
perror("shmat");
exit(1);
}
/* read or modify the segment, based on the command line: */
if (argc == 3) {
printf("writing to segment: \"%s\"\n", argv[1]);
data[0].id = atoi(argv[2]);
strncpy(data[0].name, argv[1], 10);
} else
printf("segment contains: \"%s %d\"\n", data[0].name, data[0].id);
/* detach from the segment: */
if (shmdt(data) == -1) {
perror("shmdt");
exit(1);
}
return 0;
}
|
the_stack_data/193892451.c | #include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <netdb.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
extern int errno;
#define PORT 8080
typedef struct sockaddr_in Sin;
typedef struct sockaddr S;
int connfd;
void send_file()
{
while(1)
{
char buff[66000];
char str[100];
int retv;
retv=read(connfd, buff, 65000);
buff[retv]='\0';
// printf("%s\n",buff );
if(strcmp(buff,"exit") == 0)
{
write(connfd,"done",4);
printf("Connection with the client is closed\n");
fflush(NULL);
break;
}
printf("File name recieved is %s\n", buff);
fflush(NULL);
int fd = open(buff, O_RDONLY);
if(fd == -1)
{
perror("Error in opening a file");
write(connfd,"error",5);
retv=read(connfd,buff,65000);
buff[retv]='\0';
// printf("e/o:%s\n",buff);
fflush(NULL);
continue;
}
else
{
write(connfd,"open",4);
retv=read(connfd,buff,65000);
buff[retv]='\0';
// printf("e/o:%s\n",buff);
fflush(NULL);
//bzero(buff,66000-1);
int bytes_per_read,n,m;
char num[20];
//bzero(num, 20-1);
int length = lseek(fd,0,SEEK_END);
sprintf(num,"%d",length);
// printf("%d\n", length);
write(connfd, num, strlen(num));
retv=read(connfd, num,19);
num[retv]='\0';
if(length<65000)
{
bytes_per_read=1;
n=length/bytes_per_read;
m=length%bytes_per_read;
}
else
{
n=length/65000;
m=length%65000;
bytes_per_read=65000;
}
// INITIALISING POINTER
lseek(fd, 0, SEEK_SET);
while(n--)
{
//bzero(buff, 65005);
// printf("%s\n",buff);
read(fd,buff,bytes_per_read);
buff[bytes_per_read] = '\0';
// printf("%s\n",buff);
write(connfd,buff,bytes_per_read);
// printf("c:%s\n",buff);
retv=read(connfd,buff,bytes_per_read);
buff[retv]='\0';
//printf("read is %s\n",buff);
}
if(m!=0)
{
//bzero(buff, 65005);
bytes_per_read = m;
read(fd,buff,bytes_per_read);
buff[bytes_per_read] = '\0';
//printf("1: %s\n",buff);
write(connfd,buff,bytes_per_read);
retv=read(connfd,buff,bytes_per_read);
buff[retv]='\0';
}
write(connfd,buff,bytes_per_read);
printf("File sent to Client\n");
close(fd);
}
}
}
int main()
{
// CREATING SOCKET
int serverfd;
serverfd = socket(AF_INET, SOCK_STREAM, 0);
if(serverfd == -1)
{
perror("Error in socket");
exit(0);
}
else
printf("Socket is successfully created\n");
// CHECKING AVAILABILITY OF SOCKET AND REUSING PORT
int set, value = 1;
set = setsockopt(serverfd, SOL_SOCKET, SO_REUSEADDR | SO_REUSEPORT, (char*)&value, sizeof(value));
if(set == -1)
{
perror("Error in attaching socket to port");
exit(0);
}
else
printf("Socket is successfully attached to port\n");
// ASSIGNING IP, PORT
Sin serveradd;
int serveradd_length = sizeof(serveradd);
bzero(&serveradd, serveradd_length);
serveradd.sin_family = AF_INET;
serveradd.sin_addr.s_addr = INADDR_ANY;
serveradd.sin_port = htons(PORT);
// BINDING AND VERIFYING
int bindint;
bindint = bind(serverfd, (S*)&serveradd, sizeof(serveradd));
if(bindint == -1)
{
perror("Error in binding");
exit(0);
}
else
printf("Socket is successfully binded\n");
// LISTENING AND CHECKING QUEUE
int listenint;
listenint = listen(serverfd, 2);
if(listenint == -1)
{
perror("Error in listening");
exit(0);
}
else
printf("Server is listening successfully\n");
// ACCEPTING 1ST REQUEST IN QUEUE
connfd = accept(serverfd, (S*)&serveradd, (socklen_t*)&serveradd_length);
if(connfd == -1)
{
perror("Error in accepting");
exit(0);
}
else
printf("Server successfully accepted the client\n");
// FUNCTION
send_file();
// CLOSING FILE DESCRIPTOR
close(serverfd);
return 0;
}
|
the_stack_data/29824587.c | int testLibCycleB3(void)
{
return 0;
}
|
the_stack_data/54825705.c | #include <stdio.h>
#include <math.h>
int main(void) {
const double ANSWER = 3.14159;
double response;
printf("What is the value of pi?\n");
scanf("%lf", &response);
while (fabs(response - ANSWER) > 0.0001) {
printf("Again!\n");
scanf("%lf", &response);
}
printf("Close enough!\n");
return 0;
} |
the_stack_data/153464.c | #include<stdio.h>
#include <string.h>
#include <math.h>
int main(int argc, char *argv[])//Aлгоритм обхода в глубину
{
int i,j,n,m,x,i_temp=1;
scanf("%d %d",&n,&m);
if(n==0)
{
printf("0 1\n");
printf("0 %d\n",m);
printf("0 0\n");
printf("0 %d\n",(m-1));
return 0;
}
else if(m==0)
{
printf("1 0\n");
printf("%d 0\n",n);
printf("0 0\n");
printf("%d 0\n",(n-1));
return 0;
}
else if((m==n)&&(n==1))
{
printf("%d %d\n",n,m);
printf("0 0\n");
printf("%d 0\n",n);
printf("0 %d\n",(m));
return 0;
}
else if(m==n)
{
if(m+m*1.41f>(2*sqrt((double)(m*m+(m-1)*(m-1)))))
{
printf("%d %d\n",n,m);
printf("0 0\n");
printf("%d 0\n",n);
printf("0 %d\n",n);
}
else
{
printf("%d %d\n",n-1,m);
printf("0 0\n");
printf("%d %d\n",n,m);
printf("1 0\n");
}
return 0;
}
else if(n<m)
{
if(m+sqrt((double)n*n+m*m)<(2*sqrt((double)(n-1)*(n-1)+(m)*(m))))
{
printf("%d %d\n",n-1,m);
printf("0 0\n");
printf("%d %d\n",n,m);
printf("1 0\n");
return 0;
}
else
{
printf("%d %d\n0 0 \n0 %d\n%d 0\n",n,m,m,n);
return 0;
}
}
else if(n>m)
{
if(n+sqrt((double)n*n+m*m)<(2*sqrt((double)n*n+(m-1)*(m-1))))
{
printf("%d %d\n",n,m-1);
printf("0 0\n");
printf("%d %d\n",n,m);
printf("0 1\n");
return 0;
}
else
{
printf("%d %d\n0 0 \n%d \n0 %d\n",n,m,n,m);
return 0;
}
}
} |
the_stack_data/139375.c | // This file is part of CPAchecker,
// a tool for configurable software verification:
// https://cpachecker.sosy-lab.org
//
// SPDX-FileCopyrightText: 2007-2020 Dirk Beyer <https://www.sosy-lab.org>
//
// SPDX-License-Identifier: Apache-2.0
// Variables with storage class extern do not have any default value!
extern int i;
int main() {
if (i == 1) {
ERROR: goto ERROR;
}
}
|
the_stack_data/16182.c | #include <stdio.h>
#include <stdlib.h>
typedef struct comodo_s {
char nome[50];
double largura;
double comprimento;
} comodo;
typedef struct construcao_s {
int n;
comodo *comodos;
} construcao;
void preenche(comodo *com, int pos, char nome[50], double largura, double comprimento) {
for(int i=0; i<50; i++)
com[pos].nome[i] = nome[i];
com[pos].largura = largura;
com[pos].comprimento = comprimento;
}
void imprime(construcao c) {
printf("Num de comodos %d\n", c.n);
for(int i=0; i<c.n; i++) {
printf("%s %.2f %.2f\n", (*(c.comodos+i)).nome, c.comodos[i].largura, c.comodos[i].comprimento);
}
}
int main() {
construcao c;
c.n = 3;
c.comodos = malloc(3*sizeof(comodo));
preenche(c.comodos, 0, "cozinha", 1, 2);
preenche(c.comodos, 1, "quarto", 3, 3);
preenche(c.comodos, 2, "banheiro", 2, 1);
imprime(c);
return 0;
} |
the_stack_data/257614.c | #include <stdio.h>
void fib_print(long long);
long long fib(long long);
int main(void)
{
long long num;
int i;
while (scanf("%lld", &num) == 1)
{
printf("fib sequence: ");
for (i=0;i<num;i++)
{
if (i + 1 >= num)
fib_print(i);
else
fib_print(i);
}
printf("%lld", fib(num));
printf("\n");
}
return 0;
}
long long fib(long long num)
{
return (num > 2) ? fib(num-1) + fib(num-2) : 1;
}
void fib_print(long long num)
{
if (num > 2)
{
printf("%lld ", fib(num));
}
else
{
printf("%d ", 1);
}
} |
the_stack_data/32950686.c | /* Two dimensional array example */
#include <stdio.h>
#define STUDENTS 3
#define EXAMS 4
int minimum(int [][EXAMS],int,int);
int maximum(int [][EXAMS],int,int);
double average(int [][EXAMS],int,int);
void printArray(int [][EXAMS],int,int);
int main(){
int student;
int studentGrades[ STUDENTS ][ EXAMS ] =
{ { 77, 68, 86, 73 },
{ 96, 87, 89, 78 },
{ 70, 90, 86, 81 } };
printf( "The array is:\n" );
printArray(studentGrades, STUDENTS, EXAMS);
printf( "\n\nLowest grade: %d\nHighest grade: %d\n",
minimum( studentGrades, STUDENTS, EXAMS ),
maximum( studentGrades, STUDENTS, EXAMS ) );
for ( student = 0; student <= STUDENTS - 1; student++ )
printf( "The average grade for student %d is %.2f\n",
student,
average( studentGrades, EXAMS,student ) );
return 0;
}
/* Find the minimum grade */
int minimum(int grades[][EXAMS],int pupils,int tests){
int i, j, lowGrade = 100;
for ( i = 0; i <= pupils - 1; i++ )
for ( j = 0; j <= tests - 1; j++ )
if ( grades[ i ][ j ] < lowGrade )
lowGrade = grades[ i ][ j ];
return lowGrade;
}
/* Find the maximum grade */
int maximum(int grades[][EXAMS],int pupils,int tests){
int i, j, highGrade = 0;
for ( i = 0; i <= pupils - 1; i++ )
for ( j = 0; j <= tests - 1; j++ )
if ( grades[ i ][ j ] > highGrade )
highGrade = grades[ i ][ j ];
return highGrade;
}
/* Determine the average grade for a particular exam */
double average(int grades[][EXAMS],int tests,int student){
int j, total = 0;
for ( j = 0; j <= tests - 1; j++ )
total += grades[student][j];
return ( double ) total / tests;
}
/* Print the array */
void printArray(int grades[][EXAMS],int pupils,int tests){
int i, j;
printf( " [0] [1] [2] [3]" );
for ( i = 0; i <= pupils - 1; i++ ) {
printf( "\nstudentGrades[%d] ", i );
for ( j = 0; j <= tests - 1; j++ )
printf( "%-5d", grades[ i ][ j ] );
}
} |
the_stack_data/18887841.c | int main()
{
int A[] = {1, 1};
int i;
__CPROVER_assert(i < 0 || i > 1 || A[i] == 1, "valid access into array of 1");
__CPROVER_assert(A[i] == 1, "possible out-of-bounds access");
return 0;
}
|
the_stack_data/151937.c | /* ヘッダファイルのインクルード */
#include <stdio.h> /* 標準入出力 */
#include <math.h> /* 数学関数 */
/* main関数の定義 */
int main(void){
/* 変数の宣言 */
double x; /* 入力された値を格納するdouble型変数x. */
double c; /* xより小さくない最小の整数値を格納するdouble型変数c. */
/* 値の入力 */
printf("x: "); /* xの入力フォーム. */
scanf("%lf", &x); /* 入力値をxに格納. */
/* 実数xに対して, xより小さくない最小の整数を求める. */
c = ceil(x); /* ceilでxの小数点以下を切り上げ, cに格納. */
/* cの出力 */
printf("c = %lf\n", c); /* printfでcを出力. */
/* プログラムの終了 */
return 0; /* 0を返して正常終了. */
}
|
the_stack_data/90761727.c | /*
* Copyright (c) 2017 Linaro Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdio.h>
#include <errno.h>
#ifndef __ZEPHYR__
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
#else
#include <net/socket.h>
#include <kernel.h>
#include <net/net_app.h>
#endif
#define PORT 4242
int main(void)
{
int serv;
struct sockaddr_in bind_addr;
static int counter;
serv = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
bind_addr.sin_family = AF_INET;
bind_addr.sin_addr.s_addr = htonl(INADDR_ANY);
bind_addr.sin_port = htons(PORT);
bind(serv, (struct sockaddr *)&bind_addr, sizeof(bind_addr));
listen(serv, 5);
printf("Single-threaded TCP echo server waits for a connection on port %d...\n", PORT);
while (1) {
struct sockaddr_in client_addr;
socklen_t client_addr_len = sizeof(client_addr);
char addr_str[32];
int client = accept(serv, (struct sockaddr *)&client_addr,
&client_addr_len);
inet_ntop(client_addr.sin_family, &client_addr.sin_addr,
addr_str, sizeof(addr_str));
printf("Connection #%d from %s\n", counter++, addr_str);
while (1) {
char buf[128], *p;
int len = recv(client, buf, sizeof(buf), 0);
int out_len;
if (len <= 0) {
if (len < 0) {
printf("error: recv: %d\n", errno);
}
break;
}
p = buf;
do {
out_len = send(client, p, len, 0);
if (out_len < 0) {
printf("error: send: %d\n", errno);
goto error;
}
p += out_len;
len -= out_len;
} while (len);
}
error:
close(client);
printf("Connection from %s closed\n", addr_str);
}
}
|
the_stack_data/629532.c | #include<stdio.h>
int main()
{
int T,i,r,c,k,m,n;
printf("Enter number of test cases:");
scanf("%d",&T);
for(i=1;i<=T;i++)
{
int a[8][8];
printf("enter row column and moves:");
scanf("%d %d %d",&r,&c,&k);
for(m=r-1-k;m<=r-1+k;m++)
{
for(n=c-1-k;n<=c-1+k;n++)
{
if(m>=0&&n>=0)
a[m][n]=1;
}
}
int ctr=0;
for(m=0;m<8;m++)
{
for(n=0;n<8;n++)
{
if(a[m][n]==1)
ctr++;
}
}
printf("%d",ctr);
}
}
|
the_stack_data/126239.c | //Classification: n/DAM/NP/sS/D(v)/fr/rp
//Written by: Sergey Pomelov
//Reviewed by: Igor Eremeev
//Comment:
#include <stdio.h>
int *func(void)
{
int *p = NULL;
return p;
};
int main(void)
{
static int a;
int i;
for(i=1; i<100; i++) {
a = *func();
printf("%d",a);
}
return 0;
}
|
the_stack_data/60904.c | #include "err.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#ifdef __WIN32__
/* index replacement for win32 */
static char* index(const char* str, int c) {
char* p = str;
while (1) {
if (*p == c) return p;
if (*p == '\0') break;
p += 1;
}
return NULL;
}
#endif
int main(int argc, char **argv) {
FILE *f;
int nblock, btype, x, z, width, height;
char *fname, *levelname;
char buf[128];
int i;
srand(0);
if(argc != 2) errx(1, "Usage: %s levelfile", argv[0]);
fname = argv[1];
levelname = fname;
while(index(levelname, '/')) levelname = index(levelname, '/') + 1;
f = fopen(fname, "r");
if(!f) err(1, "%s", fname);
printf("uint8_t data_%s[] = {\n", levelname);
if(!fgets(buf, sizeof(buf), f)) err(1, "%s: Empty file?", fname);
if(1 == sscanf(buf, "%d", &nblock)) {
if(nblock < 1 || nblock > 255) errx(1, "%s: Invalid block count", fname);
printf("\t\t0x%02x,\n", nblock & 255);
printf("\t\t0x%02x,\n", nblock >> 8);
for(i = 0; i < nblock; i++) {
if(!fgets(buf, sizeof(buf), f)) err(1, "%s: Unexpected EOF", fname);
if(3 == sscanf(buf, "%d , %d , %d", &btype, &x, &z)) {
printf("\t\t0x%02x, 0x%02x, 0x%02x, 0x%02x,\n",
btype,
rand() % 6,
x,
z);
} else errx(1, "%s: Couldn't parse line", fname);
}
} else if(2 == sscanf(buf, "ascii %d %d", &width, &height)) {
uint8_t buffer[65536 * 4];
nblock = 0;
for(z = 0; z < height; z++) {
if(!fgets(buf, sizeof(buf), f)) err(1, "%s: Unexpected EOF", fname);
for(x = 0; x < width; x++) {
if(buf[x] != '.') {
if(nblock >= 65535) errx(1, "%s: Too many blocks", fname);
switch(buf[x]) {
case '*':
buffer[nblock * 4 + 0] = 1;
buffer[nblock * 4 + 1] = 0;
break;
case 'R':
buffer[nblock * 4 + 0] = 1;
buffer[nblock * 4 + 1] = rand() % 6;
break;
default:
buffer[nblock * 4 + 0] = 0;
buffer[nblock * 4 + 1] = buf[x] - '1';
break;
}
buffer[nblock * 4 + 2] = x * 16;
buffer[nblock * 4 + 3] = (height - 1 - z) * 16;
nblock++;
}
}
}
printf("\t\t0x%02x,\n", nblock & 255);
printf("\t\t0x%02x,\n", nblock >> 8);
for(i = 0; i < nblock; i++) {
printf("\t\t0x%02x, 0x%02x, 0x%02x, 0x%02x,\n",
buffer[i * 4 + 0],
buffer[i * 4 + 1],
buffer[i * 4 + 2],
buffer[i * 4 + 3]);
}
} else errx(1, "%s: Unsupported high-level format", fname);
printf("};\n");
return 0;
}
|
the_stack_data/73576091.c | /* { dg-do compile } */
/* { dg-options "-O2 -fdump-tree-ivopts-details" } */
int *a;
int
foo (signed char s, signed char l)
{
signed char i;
int sum = 0;
for (i = s; i < l; i++)
{
sum += a[i];
}
return sum;
}
/* Check loop niter bound information. */
/* { dg-final { scan-tree-dump "bounded by 254" "ivopts" } } */
/* { dg-final { scan-tree-dump-not "bounded by 255" "ivopts" } } */
/* { dg-final { scan-tree-dump-not "zero if " "ivopts" } } */
|
the_stack_data/100140239.c | #include<stdio.h>
int main()
{
int s[4], r=0;
for(int i=0; i<4; i++)
{
scanf("%d",&s[i]);
for(int j=i-1; j>=0; j--)
{
if(s[i]==s[j])
{
r++;
break;
}
}
}
printf("%d\n",r);
}
|
the_stack_data/145452314.c | /* Generated by CIL v. 1.7.0 */
/* print_CIL_Input is false */
struct _IO_FILE;
struct timeval;
extern float strtof(char const *str , char const *endptr ) ;
extern void signal(int sig , void *func ) ;
typedef struct _IO_FILE FILE;
extern int atoi(char const *s ) ;
extern double strtod(char const *str , char const *endptr ) ;
extern int fclose(void *stream ) ;
extern void *fopen(char const *filename , char const *mode ) ;
extern void abort() ;
extern void exit(int status ) ;
extern int raise(int sig ) ;
extern int fprintf(struct _IO_FILE *stream , char const *format , ...) ;
extern int strcmp(char const *a , char const *b ) ;
extern int rand() ;
extern unsigned long strtoul(char const *str , char const *endptr , int base ) ;
void RandomFunc(unsigned long input[1] , unsigned long output[1] ) ;
extern int strncmp(char const *s1 , char const *s2 , unsigned long maxlen ) ;
extern int gettimeofday(struct timeval *tv , void *tz , ...) ;
extern int printf(char const *format , ...) ;
int main(int argc , char *argv[] ) ;
void megaInit(void) ;
extern unsigned long strlen(char const *s ) ;
extern long strtol(char const *str , char const *endptr , int base ) ;
extern unsigned long strnlen(char const *s , unsigned long maxlen ) ;
extern void *memcpy(void *s1 , void const *s2 , unsigned long size ) ;
struct timeval {
long tv_sec ;
long tv_usec ;
};
extern void *malloc(unsigned long size ) ;
extern int scanf(char const *format , ...) ;
void megaInit(void)
{
{
}
}
int main(int argc , char *argv[] )
{
unsigned long input[1] ;
unsigned long output[1] ;
int randomFuns_i5 ;
unsigned long randomFuns_value6 ;
int randomFuns_main_i7 ;
{
megaInit();
if (argc != 2) {
printf("Call this program with %i arguments\n", 1);
exit(-1);
} else {
}
randomFuns_i5 = 0;
while (randomFuns_i5 < 1) {
randomFuns_value6 = strtoul(argv[randomFuns_i5 + 1], 0, 10);
input[randomFuns_i5] = randomFuns_value6;
randomFuns_i5 ++;
}
RandomFunc(input, output);
if (output[0] == 18446744072512809767UL) {
printf("You win!\n");
} else {
}
randomFuns_main_i7 = 0;
while (randomFuns_main_i7 < 1) {
printf("%lu\n", output[randomFuns_main_i7]);
randomFuns_main_i7 ++;
}
}
}
void RandomFunc(unsigned long input[1] , unsigned long output[1] )
{
unsigned long state[1] ;
unsigned long local1 ;
{
state[0UL] = input[0UL] + 0xffffffffff660b45UL;
local1 = 0UL;
while (local1 < 1UL) {
state[local1] += state[local1];
local1 += 2UL;
}
local1 = 0UL;
while (local1 < 1UL) {
state[local1] += state[local1];
local1 += 2UL;
}
output[0UL] = (state[0UL] - 255873917UL) - 900558676UL;
}
}
|
the_stack_data/1038857.c | #define _GNU_SOURCE
#include <stdio.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <signal.h>
int main(int argc, char **argv)
{
long int mama = syscall(323);
printf("[SYS_HELLO] call -> %ld\n", mama);
return 0;
}
|
the_stack_data/234517266.c | #if defined _WIN32 || defined WIN32
#include "internal.h"
uint64_t cf_directory_exists(CC_String _path)
{
CC_String path = cc_string_copy(_path);
DWORD dwAttrib = GetFileAttributesA(path.data);
cc_string_destroy(path);
return (dwAttrib != INVALID_FILE_ATTRIBUTES && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
}
uint64_t cf_directory_create(CC_String path)
{
char *c_path = malloc(path.length + 1);
for (uint64_t i = 0; i < path.length; i++)
c_path[i] = path.data[i];
c_path[path.length] = '\0';
uint64_t success = CreateDirectoryA(c_path, NULL);
free(c_path);
return success;
}
uint64_t cf_directory_destroy(CC_String path)
{
char *c_path = malloc(path.length + 1);
for (uint64_t i = 0; i < path.length; i++)
c_path[i] = path.data[i];
c_path[path.length] = '\0';
uint64_t success = RemoveDirectoryA(c_path);
free(c_path);
return success;
}
#endif |
the_stack_data/20416.c | #include <stdio.h>
#include <stdlib.h>
static char* TABLE = NULL;
static int BIT = 0;
static int GROUP = 0;
static int N = 0;
static char PAD = '=';
int setTable(char* table, unsigned char len, char pad) {
if (table != NULL && len != 0){
TABLE = table;
while ((len >>= 1) != 0) BIT++;
GROUP = (BIT != 0 ? ((BIT & 1) == 1 ? BIT << 3 : BIT << (BIT & 2)) : BIT);
N = GROUP / BIT;
PAD = pad;
return 0;
}
return -1;
}
int encode(unsigned char* p_str, int len, char* result) {
if (TABLE != NULL && p_str != NULL && BIT != 0 && GROUP != 0)
{
int res_len = (((len <<= 3) - 1) / GROUP + 1) * N;
if (res_len < _msize(result))
{
unsigned int index = 0;
unsigned char bytes = *p_str;
int n = res_len - (len - 1) / BIT - 1;
int j = BIT;
do {
for (int i = 0; i < 8; i++) {
j--;
if ((signed char)bytes < 0) index += (1 << j);
if (j == 0) {
*(result++) = TABLE[index];
j = BIT;
index = 0;
}
bytes <<= 1;
}
bytes = *(++p_str);
} while (len -= 8);
if (j != 0 && j != BIT) {
*(result++) = TABLE[index];
}
while (n--) {
*(result++) = PAD;
}
return 0;
}
}
return -1;
} |
the_stack_data/913648.c | #include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
enum {
Nb = 4,
Nk = 4,
Nr = 10,
BYTES_IN_COL = sizeof(uint32_t) / sizeof(uint8_t),
RCON_SIZE = 31,
SBOX_SIZE = 256,
INV_SBOX_SIZE = 256,
};
static const uint8_t rc_tab[Nr];
static const uint8_t keys[BYTES_IN_COL * Nk];
static const uint8_t Rcon[RCON_SIZE];
static const uint8_t sbox[SBOX_SIZE];
static const uint8_t inv_sbox[INV_SBOX_SIZE];
static void rotate_word(uint8_t *a) {
uint8_t t;
t = a[0];
a[0] = a[1];
a[1] = a[2];
a[2] = a[3];
a[3] = t;
}
static void run_key_schedule(const uint8_t *key, uint8_t *round_keys) {
uint8_t i;
uint8_t rc = 0;
union {
uint32_t v32;
uint8_t v8[4];
} tmp;
memcpy(round_keys, key, BYTES_IN_COL * Nk);
for (i = 4; i < 44; ++i) {
tmp.v32 = ((uint32_t *)(round_keys))[i - 1];
if (0 == i % 4) {
rotate_word((uint8_t *)&(tmp.v32));
tmp.v8[0] = sbox[tmp.v8[0]];
tmp.v8[1] = sbox[tmp.v8[1]];
tmp.v8[2] = sbox[tmp.v8[2]];
tmp.v8[3] = sbox[tmp.v8[3]];
tmp.v8[0] ^= rc_tab[rc];
rc++;
}
((uint32_t *)(round_keys))[i] = ((uint32_t *)(round_keys))[i - 4] ^ tmp.v32;
}
}
static inline uint8_t gmul(uint8_t a, uint8_t b) {
uint8_t p = 0;
uint8_t counter;
uint8_t hi_bit_set;
for (counter = 0; counter < 8; counter++) {
if ((b & 1) == 1) {
p ^= a;
}
hi_bit_set = (a & 0x80);
a <<= 1;
if (hi_bit_set == 0x80) {
a ^= 0x1b;
}
b >>= 1;
}
return p;
}
static inline void decrypt_round(uint8_t *state, uint8_t *round_keys, int n) {
assert(state);
assert(round_keys);
assert((n > 0) && (n <= Nr));
uint8_t tmp[BYTES_IN_COL * Nb];
uint8_t t, u, v, w;
// keyAdd
for (int i = 0; i < BYTES_IN_COL * Nb; ++i) {
if (Nr != n)
tmp[i] = state[i] ^ round_keys[BYTES_IN_COL * Nb * n + i];
else
state[i] ^= round_keys[BYTES_IN_COL * Nb * n + i];
}
#ifdef DEBUG_LOG
fprintf(stderr, "state: ");
for (int i = 0; i < BYTES_IN_COL * Nb; i++)
fprintf(stderr, "0x%02x ", state[i]);
fprintf(stderr, "\n");
#endif
if (Nr != n) {
// mixColums
for (int i = 0; i < Nb; ++i) {
int offset = BYTES_IN_COL * i;
t = tmp[offset + 3] ^ tmp[offset + 2];
u = tmp[offset + 1] ^ tmp[offset + 0];
v = t ^ u;
v = gmul(0x09, v);
w = v ^ gmul(0x04, tmp[offset + 2] ^ tmp[offset + 0]);
v = v ^ gmul(0x04, tmp[offset + 3] ^ tmp[offset + 1]);
state[offset + 3] =
tmp[offset + 3] ^ v ^ gmul(0x02, tmp[offset + 0] ^ tmp[offset + 3]);
state[offset + 2] = tmp[offset + 2] ^ w ^ gmul(0x02, t);
state[offset + 1] =
tmp[offset + 1] ^ v ^ gmul(0x02, tmp[offset + 2] ^ tmp[offset + 1]);
state[offset + 0] = tmp[offset + 0] ^ w ^ gmul(0x02, u);
#ifdef DEBUG_LOG
fprintf(stderr, "%d state: ", i);
for (int k = 0; k < BYTES_IN_COL * Nb; k++)
fprintf(stderr, "0x%02x ", state[k]);
fprintf(stderr, "\n");
#endif
}
} else {
#ifdef DEBUG_LOG
fprintf(stderr, "state: ");
for (int i = 0; i < BYTES_IN_COL * Nb; i++)
fprintf(stderr, "0x%02x ", state[i]);
fprintf(stderr, "\n");
#endif
}
// shiftRows
for (int i = 1; i < BYTES_IN_COL; i++) {
uint8_t swap_buf[4];
for (int j = 0; j < Nb; j++) {
int offset = i + j * BYTES_IN_COL;
swap_buf[j] = state[offset];
}
for (int j = 0; j < Nb; j++) {
int offset = i + j * BYTES_IN_COL;
state[offset] = swap_buf[(Nb - i + j) & 3];
}
#ifdef DEBUG_LOG
fprintf(stderr, "%d state: ", i);
for (int k = 0; k < BYTES_IN_COL * Nb; k++)
fprintf(stderr, "0x%02x ", state[k]);
fprintf(stderr, "\n");
#endif
}
// subBytes
for (int i = 0; i < BYTES_IN_COL * Nb; ++i) {
state[i] = inv_sbox[state[i]];
}
#ifdef DEBUG_LOG
fprintf(stderr, "state: ");
for (int i = 0; i < BYTES_IN_COL * Nb; i++)
fprintf(stderr, "0x%02x ", state[i]);
fprintf(stderr, "\n");
#endif
}
static void decrypt_impl(uint8_t *block, uint8_t *round_keys) {
for (int i = Nr; i > 0; i--) {
#ifdef DEBUG_LOG
fprintf(stderr, "round %2d\n", i);
#endif
decrypt_round(block, round_keys, i);
}
for (int i = 0; i < BYTES_IN_COL * Nb; ++i) {
block[i] ^= round_keys[i];
}
}
void decrypt(uint8_t *block) {
uint8_t round_keys[BYTES_IN_COL * Nk * (Nr + 1)];
run_key_schedule(keys, round_keys);
decrypt_impl(block, round_keys);
}
static void encrypt_round(uint8_t *state, uint8_t *round_keys, int n) {
assert(state);
assert(round_keys);
assert((n > 0) && (n <= Nr));
uint8_t tmp[BYTES_IN_COL * Nb];
// subBytes
for (int i = 0; i < BYTES_IN_COL * Nb; i++) {
tmp[i] = sbox[state[i]];
}
#ifdef DEBUG_LOG
fprintf(stderr, " tmp: ");
for (int i = 0; i < BYTES_IN_COL * Nb; i++)
fprintf(stderr, "0x%02x ", tmp[i]);
fprintf(stderr, "\n");
#endif
// shiftRows
for (int i = 1; i < BYTES_IN_COL; i++) {
uint8_t swap_buf[Nb];
for (int j = 0; j < Nb; j++) {
int offset = i + j * BYTES_IN_COL;
swap_buf[j] = tmp[offset];
}
for (int j = 0; j < Nb; j++) {
int offset = i + j * BYTES_IN_COL;
tmp[offset] = swap_buf[(i + j) & 3];
}
#ifdef DEBUG_LOG
fprintf(stderr, "%d tmp: ", i);
for (int k = 0; k < 16; k++)
fprintf(stderr, "0x%02x ", tmp[k]);
fprintf(stderr, "\n");
#endif
}
if (n != Nr) {
// mixColums
for (int i = 0; i < Nb; ++i) {
int offset = i * BYTES_IN_COL;
uint8_t t =
tmp[offset + 0] ^ tmp[offset + 1] ^ tmp[offset + 2] ^ tmp[offset + 3];
state[offset + 0] =
gmul(2, tmp[offset + 0] ^ tmp[offset + 1]) ^ tmp[offset + 0] ^ t;
state[offset + 1] =
gmul(2, tmp[offset + 1] ^ tmp[offset + 2]) ^ tmp[offset + 1] ^ t;
state[offset + 2] =
gmul(2, tmp[offset + 2] ^ tmp[offset + 3]) ^ tmp[offset + 2] ^ t;
state[offset + 3] =
gmul(2, tmp[offset + 3] ^ tmp[offset + 0]) ^ tmp[offset + 3] ^ t;
#ifdef DEBUG_LOG
fprintf(stderr, "%d state: ", i);
for (int k = 0; k < BYTES_IN_COL * Nb; k++)
fprintf(stderr, "0x%02x ", state[k]);
fprintf(stderr, "\n");
#endif
}
} else {
#ifdef DEBUG_LOG
fprintf(stderr, "state: ");
for (int i = 0; i < BYTES_IN_COL * Nb; i++)
fprintf(stderr, "0x%02x ", state[i]);
fprintf(stderr, "\n");
#endif
}
// addKey
for (int i = 0; i < BYTES_IN_COL * Nb; i++) {
state[i] =
(n == Nr ? tmp[i] : state[i]) ^ round_keys[BYTES_IN_COL * Nb * n + i];
}
#ifdef DEBUG_LOG
fprintf(stderr, "state: ");
for (int i = 0; i < BYTES_IN_COL * Nb; i++)
fprintf(stderr, "0x%02x ", state[i]);
fprintf(stderr, "\n");
#endif
}
static void encrypt_impl(uint8_t *block, uint8_t *round_keys) {
assert(block);
assert(round_keys);
for (int i = 0; i < BYTES_IN_COL * Nb; i++) {
block[i] ^= round_keys[i];
}
for (int i = 1; i <= Nr; i++) {
#ifdef DEBUG_LOG
fprintf(stderr, "round %2d\n", i);
#endif
encrypt_round(block, round_keys, i);
}
}
void encrypt(uint8_t *block) {
assert(block);
uint8_t round_keys[BYTES_IN_COL * Nk * (Nr + 1)];
run_key_schedule(keys, round_keys);
encrypt_impl(block, round_keys);
}
static const uint8_t rc_tab[Nr] = {0x01, 0x02, 0x04, 0x08, 0x10,
0x20, 0x40, 0x80, 0x1b, 0x36};
static const uint8_t keys[BYTES_IN_COL * Nk] = {
0xf5, 0x30, 0x35, 0x79, 0x68, 0x57, 0x84, 0x80,
0xb3, 0x98, 0xa3, 0xc2, 0x51, 0xcd, 0x10, 0x93};
static const uint8_t Rcon[RCON_SIZE] = {
0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36,
0x6c, 0xc0, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97,
0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91};
static const uint8_t sbox[SBOX_SIZE] = {
0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
0xb0, 0x54, 0xbb, 0x16,
};
static const uint8_t inv_sbox[INV_SBOX_SIZE] = {
0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
0x55, 0x21, 0x0c, 0x7d,
};
|
the_stack_data/125139646.c | /*
* Linux Wireless Extensions support
*
* Copyright (C) 1999-2013, Broadcom Corporation
*
* Unless you and Broadcom execute a separate written software license
* agreement governing use of this software, this software is licensed to you
* under the terms of the GNU General Public License version 2 (the "GPL"),
* available at http://www.broadcom.com/licenses/GPLv2.php, with the
* following added to such license:
*
* As a special exception, the copyright holders of this software give you
* permission to link this software with independent modules, and to copy and
* distribute the resulting executable under terms of your choice, provided that
* you also meet, for each linked independent module, the terms and conditions of
* the license of that module. An independent module is a module which is not
* derived from this software. The special exception does not apply to any
* modifications of the software.
*
* Notwithstanding the above, under no circumstances may you combine this
* software in any way with any other Broadcom software provided under a license
* other than the GPL, without Broadcom's express prior written consent.
*
* $Id: wl_iw.c 396420 2013-04-12 06:55:45Z $
*/
#if defined(USE_IW)
#define LINUX_PORT
#include <typedefs.h>
#include <linuxver.h>
#include <osl.h>
#include <bcmutils.h>
#include <bcmendian.h>
#include <proto/ethernet.h>
#include <linux/if_arp.h>
#include <asm/uaccess.h>
typedef const struct si_pub si_t;
#include <wlioctl.h>
#include <wl_dbg.h>
#include <wl_iw.h>
/* Broadcom extensions to WEXT, linux upstream has obsoleted WEXT */
#ifndef IW_AUTH_KEY_MGMT_FT_802_1X
#define IW_AUTH_KEY_MGMT_FT_802_1X 0x04
#endif
#ifndef IW_AUTH_KEY_MGMT_FT_PSK
#define IW_AUTH_KEY_MGMT_FT_PSK 0x08
#endif
#ifndef IW_ENC_CAPA_FW_ROAM_ENABLE
#define IW_ENC_CAPA_FW_ROAM_ENABLE 0x00000020
#endif
/* FC9: wireless.h 2.6.25-14.fc9.i686 is missing these, even though WIRELESS_EXT is set to latest
* version 22.
*/
#ifndef IW_ENCODE_ALG_PMK
#define IW_ENCODE_ALG_PMK 4
#endif
#ifndef IW_ENC_CAPA_4WAY_HANDSHAKE
#define IW_ENC_CAPA_4WAY_HANDSHAKE 0x00000010
#endif
/* End FC9. */
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
#include <linux/rtnetlink.h>
#endif
#if defined(SOFTAP)
struct net_device *ap_net_dev = NULL;
tsk_ctl_t ap_eth_ctl; /* apsta AP netdev waiter thread */
#endif /* SOFTAP */
extern bool wl_iw_conn_status_str(uint32 event_type, uint32 status,
uint32 reason, char* stringBuf, uint buflen);
uint wl_msg_level = WL_ERROR_VAL;
#define MAX_WLIW_IOCTL_LEN 1024
/* IOCTL swapping mode for Big Endian host with Little Endian dongle. Default to off */
#define htod32(i) i
#define htod16(i) i
#define dtoh32(i) i
#define dtoh16(i) i
#define htodchanspec(i) i
#define dtohchanspec(i) i
extern struct iw_statistics *dhd_get_wireless_stats(struct net_device *dev);
extern int dhd_wait_pend8021x(struct net_device *dev);
#if WIRELESS_EXT < 19
#define IW_IOCTL_IDX(cmd) ((cmd) - SIOCIWFIRST)
#define IW_EVENT_IDX(cmd) ((cmd) - IWEVFIRST)
#endif /* WIRELESS_EXT < 19 */
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
#define DAEMONIZE(a)
#elif ((LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0)) && \
(LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)))
#define DAEMONIZE(a) daemonize(a); \
allow_signal(SIGKILL); \
allow_signal(SIGTERM);
#else /* Linux 2.4 (w/o preemption patch) */
#define RAISE_RX_SOFTIRQ() \
cpu_raise_softirq(smp_processor_id(), NET_RX_SOFTIRQ)
#define DAEMONIZE(a) daemonize(); \
do { if (a) \
strncpy(current->comm, a, MIN(sizeof(current->comm), (strlen(a) + 1))); \
} while (0);
#endif /* LINUX_VERSION_CODE */
#define ISCAN_STATE_IDLE 0
#define ISCAN_STATE_SCANING 1
/* the buf lengh can be WLC_IOCTL_MAXLEN (8K) to reduce iteration */
#define WLC_IW_ISCAN_MAXLEN 2048
typedef struct iscan_buf {
struct iscan_buf * next;
char iscan_buf[WLC_IW_ISCAN_MAXLEN];
} iscan_buf_t;
typedef struct iscan_info {
struct net_device *dev;
struct timer_list timer;
uint32 timer_ms;
uint32 timer_on;
int iscan_state;
iscan_buf_t * list_hdr;
iscan_buf_t * list_cur;
/* Thread to work on iscan */
long sysioc_pid;
struct semaphore sysioc_sem;
struct completion sysioc_exited;
char ioctlbuf[WLC_IOCTL_SMLEN];
} iscan_info_t;
iscan_info_t *g_iscan = NULL;
static void wl_iw_timerfunc(ulong data);
static void wl_iw_set_event_mask(struct net_device *dev);
static int wl_iw_iscan(iscan_info_t *iscan, wlc_ssid_t *ssid, uint16 action);
/* priv_link becomes netdev->priv and is the link between netdev and wlif struct */
typedef struct priv_link {
wl_iw_t *wliw;
} priv_link_t;
/* dev to priv_link */
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24))
#define WL_DEV_LINK(dev) (priv_link_t*)(dev->priv)
#else
#define WL_DEV_LINK(dev) (priv_link_t*)netdev_priv(dev)
#endif
/* dev to wl_iw_t */
#define IW_DEV_IF(dev) ((wl_iw_t*)(WL_DEV_LINK(dev))->wliw)
static void swap_key_from_BE(
wl_wsec_key_t *key
)
{
key->index = htod32(key->index);
key->len = htod32(key->len);
key->algo = htod32(key->algo);
key->flags = htod32(key->flags);
key->rxiv.hi = htod32(key->rxiv.hi);
key->rxiv.lo = htod16(key->rxiv.lo);
key->iv_initialized = htod32(key->iv_initialized);
}
static void swap_key_to_BE(
wl_wsec_key_t *key
)
{
key->index = dtoh32(key->index);
key->len = dtoh32(key->len);
key->algo = dtoh32(key->algo);
key->flags = dtoh32(key->flags);
key->rxiv.hi = dtoh32(key->rxiv.hi);
key->rxiv.lo = dtoh16(key->rxiv.lo);
key->iv_initialized = dtoh32(key->iv_initialized);
}
static int
dev_wlc_ioctl(
struct net_device *dev,
int cmd,
void *arg,
int len
)
{
struct ifreq ifr;
wl_ioctl_t ioc;
mm_segment_t fs;
int ret;
memset(&ioc, 0, sizeof(ioc));
ioc.cmd = cmd;
ioc.buf = arg;
ioc.len = len;
strcpy(ifr.ifr_name, dev->name);
ifr.ifr_data = (caddr_t) &ioc;
#ifndef LINUX_HYBRID
/* Causes an extraneous 'up'. If specific ioctls are failing due
to device down, then we can investigate those ioctls.
*/
dev_open(dev);
#endif
fs = get_fs();
set_fs(get_ds());
#if defined(WL_USE_NETDEV_OPS)
ret = dev->netdev_ops->ndo_do_ioctl(dev, &ifr, SIOCDEVPRIVATE);
#else
ret = dev->do_ioctl(dev, &ifr, SIOCDEVPRIVATE);
#endif
set_fs(fs);
return ret;
}
/*
set named driver variable to int value and return error indication
calling example: dev_wlc_intvar_set(dev, "arate", rate)
*/
static int
dev_wlc_intvar_set(
struct net_device *dev,
char *name,
int val)
{
char buf[WLC_IOCTL_SMLEN];
uint len;
val = htod32(val);
len = bcm_mkiovar(name, (char *)(&val), sizeof(val), buf, sizeof(buf));
ASSERT(len);
return (dev_wlc_ioctl(dev, WLC_SET_VAR, buf, len));
}
static int
dev_iw_iovar_setbuf(
struct net_device *dev,
char *iovar,
void *param,
int paramlen,
void *bufptr,
int buflen)
{
int iolen;
iolen = bcm_mkiovar(iovar, param, paramlen, bufptr, buflen);
ASSERT(iolen);
BCM_REFERENCE(iolen);
return (dev_wlc_ioctl(dev, WLC_SET_VAR, bufptr, iolen));
}
static int
dev_iw_iovar_getbuf(
struct net_device *dev,
char *iovar,
void *param,
int paramlen,
void *bufptr,
int buflen)
{
int iolen;
iolen = bcm_mkiovar(iovar, param, paramlen, bufptr, buflen);
ASSERT(iolen);
BCM_REFERENCE(iolen);
return (dev_wlc_ioctl(dev, WLC_GET_VAR, bufptr, buflen));
}
#if WIRELESS_EXT > 17
static int
dev_wlc_bufvar_set(
struct net_device *dev,
char *name,
char *buf, int len)
{
char *ioctlbuf;
uint buflen;
int error;
ioctlbuf = kmalloc(MAX_WLIW_IOCTL_LEN, GFP_KERNEL);
if (!ioctlbuf)
return -ENOMEM;
buflen = bcm_mkiovar(name, buf, len, ioctlbuf, MAX_WLIW_IOCTL_LEN);
ASSERT(buflen);
error = dev_wlc_ioctl(dev, WLC_SET_VAR, ioctlbuf, buflen);
kfree(ioctlbuf);
return error;
}
#endif /* WIRELESS_EXT > 17 */
/*
get named driver variable to int value and return error indication
calling example: dev_wlc_bufvar_get(dev, "arate", &rate)
*/
static int
dev_wlc_bufvar_get(
struct net_device *dev,
char *name,
char *buf, int buflen)
{
char *ioctlbuf;
int error;
uint len;
ioctlbuf = kmalloc(MAX_WLIW_IOCTL_LEN, GFP_KERNEL);
if (!ioctlbuf)
return -ENOMEM;
len = bcm_mkiovar(name, NULL, 0, ioctlbuf, MAX_WLIW_IOCTL_LEN);
ASSERT(len);
BCM_REFERENCE(len);
error = dev_wlc_ioctl(dev, WLC_GET_VAR, (void *)ioctlbuf, MAX_WLIW_IOCTL_LEN);
if (!error)
bcopy(ioctlbuf, buf, buflen);
kfree(ioctlbuf);
return (error);
}
/*
get named driver variable to int value and return error indication
calling example: dev_wlc_intvar_get(dev, "arate", &rate)
*/
static int
dev_wlc_intvar_get(
struct net_device *dev,
char *name,
int *retval)
{
union {
char buf[WLC_IOCTL_SMLEN];
int val;
} var;
int error;
uint len;
uint data_null;
len = bcm_mkiovar(name, (char *)(&data_null), 0, (char *)(&var), sizeof(var.buf));
ASSERT(len);
error = dev_wlc_ioctl(dev, WLC_GET_VAR, (void *)&var, len);
*retval = dtoh32(var.val);
return (error);
}
/* Maintain backward compatibility */
#if WIRELESS_EXT < 13
struct iw_request_info
{
__u16 cmd; /* Wireless Extension command */
__u16 flags; /* More to come ;-) */
};
typedef int (*iw_handler)(struct net_device *dev, struct iw_request_info *info,
void *wrqu, char *extra);
#endif /* WIRELESS_EXT < 13 */
#if WIRELESS_EXT > 12
static int
wl_iw_set_leddc(
struct net_device *dev,
struct iw_request_info *info,
union iwreq_data *wrqu,
char *extra
)
{
int dc = *(int *)extra;
int error;
error = dev_wlc_intvar_set(dev, "leddc", dc);
return error;
}
static int
wl_iw_set_vlanmode(
struct net_device *dev,
struct iw_request_info *info,
union iwreq_data *wrqu,
char *extra
)
{
int mode = *(int *)extra;
int error;
mode = htod32(mode);
error = dev_wlc_intvar_set(dev, "vlan_mode", mode);
return error;
}
static int
wl_iw_set_pm(
struct net_device *dev,
struct iw_request_info *info,
union iwreq_data *wrqu,
char *extra
)
{
int pm = *(int *)extra;
int error;
pm = htod32(pm);
error = dev_wlc_ioctl(dev, WLC_SET_PM, &pm, sizeof(pm));
return error;
}
#if WIRELESS_EXT > 17
#endif /* WIRELESS_EXT > 17 */
#endif /* WIRELESS_EXT > 12 */
int
wl_iw_send_priv_event(
struct net_device *dev,
char *flag
)
{
union iwreq_data wrqu;
char extra[IW_CUSTOM_MAX + 1];
int cmd;
cmd = IWEVCUSTOM;
memset(&wrqu, 0, sizeof(wrqu));
if (strlen(flag) > sizeof(extra))
return -1;
strcpy(extra, flag);
wrqu.data.length = strlen(extra);
wireless_send_event(dev, cmd, &wrqu, extra);
WL_TRACE(("Send IWEVCUSTOM Event as %s\n", extra));
return 0;
}
static int
wl_iw_config_commit(
struct net_device *dev,
struct iw_request_info *info,
void *zwrq,
char *extra
)
{
wlc_ssid_t ssid;
int error;
struct sockaddr bssid;
WL_TRACE(("%s: SIOCSIWCOMMIT\n", dev->name));
if ((error = dev_wlc_ioctl(dev, WLC_GET_SSID, &ssid, sizeof(ssid))))
return error;
ssid.SSID_len = dtoh32(ssid.SSID_len);
if (!ssid.SSID_len)
return 0;
bzero(&bssid, sizeof(struct sockaddr));
if ((error = dev_wlc_ioctl(dev, WLC_REASSOC, &bssid, ETHER_ADDR_LEN))) {
WL_ERROR(("%s: WLC_REASSOC failed (%d)\n", __FUNCTION__, error));
return error;
}
return 0;
}
static int
wl_iw_get_name(
struct net_device *dev,
struct iw_request_info *info,
union iwreq_data *cwrq,
char *extra
)
{
int phytype, err;
uint band[3];
char cap[5];
WL_TRACE(("%s: SIOCGIWNAME\n", dev->name));
cap[0] = 0;
if ((err = dev_wlc_ioctl(dev, WLC_GET_PHYTYPE, &phytype, sizeof(phytype))) < 0)
goto done;
if ((err = dev_wlc_ioctl(dev, WLC_GET_BANDLIST, band, sizeof(band))) < 0)
goto done;
band[0] = dtoh32(band[0]);
switch (phytype) {
case WLC_PHY_TYPE_A:
strcpy(cap, "a");
break;
case WLC_PHY_TYPE_B:
strcpy(cap, "b");
break;
case WLC_PHY_TYPE_LP:
case WLC_PHY_TYPE_G:
if (band[0] >= 2)
strcpy(cap, "abg");
else
strcpy(cap, "bg");
break;
case WLC_PHY_TYPE_N:
if (band[0] >= 2)
strcpy(cap, "abgn");
else
strcpy(cap, "bgn");
break;
}
done:
snprintf(cwrq->name, IFNAMSIZ, "IEEE 802.11%s", cap);
return 0;
}
static int
wl_iw_set_freq(
struct net_device *dev,
struct iw_request_info *info,
struct iw_freq *fwrq,
char *extra
)
{
int error, chan;
uint sf = 0;
WL_TRACE(("%s: SIOCSIWFREQ\n", dev->name));
/* Setting by channel number */
if (fwrq->e == 0 && fwrq->m < MAXCHANNEL) {
chan = fwrq->m;
}
/* Setting by frequency */
else {
/* Convert to MHz as best we can */
if (fwrq->e >= 6) {
fwrq->e -= 6;
while (fwrq->e--)
fwrq->m *= 10;
} else if (fwrq->e < 6) {
while (fwrq->e++ < 6)
fwrq->m /= 10;
}
/* handle 4.9GHz frequencies as Japan 4 GHz based channelization */
if (fwrq->m > 4000 && fwrq->m < 5000)
sf = WF_CHAN_FACTOR_4_G; /* start factor for 4 GHz */
chan = wf_mhz2channel(fwrq->m, sf);
}
chan = htod32(chan);
if ((error = dev_wlc_ioctl(dev, WLC_SET_CHANNEL, &chan, sizeof(chan))))
return error;
/* -EINPROGRESS: Call commit handler */
return -EINPROGRESS;
}
static int
wl_iw_get_freq(
struct net_device *dev,
struct iw_request_info *info,
struct iw_freq *fwrq,
char *extra
)
{
channel_info_t ci;
int error;
WL_TRACE(("%s: SIOCGIWFREQ\n", dev->name));
if ((error = dev_wlc_ioctl(dev, WLC_GET_CHANNEL, &ci, sizeof(ci))))
return error;
/* Return radio channel in channel form */
fwrq->m = dtoh32(ci.hw_channel);
fwrq->e = dtoh32(0);
return 0;
}
static int
wl_iw_set_mode(
struct net_device *dev,
struct iw_request_info *info,
__u32 *uwrq,
char *extra
)
{
int infra = 0, ap = 0, error = 0;
WL_TRACE(("%s: SIOCSIWMODE\n", dev->name));
switch (*uwrq) {
case IW_MODE_MASTER:
infra = ap = 1;
break;
case IW_MODE_ADHOC:
case IW_MODE_AUTO:
break;
case IW_MODE_INFRA:
infra = 1;
break;
default:
return -EINVAL;
}
infra = htod32(infra);
ap = htod32(ap);
if ((error = dev_wlc_ioctl(dev, WLC_SET_INFRA, &infra, sizeof(infra))) ||
(error = dev_wlc_ioctl(dev, WLC_SET_AP, &ap, sizeof(ap))))
return error;
/* -EINPROGRESS: Call commit handler */
return -EINPROGRESS;
}
static int
wl_iw_get_mode(
struct net_device *dev,
struct iw_request_info *info,
__u32 *uwrq,
char *extra
)
{
int error, infra = 0, ap = 0;
WL_TRACE(("%s: SIOCGIWMODE\n", dev->name));
if ((error = dev_wlc_ioctl(dev, WLC_GET_INFRA, &infra, sizeof(infra))) ||
(error = dev_wlc_ioctl(dev, WLC_GET_AP, &ap, sizeof(ap))))
return error;
infra = dtoh32(infra);
ap = dtoh32(ap);
*uwrq = infra ? ap ? IW_MODE_MASTER : IW_MODE_INFRA : IW_MODE_ADHOC;
return 0;
}
static int
wl_iw_get_range(
struct net_device *dev,
struct iw_request_info *info,
struct iw_point *dwrq,
char *extra
)
{
struct iw_range *range = (struct iw_range *) extra;
static int channels[MAXCHANNEL+1];
wl_uint32_list_t *list = (wl_uint32_list_t *) channels;
wl_rateset_t rateset;
int error, i, k;
uint sf, ch;
int phytype;
int bw_cap = 0, sgi_tx = 0, nmode = 0;
channel_info_t ci;
uint8 nrate_list2copy = 0;
uint16 nrate_list[4][8] = { {13, 26, 39, 52, 78, 104, 117, 130},
{14, 29, 43, 58, 87, 116, 130, 144},
{27, 54, 81, 108, 162, 216, 243, 270},
{30, 60, 90, 120, 180, 240, 270, 300}};
int fbt_cap = 0;
WL_TRACE(("%s: SIOCGIWRANGE\n", dev->name));
if (!extra)
return -EINVAL;
dwrq->length = sizeof(struct iw_range);
memset(range, 0, sizeof(*range));
/* We don't use nwids */
range->min_nwid = range->max_nwid = 0;
/* Set available channels/frequencies */
list->count = htod32(MAXCHANNEL);
if ((error = dev_wlc_ioctl(dev, WLC_GET_VALID_CHANNELS, channels, sizeof(channels))))
return error;
for (i = 0; i < dtoh32(list->count) && i < IW_MAX_FREQUENCIES; i++) {
range->freq[i].i = dtoh32(list->element[i]);
ch = dtoh32(list->element[i]);
if (ch <= CH_MAX_2G_CHANNEL)
sf = WF_CHAN_FACTOR_2_4_G;
else
sf = WF_CHAN_FACTOR_5_G;
range->freq[i].m = wf_channel2mhz(ch, sf);
range->freq[i].e = 6;
}
range->num_frequency = range->num_channels = i;
/* Link quality (use NDIS cutoffs) */
range->max_qual.qual = 5;
/* Signal level (use RSSI) */
range->max_qual.level = 0x100 - 200; /* -200 dBm */
/* Noise level (use noise) */
range->max_qual.noise = 0x100 - 200; /* -200 dBm */
/* Signal level threshold range (?) */
range->sensitivity = 65535;
#if WIRELESS_EXT > 11
/* Link quality (use NDIS cutoffs) */
range->avg_qual.qual = 3;
/* Signal level (use RSSI) */
range->avg_qual.level = 0x100 + WL_IW_RSSI_GOOD;
/* Noise level (use noise) */
range->avg_qual.noise = 0x100 - 75; /* -75 dBm */
#endif /* WIRELESS_EXT > 11 */
/* Set available bitrates */
if ((error = dev_wlc_ioctl(dev, WLC_GET_CURR_RATESET, &rateset, sizeof(rateset))))
return error;
rateset.count = dtoh32(rateset.count);
range->num_bitrates = rateset.count;
for (i = 0; i < rateset.count && i < IW_MAX_BITRATES; i++)
range->bitrate[i] = (rateset.rates[i] & 0x7f) * 500000; /* convert to bps */
if ((error = dev_wlc_intvar_get(dev, "nmode", &nmode)))
return error;
if ((error = dev_wlc_ioctl(dev, WLC_GET_PHYTYPE, &phytype, sizeof(phytype))))
return error;
if (nmode == 1 && ((phytype == WLC_PHY_TYPE_SSN) || (phytype == WLC_PHY_TYPE_LCN) ||
(phytype == WLC_PHY_TYPE_LCN40))) {
if ((error = dev_wlc_intvar_get(dev, "mimo_bw_cap", &bw_cap)))
return error;
if ((error = dev_wlc_intvar_get(dev, "sgi_tx", &sgi_tx)))
return error;
if ((error = dev_wlc_ioctl(dev, WLC_GET_CHANNEL, &ci, sizeof(channel_info_t))))
return error;
ci.hw_channel = dtoh32(ci.hw_channel);
if (bw_cap == 0 ||
(bw_cap == 2 && ci.hw_channel <= 14)) {
if (sgi_tx == 0)
nrate_list2copy = 0;
else
nrate_list2copy = 1;
}
if (bw_cap == 1 ||
(bw_cap == 2 && ci.hw_channel >= 36)) {
if (sgi_tx == 0)
nrate_list2copy = 2;
else
nrate_list2copy = 3;
}
range->num_bitrates += 8;
ASSERT(range->num_bitrates < IW_MAX_BITRATES);
for (k = 0; i < range->num_bitrates; k++, i++) {
/* convert to bps */
range->bitrate[i] = (nrate_list[nrate_list2copy][k]) * 500000;
}
}
/* Set an indication of the max TCP throughput
* in bit/s that we can expect using this interface.
* May be use for QoS stuff... Jean II
*/
if ((error = dev_wlc_ioctl(dev, WLC_GET_PHYTYPE, &i, sizeof(i))))
return error;
i = dtoh32(i);
if (i == WLC_PHY_TYPE_A)
range->throughput = 24000000; /* 24 Mbits/s */
else
range->throughput = 1500000; /* 1.5 Mbits/s */
/* RTS and fragmentation thresholds */
range->min_rts = 0;
range->max_rts = 2347;
range->min_frag = 256;
range->max_frag = 2346;
range->max_encoding_tokens = DOT11_MAX_DEFAULT_KEYS;
range->num_encoding_sizes = 4;
range->encoding_size[0] = WEP1_KEY_SIZE;
range->encoding_size[1] = WEP128_KEY_SIZE;
#if WIRELESS_EXT > 17
range->encoding_size[2] = TKIP_KEY_SIZE;
#else
range->encoding_size[2] = 0;
#endif
range->encoding_size[3] = AES_KEY_SIZE;
/* Do not support power micro-management */
range->min_pmp = 0;
range->max_pmp = 0;
range->min_pmt = 0;
range->max_pmt = 0;
range->pmp_flags = 0;
range->pm_capa = 0;
/* Transmit Power - values are in mW */
range->num_txpower = 2;
range->txpower[0] = 1;
range->txpower[1] = 255;
range->txpower_capa = IW_TXPOW_MWATT;
#if WIRELESS_EXT > 10
range->we_version_compiled = WIRELESS_EXT;
range->we_version_source = 19;
/* Only support retry limits */
range->retry_capa = IW_RETRY_LIMIT;
range->retry_flags = IW_RETRY_LIMIT;
range->r_time_flags = 0;
/* SRL and LRL limits */
range->min_retry = 1;
range->max_retry = 255;
/* Retry lifetime limits unsupported */
range->min_r_time = 0;
range->max_r_time = 0;
#endif /* WIRELESS_EXT > 10 */
#if WIRELESS_EXT > 17
range->enc_capa = IW_ENC_CAPA_WPA;
range->enc_capa |= IW_ENC_CAPA_CIPHER_TKIP;
range->enc_capa |= IW_ENC_CAPA_CIPHER_CCMP;
range->enc_capa |= IW_ENC_CAPA_WPA2;
/* Determine driver FBT capability. */
if (dev_wlc_intvar_get(dev, "fbt_cap", &fbt_cap) == 0) {
if (fbt_cap == WLC_FBT_CAP_DRV_4WAY_AND_REASSOC) {
/* Tell the host (e.g. wpa_supplicant) to let driver do the handshake */
range->enc_capa |= IW_ENC_CAPA_4WAY_HANDSHAKE;
}
}
#ifdef BCMFW_ROAM_ENABLE_WEXT
/* Advertise firmware roam capability to the external supplicant */
range->enc_capa |= IW_ENC_CAPA_FW_ROAM_ENABLE;
#endif /* BCMFW_ROAM_ENABLE_WEXT */
/* Event capability (kernel) */
IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
/* Event capability (driver) */
IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
IW_EVENT_CAPA_SET(range->event_capa, IWEVMICHAELMICFAILURE);
IW_EVENT_CAPA_SET(range->event_capa, IWEVASSOCREQIE);
IW_EVENT_CAPA_SET(range->event_capa, IWEVASSOCRESPIE);
IW_EVENT_CAPA_SET(range->event_capa, IWEVPMKIDCAND);
#if WIRELESS_EXT >= 22 && defined(IW_SCAN_CAPA_ESSID)
/* FC7 wireless.h defines EXT 22 but doesn't define scan_capa bits */
range->scan_capa = IW_SCAN_CAPA_ESSID;
#endif
#endif /* WIRELESS_EXT > 17 */
return 0;
}
static int
rssi_to_qual(int rssi)
{
if (rssi <= WL_IW_RSSI_NO_SIGNAL)
return 0;
else if (rssi <= WL_IW_RSSI_VERY_LOW)
return 1;
else if (rssi <= WL_IW_RSSI_LOW)
return 2;
else if (rssi <= WL_IW_RSSI_GOOD)
return 3;
else if (rssi <= WL_IW_RSSI_VERY_GOOD)
return 4;
else
return 5;
}
static int
wl_iw_set_spy(
struct net_device *dev,
struct iw_request_info *info,
struct iw_point *dwrq,
char *extra
)
{
wl_iw_t *iw = IW_DEV_IF(dev);
struct sockaddr *addr = (struct sockaddr *) extra;
int i;
WL_TRACE(("%s: SIOCSIWSPY\n", dev->name));
if (!extra)
return -EINVAL;
iw->spy_num = MIN(ARRAYSIZE(iw->spy_addr), dwrq->length);
for (i = 0; i < iw->spy_num; i++)
memcpy(&iw->spy_addr[i], addr[i].sa_data, ETHER_ADDR_LEN);
memset(iw->spy_qual, 0, sizeof(iw->spy_qual));
return 0;
}
static int
wl_iw_get_spy(
struct net_device *dev,
struct iw_request_info *info,
struct iw_point *dwrq,
char *extra
)
{
wl_iw_t *iw = IW_DEV_IF(dev);
struct sockaddr *addr = (struct sockaddr *) extra;
struct iw_quality *qual = (struct iw_quality *) &addr[iw->spy_num];
int i;
WL_TRACE(("%s: SIOCGIWSPY\n", dev->name));
if (!extra)
return -EINVAL;
dwrq->length = iw->spy_num;
for (i = 0; i < iw->spy_num; i++) {
memcpy(addr[i].sa_data, &iw->spy_addr[i], ETHER_ADDR_LEN);
addr[i].sa_family = AF_UNIX;
memcpy(&qual[i], &iw->spy_qual[i], sizeof(struct iw_quality));
iw->spy_qual[i].updated = 0;
}
return 0;
}
static int
wl_iw_set_wap(
struct net_device *dev,
struct iw_request_info *info,
struct sockaddr *awrq,
char *extra
)
{
int error = -EINVAL;
WL_TRACE(("%s: SIOCSIWAP\n", dev->name));
if (awrq->sa_family != ARPHRD_ETHER) {
WL_ERROR(("%s: Invalid Header...sa_family\n", __FUNCTION__));
return -EINVAL;
}
/* Ignore "auto" or "off" */
if (ETHER_ISBCAST(awrq->sa_data) || ETHER_ISNULLADDR(awrq->sa_data)) {
scb_val_t scbval;
bzero(&scbval, sizeof(scb_val_t));
if ((error = dev_wlc_ioctl(dev, WLC_DISASSOC, &scbval, sizeof(scb_val_t)))) {
WL_ERROR(("%s: WLC_DISASSOC failed (%d).\n", __FUNCTION__, error));
}
return 0;
}
/* WL_ASSOC(("Assoc to %s\n", bcm_ether_ntoa((struct ether_addr *)&(awrq->sa_data),
* eabuf)));
*/
/* Reassociate to the specified AP */
if ((error = dev_wlc_ioctl(dev, WLC_REASSOC, awrq->sa_data, ETHER_ADDR_LEN))) {
WL_ERROR(("%s: WLC_REASSOC failed (%d).\n", __FUNCTION__, error));
return error;
}
return 0;
}
static int
wl_iw_get_wap(
struct net_device *dev,
struct iw_request_info *info,
struct sockaddr *awrq,
char *extra
)
{
WL_TRACE(("%s: SIOCGIWAP\n", dev->name));
awrq->sa_family = ARPHRD_ETHER;
memset(awrq->sa_data, 0, ETHER_ADDR_LEN);
/* Ignore error (may be down or disassociated) */
(void) dev_wlc_ioctl(dev, WLC_GET_BSSID, awrq->sa_data, ETHER_ADDR_LEN);
return 0;
}
#if WIRELESS_EXT > 17
static int
wl_iw_mlme(
struct net_device *dev,
struct iw_request_info *info,
struct sockaddr *awrq,
char *extra
)
{
struct iw_mlme *mlme;
scb_val_t scbval;
int error = -EINVAL;
WL_TRACE(("%s: SIOCSIWMLME\n", dev->name));
mlme = (struct iw_mlme *)extra;
if (mlme == NULL) {
WL_ERROR(("Invalid ioctl data.\n"));
return error;
}
scbval.val = mlme->reason_code;
bcopy(&mlme->addr.sa_data, &scbval.ea, ETHER_ADDR_LEN);
if (mlme->cmd == IW_MLME_DISASSOC) {
scbval.val = htod32(scbval.val);
error = dev_wlc_ioctl(dev, WLC_DISASSOC, &scbval, sizeof(scb_val_t));
}
else if (mlme->cmd == IW_MLME_DEAUTH) {
scbval.val = htod32(scbval.val);
error = dev_wlc_ioctl(dev, WLC_SCB_DEAUTHENTICATE_FOR_REASON, &scbval,
sizeof(scb_val_t));
}
else {
WL_ERROR(("%s: Invalid ioctl data.\n", __FUNCTION__));
return error;
}
return error;
}
#endif /* WIRELESS_EXT > 17 */
static int
wl_iw_get_aplist(
struct net_device *dev,
struct iw_request_info *info,
struct iw_point *dwrq,
char *extra
)
{
wl_scan_results_t *list;
struct sockaddr *addr = (struct sockaddr *) extra;
struct iw_quality qual[IW_MAX_AP];
wl_bss_info_t *bi = NULL;
int error, i;
uint buflen = dwrq->length;
WL_TRACE(("%s: SIOCGIWAPLIST\n", dev->name));
if (!extra)
return -EINVAL;
/* Get scan results (too large to put on the stack) */
list = kmalloc(buflen, GFP_KERNEL);
if (!list)
return -ENOMEM;
memset(list, 0, buflen);
list->buflen = htod32(buflen);
if ((error = dev_wlc_ioctl(dev, WLC_SCAN_RESULTS, list, buflen))) {
WL_ERROR(("%d: Scan results error %d\n", __LINE__, error));
kfree(list);
return error;
}
list->buflen = dtoh32(list->buflen);
list->version = dtoh32(list->version);
list->count = dtoh32(list->count);
ASSERT(list->version == WL_BSS_INFO_VERSION);
for (i = 0, dwrq->length = 0; i < list->count && dwrq->length < IW_MAX_AP; i++) {
bi = bi ? (wl_bss_info_t *)((uintptr)bi + dtoh32(bi->length)) : list->bss_info;
ASSERT(((uintptr)bi + dtoh32(bi->length)) <= ((uintptr)list +
buflen));
/* Infrastructure only */
if (!(dtoh16(bi->capability) & DOT11_CAP_ESS))
continue;
/* BSSID */
memcpy(addr[dwrq->length].sa_data, &bi->BSSID, ETHER_ADDR_LEN);
addr[dwrq->length].sa_family = ARPHRD_ETHER;
qual[dwrq->length].qual = rssi_to_qual(dtoh16(bi->RSSI));
qual[dwrq->length].level = 0x100 + dtoh16(bi->RSSI);
qual[dwrq->length].noise = 0x100 + bi->phy_noise;
/* Updated qual, level, and noise */
#if WIRELESS_EXT > 18
qual[dwrq->length].updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
#else
qual[dwrq->length].updated = 7;
#endif /* WIRELESS_EXT > 18 */
dwrq->length++;
}
kfree(list);
if (dwrq->length) {
memcpy(&addr[dwrq->length], qual, sizeof(struct iw_quality) * dwrq->length);
/* Provided qual */
dwrq->flags = 1;
}
return 0;
}
static int
wl_iw_iscan_get_aplist(
struct net_device *dev,
struct iw_request_info *info,
struct iw_point *dwrq,
char *extra
)
{
wl_scan_results_t *list;
iscan_buf_t * buf;
iscan_info_t *iscan = g_iscan;
struct sockaddr *addr = (struct sockaddr *) extra;
struct iw_quality qual[IW_MAX_AP];
wl_bss_info_t *bi = NULL;
int i;
WL_TRACE(("%s: SIOCGIWAPLIST\n", dev->name));
if (!extra)
return -EINVAL;
if ((!iscan) || (iscan->sysioc_pid < 0)) {
return wl_iw_get_aplist(dev, info, dwrq, extra);
}
buf = iscan->list_hdr;
/* Get scan results (too large to put on the stack) */
while (buf) {
list = &((wl_iscan_results_t*)buf->iscan_buf)->results;
ASSERT(list->version == WL_BSS_INFO_VERSION);
bi = NULL;
for (i = 0, dwrq->length = 0; i < list->count && dwrq->length < IW_MAX_AP; i++) {
bi = bi ? (wl_bss_info_t *)((uintptr)bi + dtoh32(bi->length)) : list->bss_info;
ASSERT(((uintptr)bi + dtoh32(bi->length)) <= ((uintptr)list +
WLC_IW_ISCAN_MAXLEN));
/* Infrastructure only */
if (!(dtoh16(bi->capability) & DOT11_CAP_ESS))
continue;
/* BSSID */
memcpy(addr[dwrq->length].sa_data, &bi->BSSID, ETHER_ADDR_LEN);
addr[dwrq->length].sa_family = ARPHRD_ETHER;
qual[dwrq->length].qual = rssi_to_qual(dtoh16(bi->RSSI));
qual[dwrq->length].level = 0x100 + dtoh16(bi->RSSI);
qual[dwrq->length].noise = 0x100 + bi->phy_noise;
/* Updated qual, level, and noise */
#if WIRELESS_EXT > 18
qual[dwrq->length].updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
#else
qual[dwrq->length].updated = 7;
#endif /* WIRELESS_EXT > 18 */
dwrq->length++;
}
buf = buf->next;
}
if (dwrq->length) {
memcpy(&addr[dwrq->length], qual, sizeof(struct iw_quality) * dwrq->length);
/* Provided qual */
dwrq->flags = 1;
}
return 0;
}
#if WIRELESS_EXT > 13
static int
wl_iw_set_scan(
struct net_device *dev,
struct iw_request_info *info,
union iwreq_data *wrqu,
char *extra
)
{
wlc_ssid_t ssid;
WL_TRACE(("%s: SIOCSIWSCAN\n", dev->name));
/* default Broadcast scan */
memset(&ssid, 0, sizeof(ssid));
#if WIRELESS_EXT > 17
/* check for given essid */
if (wrqu->data.length == sizeof(struct iw_scan_req)) {
if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
struct iw_scan_req *req = (struct iw_scan_req *)extra;
ssid.SSID_len = MIN(sizeof(ssid.SSID), req->essid_len);
memcpy(ssid.SSID, req->essid, ssid.SSID_len);
ssid.SSID_len = htod32(ssid.SSID_len);
}
}
#endif
/* Ignore error (most likely scan in progress) */
(void) dev_wlc_ioctl(dev, WLC_SCAN, &ssid, sizeof(ssid));
return 0;
}
static int
wl_iw_iscan_set_scan(
struct net_device *dev,
struct iw_request_info *info,
union iwreq_data *wrqu,
char *extra
)
{
wlc_ssid_t ssid;
iscan_info_t *iscan = g_iscan;
WL_TRACE(("%s: SIOCSIWSCAN\n", dev->name));
/* use backup if our thread is not successful */
if ((!iscan) || (iscan->sysioc_pid < 0)) {
return wl_iw_set_scan(dev, info, wrqu, extra);
}
if (iscan->iscan_state == ISCAN_STATE_SCANING) {
return 0;
}
/* default Broadcast scan */
memset(&ssid, 0, sizeof(ssid));
#if WIRELESS_EXT > 17
/* check for given essid */
if (wrqu->data.length == sizeof(struct iw_scan_req)) {
if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
struct iw_scan_req *req = (struct iw_scan_req *)extra;
ssid.SSID_len = MIN(sizeof(ssid.SSID), req->essid_len);
memcpy(ssid.SSID, req->essid, ssid.SSID_len);
ssid.SSID_len = htod32(ssid.SSID_len);
}
}
#endif
iscan->list_cur = iscan->list_hdr;
iscan->iscan_state = ISCAN_STATE_SCANING;
wl_iw_set_event_mask(dev);
wl_iw_iscan(iscan, &ssid, WL_SCAN_ACTION_START);
iscan->timer.expires = jiffies + msecs_to_jiffies(iscan->timer_ms);
add_timer(&iscan->timer);
iscan->timer_on = 1;
return 0;
}
#if WIRELESS_EXT > 17
static bool
ie_is_wpa_ie(uint8 **wpaie, uint8 **tlvs, int *tlvs_len)
{
/* Is this body of this tlvs entry a WPA entry? If */
/* not update the tlvs buffer pointer/length */
uint8 *ie = *wpaie;
/* If the contents match the WPA_OUI and type=1 */
if ((ie[1] >= 6) &&
!bcmp((const void *)&ie[2], (const void *)(WPA_OUI "\x01"), 4)) {
return TRUE;
}
/* point to the next ie */
ie += ie[1] + 2;
/* calculate the length of the rest of the buffer */
*tlvs_len -= (int)(ie - *tlvs);
/* update the pointer to the start of the buffer */
*tlvs = ie;
return FALSE;
}
static bool
ie_is_wps_ie(uint8 **wpsie, uint8 **tlvs, int *tlvs_len)
{
/* Is this body of this tlvs entry a WPS entry? If */
/* not update the tlvs buffer pointer/length */
uint8 *ie = *wpsie;
/* If the contents match the WPA_OUI and type=4 */
if ((ie[1] >= 4) &&
!bcmp((const void *)&ie[2], (const void *)(WPA_OUI "\x04"), 4)) {
return TRUE;
}
/* point to the next ie */
ie += ie[1] + 2;
/* calculate the length of the rest of the buffer */
*tlvs_len -= (int)(ie - *tlvs);
/* update the pointer to the start of the buffer */
*tlvs = ie;
return FALSE;
}
#endif /* WIRELESS_EXT > 17 */
static int
wl_iw_handle_scanresults_ies(char **event_p, char *end,
struct iw_request_info *info, wl_bss_info_t *bi)
{
#if WIRELESS_EXT > 17
struct iw_event iwe;
char *event;
event = *event_p;
if (bi->ie_length) {
/* look for wpa/rsn ies in the ie list... */
bcm_tlv_t *ie;
uint8 *ptr = ((uint8 *)bi) + sizeof(wl_bss_info_t);
int ptr_len = bi->ie_length;
if ((ie = bcm_parse_tlvs(ptr, ptr_len, DOT11_MNG_RSN_ID))) {
iwe.cmd = IWEVGENIE;
iwe.u.data.length = ie->len + 2;
event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, (char *)ie);
}
ptr = ((uint8 *)bi) + sizeof(wl_bss_info_t);
if ((ie = bcm_parse_tlvs(ptr, ptr_len, DOT11_MNG_MDIE_ID))) {
iwe.cmd = IWEVGENIE;
iwe.u.data.length = ie->len + 2;
event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, (char *)ie);
}
ptr = ((uint8 *)bi) + sizeof(wl_bss_info_t);
while ((ie = bcm_parse_tlvs(ptr, ptr_len, DOT11_MNG_WPA_ID))) {
/* look for WPS IE */
if (ie_is_wps_ie(((uint8 **)&ie), &ptr, &ptr_len)) {
iwe.cmd = IWEVGENIE;
iwe.u.data.length = ie->len + 2;
event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, (char *)ie);
break;
}
}
ptr = ((uint8 *)bi) + sizeof(wl_bss_info_t);
ptr_len = bi->ie_length;
while ((ie = bcm_parse_tlvs(ptr, ptr_len, DOT11_MNG_WPA_ID))) {
if (ie_is_wpa_ie(((uint8 **)&ie), &ptr, &ptr_len)) {
iwe.cmd = IWEVGENIE;
iwe.u.data.length = ie->len + 2;
event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, (char *)ie);
break;
}
}
*event_p = event;
}
#endif /* WIRELESS_EXT > 17 */
return 0;
}
static int
wl_iw_get_scan(
struct net_device *dev,
struct iw_request_info *info,
struct iw_point *dwrq,
char *extra
)
{
channel_info_t ci;
wl_scan_results_t *list;
struct iw_event iwe;
wl_bss_info_t *bi = NULL;
int error, i, j;
char *event = extra, *end = extra + dwrq->length, *value;
uint buflen = dwrq->length;
WL_TRACE(("%s: SIOCGIWSCAN\n", dev->name));
if (!extra)
return -EINVAL;
/* Check for scan in progress */
if ((error = dev_wlc_ioctl(dev, WLC_GET_CHANNEL, &ci, sizeof(ci))))
return error;
ci.scan_channel = dtoh32(ci.scan_channel);
if (ci.scan_channel)
return -EAGAIN;
/* Get scan results (too large to put on the stack) */
list = kmalloc(buflen, GFP_KERNEL);
if (!list)
return -ENOMEM;
memset(list, 0, buflen);
list->buflen = htod32(buflen);
if ((error = dev_wlc_ioctl(dev, WLC_SCAN_RESULTS, list, buflen))) {
kfree(list);
return error;
}
list->buflen = dtoh32(list->buflen);
list->version = dtoh32(list->version);
list->count = dtoh32(list->count);
ASSERT(list->version == WL_BSS_INFO_VERSION);
for (i = 0; i < list->count && i < IW_MAX_AP; i++) {
bi = bi ? (wl_bss_info_t *)((uintptr)bi + dtoh32(bi->length)) : list->bss_info;
ASSERT(((uintptr)bi + dtoh32(bi->length)) <= ((uintptr)list +
buflen));
/* First entry must be the BSSID */
iwe.cmd = SIOCGIWAP;
iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
memcpy(iwe.u.ap_addr.sa_data, &bi->BSSID, ETHER_ADDR_LEN);
event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_ADDR_LEN);
/* SSID */
iwe.u.data.length = dtoh32(bi->SSID_len);
iwe.cmd = SIOCGIWESSID;
iwe.u.data.flags = 1;
event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, bi->SSID);
/* Mode */
if (dtoh16(bi->capability) & (DOT11_CAP_ESS | DOT11_CAP_IBSS)) {
iwe.cmd = SIOCGIWMODE;
if (dtoh16(bi->capability) & DOT11_CAP_ESS)
iwe.u.mode = IW_MODE_INFRA;
else
iwe.u.mode = IW_MODE_ADHOC;
event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_UINT_LEN);
}
/* Channel */
iwe.cmd = SIOCGIWFREQ;
iwe.u.freq.m = wf_channel2mhz(CHSPEC_CHANNEL(bi->chanspec),
CHSPEC_CHANNEL(bi->chanspec) <= CH_MAX_2G_CHANNEL ?
WF_CHAN_FACTOR_2_4_G : WF_CHAN_FACTOR_5_G);
iwe.u.freq.e = 6;
event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_FREQ_LEN);
/* Channel quality */
iwe.cmd = IWEVQUAL;
iwe.u.qual.qual = rssi_to_qual(dtoh16(bi->RSSI));
iwe.u.qual.level = 0x100 + dtoh16(bi->RSSI);
iwe.u.qual.noise = 0x100 + bi->phy_noise;
event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_QUAL_LEN);
/* WPA, WPA2, WPS, WAPI IEs */
wl_iw_handle_scanresults_ies(&event, end, info, bi);
/* Encryption */
iwe.cmd = SIOCGIWENCODE;
if (dtoh16(bi->capability) & DOT11_CAP_PRIVACY)
iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
else
iwe.u.data.flags = IW_ENCODE_DISABLED;
iwe.u.data.length = 0;
event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, (char *)event);
/* Rates */
if (bi->rateset.count) {
value = event + IW_EV_LCP_LEN;
iwe.cmd = SIOCGIWRATE;
/* Those two flags are ignored... */
iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
for (j = 0; j < bi->rateset.count && j < IW_MAX_BITRATES; j++) {
iwe.u.bitrate.value = (bi->rateset.rates[j] & 0x7f) * 500000;
value = IWE_STREAM_ADD_VALUE(info, event, value, end, &iwe,
IW_EV_PARAM_LEN);
}
event = value;
}
}
kfree(list);
dwrq->length = event - extra;
dwrq->flags = 0; /* todo */
return 0;
}
static int
wl_iw_iscan_get_scan(
struct net_device *dev,
struct iw_request_info *info,
struct iw_point *dwrq,
char *extra
)
{
wl_scan_results_t *list;
struct iw_event iwe;
wl_bss_info_t *bi = NULL;
int ii, j;
int apcnt;
char *event = extra, *end = extra + dwrq->length, *value;
iscan_info_t *iscan = g_iscan;
iscan_buf_t * p_buf;
WL_TRACE(("%s: SIOCGIWSCAN\n", dev->name));
if (!extra)
return -EINVAL;
/* use backup if our thread is not successful */
if ((!iscan) || (iscan->sysioc_pid < 0)) {
return wl_iw_get_scan(dev, info, dwrq, extra);
}
/* Check for scan in progress */
if (iscan->iscan_state == ISCAN_STATE_SCANING)
return -EAGAIN;
apcnt = 0;
p_buf = iscan->list_hdr;
/* Get scan results */
while (p_buf != iscan->list_cur) {
list = &((wl_iscan_results_t*)p_buf->iscan_buf)->results;
if (list->version != WL_BSS_INFO_VERSION) {
WL_ERROR(("list->version %d != WL_BSS_INFO_VERSION\n", list->version));
}
bi = NULL;
for (ii = 0; ii < list->count && apcnt < IW_MAX_AP; apcnt++, ii++) {
bi = bi ? (wl_bss_info_t *)((uintptr)bi + dtoh32(bi->length)) : list->bss_info;
ASSERT(((uintptr)bi + dtoh32(bi->length)) <= ((uintptr)list +
WLC_IW_ISCAN_MAXLEN));
/* overflow check cover fields before wpa IEs */
if (event + ETHER_ADDR_LEN + bi->SSID_len + IW_EV_UINT_LEN + IW_EV_FREQ_LEN +
IW_EV_QUAL_LEN >= end)
return -E2BIG;
/* First entry must be the BSSID */
iwe.cmd = SIOCGIWAP;
iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
memcpy(iwe.u.ap_addr.sa_data, &bi->BSSID, ETHER_ADDR_LEN);
event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_ADDR_LEN);
/* SSID */
iwe.u.data.length = dtoh32(bi->SSID_len);
iwe.cmd = SIOCGIWESSID;
iwe.u.data.flags = 1;
event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, bi->SSID);
/* Mode */
if (dtoh16(bi->capability) & (DOT11_CAP_ESS | DOT11_CAP_IBSS)) {
iwe.cmd = SIOCGIWMODE;
if (dtoh16(bi->capability) & DOT11_CAP_ESS)
iwe.u.mode = IW_MODE_INFRA;
else
iwe.u.mode = IW_MODE_ADHOC;
event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_UINT_LEN);
}
/* Channel */
iwe.cmd = SIOCGIWFREQ;
iwe.u.freq.m = wf_channel2mhz(CHSPEC_CHANNEL(bi->chanspec),
CHSPEC_CHANNEL(bi->chanspec) <= CH_MAX_2G_CHANNEL ?
WF_CHAN_FACTOR_2_4_G : WF_CHAN_FACTOR_5_G);
iwe.u.freq.e = 6;
event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_FREQ_LEN);
/* Channel quality */
iwe.cmd = IWEVQUAL;
iwe.u.qual.qual = rssi_to_qual(dtoh16(bi->RSSI));
iwe.u.qual.level = 0x100 + dtoh16(bi->RSSI);
iwe.u.qual.noise = 0x100 + bi->phy_noise;
event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_QUAL_LEN);
/* WPA, WPA2, WPS, WAPI IEs */
wl_iw_handle_scanresults_ies(&event, end, info, bi);
/* Encryption */
iwe.cmd = SIOCGIWENCODE;
if (dtoh16(bi->capability) & DOT11_CAP_PRIVACY)
iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
else
iwe.u.data.flags = IW_ENCODE_DISABLED;
iwe.u.data.length = 0;
event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, (char *)event);
/* Rates */
if (bi->rateset.count <= sizeof(bi->rateset.rates)) {
if (event + IW_MAX_BITRATES*IW_EV_PARAM_LEN >= end)
return -E2BIG;
value = event + IW_EV_LCP_LEN;
iwe.cmd = SIOCGIWRATE;
/* Those two flags are ignored... */
iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
for (j = 0; j < bi->rateset.count && j < IW_MAX_BITRATES; j++) {
iwe.u.bitrate.value = (bi->rateset.rates[j] & 0x7f) * 500000;
value = IWE_STREAM_ADD_VALUE(info, event, value, end, &iwe,
IW_EV_PARAM_LEN);
}
event = value;
}
}
p_buf = p_buf->next;
} /* while (p_buf) */
dwrq->length = event - extra;
dwrq->flags = 0; /* todo */
return 0;
}
#endif /* WIRELESS_EXT > 13 */
static int
wl_iw_set_essid(
struct net_device *dev,
struct iw_request_info *info,
struct iw_point *dwrq,
char *extra
)
{
wlc_ssid_t ssid;
int error;
WL_TRACE(("%s: SIOCSIWESSID\n", dev->name));
/* default Broadcast SSID */
memset(&ssid, 0, sizeof(ssid));
if (dwrq->length && extra) {
#if WIRELESS_EXT > 20
ssid.SSID_len = MIN(sizeof(ssid.SSID), dwrq->length);
#else
ssid.SSID_len = MIN(sizeof(ssid.SSID), dwrq->length-1);
#endif
memcpy(ssid.SSID, extra, ssid.SSID_len);
ssid.SSID_len = htod32(ssid.SSID_len);
if ((error = dev_wlc_ioctl(dev, WLC_SET_SSID, &ssid, sizeof(ssid))))
return error;
}
/* If essid null then it is "iwconfig <interface> essid off" command */
else {
scb_val_t scbval;
bzero(&scbval, sizeof(scb_val_t));
if ((error = dev_wlc_ioctl(dev, WLC_DISASSOC, &scbval, sizeof(scb_val_t))))
return error;
}
return 0;
}
static int
wl_iw_get_essid(
struct net_device *dev,
struct iw_request_info *info,
struct iw_point *dwrq,
char *extra
)
{
wlc_ssid_t ssid;
int error;
WL_TRACE(("%s: SIOCGIWESSID\n", dev->name));
if (!extra)
return -EINVAL;
if ((error = dev_wlc_ioctl(dev, WLC_GET_SSID, &ssid, sizeof(ssid)))) {
WL_ERROR(("Error getting the SSID\n"));
return error;
}
ssid.SSID_len = dtoh32(ssid.SSID_len);
/* Get the current SSID */
memcpy(extra, ssid.SSID, ssid.SSID_len);
dwrq->length = ssid.SSID_len;
dwrq->flags = 1; /* active */
return 0;
}
static int
wl_iw_set_nick(
struct net_device *dev,
struct iw_request_info *info,
struct iw_point *dwrq,
char *extra
)
{
wl_iw_t *iw = IW_DEV_IF(dev);
WL_TRACE(("%s: SIOCSIWNICKN\n", dev->name));
if (!extra)
return -EINVAL;
/* Check the size of the string */
if (dwrq->length > sizeof(iw->nickname))
return -E2BIG;
memcpy(iw->nickname, extra, dwrq->length);
iw->nickname[dwrq->length - 1] = '\0';
return 0;
}
static int
wl_iw_get_nick(
struct net_device *dev,
struct iw_request_info *info,
struct iw_point *dwrq,
char *extra
)
{
wl_iw_t *iw = IW_DEV_IF(dev);
WL_TRACE(("%s: SIOCGIWNICKN\n", dev->name));
if (!extra)
return -EINVAL;
strcpy(extra, iw->nickname);
dwrq->length = strlen(extra) + 1;
return 0;
}
static int wl_iw_set_rate(
struct net_device *dev,
struct iw_request_info *info,
struct iw_param *vwrq,
char *extra
)
{
wl_rateset_t rateset;
int error, rate, i, error_bg, error_a;
WL_TRACE(("%s: SIOCSIWRATE\n", dev->name));
/* Get current rateset */
if ((error = dev_wlc_ioctl(dev, WLC_GET_CURR_RATESET, &rateset, sizeof(rateset))))
return error;
rateset.count = dtoh32(rateset.count);
if (vwrq->value < 0) {
/* Select maximum rate */
rate = rateset.rates[rateset.count - 1] & 0x7f;
} else if (vwrq->value < rateset.count) {
/* Select rate by rateset index */
rate = rateset.rates[vwrq->value] & 0x7f;
} else {
/* Specified rate in bps */
rate = vwrq->value / 500000;
}
if (vwrq->fixed) {
/*
Set rate override,
Since the is a/b/g-blind, both a/bg_rate are enforced.
*/
error_bg = dev_wlc_intvar_set(dev, "bg_rate", rate);
error_a = dev_wlc_intvar_set(dev, "a_rate", rate);
if (error_bg && error_a)
return (error_bg | error_a);
} else {
/*
clear rate override
Since the is a/b/g-blind, both a/bg_rate are enforced.
*/
/* 0 is for clearing rate override */
error_bg = dev_wlc_intvar_set(dev, "bg_rate", 0);
/* 0 is for clearing rate override */
error_a = dev_wlc_intvar_set(dev, "a_rate", 0);
if (error_bg && error_a)
return (error_bg | error_a);
/* Remove rates above selected rate */
for (i = 0; i < rateset.count; i++)
if ((rateset.rates[i] & 0x7f) > rate)
break;
rateset.count = htod32(i);
/* Set current rateset */
if ((error = dev_wlc_ioctl(dev, WLC_SET_RATESET, &rateset, sizeof(rateset))))
return error;
}
return 0;
}
static int wl_iw_get_rate(
struct net_device *dev,
struct iw_request_info *info,
struct iw_param *vwrq,
char *extra
)
{
int error, rate;
WL_TRACE(("%s: SIOCGIWRATE\n", dev->name));
/* Report the current tx rate */
if ((error = dev_wlc_ioctl(dev, WLC_GET_RATE, &rate, sizeof(rate))))
return error;
rate = dtoh32(rate);
vwrq->value = rate * 500000;
return 0;
}
static int
wl_iw_set_rts(
struct net_device *dev,
struct iw_request_info *info,
struct iw_param *vwrq,
char *extra
)
{
int error, rts;
WL_TRACE(("%s: SIOCSIWRTS\n", dev->name));
if (vwrq->disabled)
rts = DOT11_DEFAULT_RTS_LEN;
else if (vwrq->value < 0 || vwrq->value > DOT11_DEFAULT_RTS_LEN)
return -EINVAL;
else
rts = vwrq->value;
if ((error = dev_wlc_intvar_set(dev, "rtsthresh", rts)))
return error;
return 0;
}
static int
wl_iw_get_rts(
struct net_device *dev,
struct iw_request_info *info,
struct iw_param *vwrq,
char *extra
)
{
int error, rts;
WL_TRACE(("%s: SIOCGIWRTS\n", dev->name));
if ((error = dev_wlc_intvar_get(dev, "rtsthresh", &rts)))
return error;
vwrq->value = rts;
vwrq->disabled = (rts >= DOT11_DEFAULT_RTS_LEN);
vwrq->fixed = 1;
return 0;
}
static int
wl_iw_set_frag(
struct net_device *dev,
struct iw_request_info *info,
struct iw_param *vwrq,
char *extra
)
{
int error, frag;
WL_TRACE(("%s: SIOCSIWFRAG\n", dev->name));
if (vwrq->disabled)
frag = DOT11_DEFAULT_FRAG_LEN;
else if (vwrq->value < 0 || vwrq->value > DOT11_DEFAULT_FRAG_LEN)
return -EINVAL;
else
frag = vwrq->value;
if ((error = dev_wlc_intvar_set(dev, "fragthresh", frag)))
return error;
return 0;
}
static int
wl_iw_get_frag(
struct net_device *dev,
struct iw_request_info *info,
struct iw_param *vwrq,
char *extra
)
{
int error, fragthreshold;
WL_TRACE(("%s: SIOCGIWFRAG\n", dev->name));
if ((error = dev_wlc_intvar_get(dev, "fragthresh", &fragthreshold)))
return error;
vwrq->value = fragthreshold;
vwrq->disabled = (fragthreshold >= DOT11_DEFAULT_FRAG_LEN);
vwrq->fixed = 1;
return 0;
}
static int
wl_iw_set_txpow(
struct net_device *dev,
struct iw_request_info *info,
struct iw_param *vwrq,
char *extra
)
{
int error, disable;
uint16 txpwrmw;
WL_TRACE(("%s: SIOCSIWTXPOW\n", dev->name));
/* Make sure radio is off or on as far as software is concerned */
disable = vwrq->disabled ? WL_RADIO_SW_DISABLE : 0;
disable += WL_RADIO_SW_DISABLE << 16;
disable = htod32(disable);
if ((error = dev_wlc_ioctl(dev, WLC_SET_RADIO, &disable, sizeof(disable))))
return error;
/* If Radio is off, nothing more to do */
if (disable & WL_RADIO_SW_DISABLE)
return 0;
/* Only handle mW */
if (!(vwrq->flags & IW_TXPOW_MWATT))
return -EINVAL;
/* Value < 0 means just "on" or "off" */
if (vwrq->value < 0)
return 0;
if (vwrq->value > 0xffff) txpwrmw = 0xffff;
else txpwrmw = (uint16)vwrq->value;
error = dev_wlc_intvar_set(dev, "qtxpower", (int)(bcm_mw_to_qdbm(txpwrmw)));
return error;
}
static int
wl_iw_get_txpow(
struct net_device *dev,
struct iw_request_info *info,
struct iw_param *vwrq,
char *extra
)
{
int error, disable, txpwrdbm;
uint8 result;
WL_TRACE(("%s: SIOCGIWTXPOW\n", dev->name));
if ((error = dev_wlc_ioctl(dev, WLC_GET_RADIO, &disable, sizeof(disable))) ||
(error = dev_wlc_intvar_get(dev, "qtxpower", &txpwrdbm)))
return error;
disable = dtoh32(disable);
result = (uint8)(txpwrdbm & ~WL_TXPWR_OVERRIDE);
vwrq->value = (int32)bcm_qdbm_to_mw(result);
vwrq->fixed = 0;
vwrq->disabled = (disable & (WL_RADIO_SW_DISABLE | WL_RADIO_HW_DISABLE)) ? 1 : 0;
vwrq->flags = IW_TXPOW_MWATT;
return 0;
}
#if WIRELESS_EXT > 10
static int
wl_iw_set_retry(
struct net_device *dev,
struct iw_request_info *info,
struct iw_param *vwrq,
char *extra
)
{
int error, lrl, srl;
WL_TRACE(("%s: SIOCSIWRETRY\n", dev->name));
/* Do not handle "off" or "lifetime" */
if (vwrq->disabled || (vwrq->flags & IW_RETRY_LIFETIME))
return -EINVAL;
/* Handle "[min|max] limit" */
if (vwrq->flags & IW_RETRY_LIMIT) {
/* "max limit" or just "limit" */
#if WIRELESS_EXT > 20
if ((vwrq->flags & IW_RETRY_LONG) ||(vwrq->flags & IW_RETRY_MAX) ||
!((vwrq->flags & IW_RETRY_SHORT) || (vwrq->flags & IW_RETRY_MIN))) {
#else
if ((vwrq->flags & IW_RETRY_MAX) || !(vwrq->flags & IW_RETRY_MIN)) {
#endif /* WIRELESS_EXT > 20 */
lrl = htod32(vwrq->value);
if ((error = dev_wlc_ioctl(dev, WLC_SET_LRL, &lrl, sizeof(lrl))))
return error;
}
/* "min limit" or just "limit" */
#if WIRELESS_EXT > 20
if ((vwrq->flags & IW_RETRY_SHORT) ||(vwrq->flags & IW_RETRY_MIN) ||
!((vwrq->flags & IW_RETRY_LONG) || (vwrq->flags & IW_RETRY_MAX))) {
#else
if ((vwrq->flags & IW_RETRY_MIN) || !(vwrq->flags & IW_RETRY_MAX)) {
#endif /* WIRELESS_EXT > 20 */
srl = htod32(vwrq->value);
if ((error = dev_wlc_ioctl(dev, WLC_SET_SRL, &srl, sizeof(srl))))
return error;
}
}
return 0;
}
static int
wl_iw_get_retry(
struct net_device *dev,
struct iw_request_info *info,
struct iw_param *vwrq,
char *extra
)
{
int error, lrl, srl;
WL_TRACE(("%s: SIOCGIWRETRY\n", dev->name));
vwrq->disabled = 0; /* Can't be disabled */
/* Do not handle lifetime queries */
if ((vwrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME)
return -EINVAL;
/* Get retry limits */
if ((error = dev_wlc_ioctl(dev, WLC_GET_LRL, &lrl, sizeof(lrl))) ||
(error = dev_wlc_ioctl(dev, WLC_GET_SRL, &srl, sizeof(srl))))
return error;
lrl = dtoh32(lrl);
srl = dtoh32(srl);
/* Note : by default, display the min retry number */
if (vwrq->flags & IW_RETRY_MAX) {
vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
vwrq->value = lrl;
} else {
vwrq->flags = IW_RETRY_LIMIT;
vwrq->value = srl;
if (srl != lrl)
vwrq->flags |= IW_RETRY_MIN;
}
return 0;
}
#endif /* WIRELESS_EXT > 10 */
static int
wl_iw_set_encode(
struct net_device *dev,
struct iw_request_info *info,
struct iw_point *dwrq,
char *extra
)
{
wl_wsec_key_t key;
int error, val, wsec;
WL_TRACE(("%s: SIOCSIWENCODE\n", dev->name));
memset(&key, 0, sizeof(key));
if ((dwrq->flags & IW_ENCODE_INDEX) == 0) {
/* Find the current key */
for (key.index = 0; key.index < DOT11_MAX_DEFAULT_KEYS; key.index++) {
val = htod32(key.index);
if ((error = dev_wlc_ioctl(dev, WLC_GET_KEY_PRIMARY, &val, sizeof(val))))
return error;
val = dtoh32(val);
if (val)
break;
}
/* Default to 0 */
if (key.index == DOT11_MAX_DEFAULT_KEYS)
key.index = 0;
} else {
key.index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
if (key.index >= DOT11_MAX_DEFAULT_KEYS)
return -EINVAL;
}
/* Interpret "off" to mean no encryption */
wsec = (dwrq->flags & IW_ENCODE_DISABLED) ? 0 : WEP_ENABLED;
if ((error = dev_wlc_intvar_set(dev, "wsec", wsec)))
return error;
/* Old API used to pass a NULL pointer instead of IW_ENCODE_NOKEY */
if (!extra || !dwrq->length || (dwrq->flags & IW_ENCODE_NOKEY)) {
/* Just select a new current key */
val = htod32(key.index);
if ((error = dev_wlc_ioctl(dev, WLC_SET_KEY_PRIMARY, &val, sizeof(val))))
return error;
} else {
key.len = dwrq->length;
if (dwrq->length > sizeof(key.data))
return -EINVAL;
memcpy(key.data, extra, dwrq->length);
key.flags = WL_PRIMARY_KEY;
switch (key.len) {
case WEP1_KEY_SIZE:
key.algo = CRYPTO_ALGO_WEP1;
break;
case WEP128_KEY_SIZE:
key.algo = CRYPTO_ALGO_WEP128;
break;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 14)
case TKIP_KEY_SIZE:
key.algo = CRYPTO_ALGO_TKIP;
break;
#endif
case AES_KEY_SIZE:
key.algo = CRYPTO_ALGO_AES_CCM;
break;
default:
return -EINVAL;
}
/* Set the new key/index */
swap_key_from_BE(&key);
if ((error = dev_wlc_ioctl(dev, WLC_SET_KEY, &key, sizeof(key))))
return error;
}
/* Interpret "restricted" to mean shared key authentication */
val = (dwrq->flags & IW_ENCODE_RESTRICTED) ? 1 : 0;
val = htod32(val);
if ((error = dev_wlc_ioctl(dev, WLC_SET_AUTH, &val, sizeof(val))))
return error;
return 0;
}
static int
wl_iw_get_encode(
struct net_device *dev,
struct iw_request_info *info,
struct iw_point *dwrq,
char *extra
)
{
wl_wsec_key_t key;
int error, val, wsec, auth;
WL_TRACE(("%s: SIOCGIWENCODE\n", dev->name));
/* assure default values of zero for things we don't touch */
bzero(&key, sizeof(wl_wsec_key_t));
if ((dwrq->flags & IW_ENCODE_INDEX) == 0) {
/* Find the current key */
for (key.index = 0; key.index < DOT11_MAX_DEFAULT_KEYS; key.index++) {
val = key.index;
if ((error = dev_wlc_ioctl(dev, WLC_GET_KEY_PRIMARY, &val, sizeof(val))))
return error;
val = dtoh32(val);
if (val)
break;
}
} else
key.index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
if (key.index >= DOT11_MAX_DEFAULT_KEYS)
key.index = 0;
/* Get info */
if ((error = dev_wlc_ioctl(dev, WLC_GET_WSEC, &wsec, sizeof(wsec))) ||
(error = dev_wlc_ioctl(dev, WLC_GET_AUTH, &auth, sizeof(auth))))
return error;
swap_key_to_BE(&key);
wsec = dtoh32(wsec);
auth = dtoh32(auth);
/* Get key length */
dwrq->length = MIN(IW_ENCODING_TOKEN_MAX, key.len);
/* Get flags */
dwrq->flags = key.index + 1;
if (!(wsec & (WEP_ENABLED | TKIP_ENABLED | AES_ENABLED))) {
/* Interpret "off" to mean no encryption */
dwrq->flags |= IW_ENCODE_DISABLED;
}
if (auth) {
/* Interpret "restricted" to mean shared key authentication */
dwrq->flags |= IW_ENCODE_RESTRICTED;
}
/* Get key */
if (dwrq->length && extra)
memcpy(extra, key.data, dwrq->length);
return 0;
}
static int
wl_iw_set_power(
struct net_device *dev,
struct iw_request_info *info,
struct iw_param *vwrq,
char *extra
)
{
int error, pm;
WL_TRACE(("%s: SIOCSIWPOWER\n", dev->name));
pm = vwrq->disabled ? PM_OFF : PM_MAX;
pm = htod32(pm);
if ((error = dev_wlc_ioctl(dev, WLC_SET_PM, &pm, sizeof(pm))))
return error;
return 0;
}
static int
wl_iw_get_power(
struct net_device *dev,
struct iw_request_info *info,
struct iw_param *vwrq,
char *extra
)
{
int error, pm;
WL_TRACE(("%s: SIOCGIWPOWER\n", dev->name));
if ((error = dev_wlc_ioctl(dev, WLC_GET_PM, &pm, sizeof(pm))))
return error;
pm = dtoh32(pm);
vwrq->disabled = pm ? 0 : 1;
vwrq->flags = IW_POWER_ALL_R;
return 0;
}
#if WIRELESS_EXT > 17
static int
wl_iw_set_wpaie(
struct net_device *dev,
struct iw_request_info *info,
struct iw_point *iwp,
char *extra
)
{
dev_wlc_bufvar_set(dev, "wpaie", extra, iwp->length);
return 0;
}
static int
wl_iw_get_wpaie(
struct net_device *dev,
struct iw_request_info *info,
struct iw_point *iwp,
char *extra
)
{
WL_TRACE(("%s: SIOCGIWGENIE\n", dev->name));
iwp->length = 64;
dev_wlc_bufvar_get(dev, "wpaie", extra, iwp->length);
return 0;
}
static int
wl_iw_set_encodeext(
struct net_device *dev,
struct iw_request_info *info,
struct iw_point *dwrq,
char *extra
)
{
wl_wsec_key_t key;
int error;
struct iw_encode_ext *iwe;
WL_TRACE(("%s: SIOCSIWENCODEEXT\n", dev->name));
memset(&key, 0, sizeof(key));
iwe = (struct iw_encode_ext *)extra;
/* disable encryption completely */
if (dwrq->flags & IW_ENCODE_DISABLED) {
}
/* get the key index */
key.index = 0;
if (dwrq->flags & IW_ENCODE_INDEX)
key.index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
key.len = iwe->key_len;
/* Instead of bcast for ea address for default wep keys, driver needs it to be Null */
if (!ETHER_ISMULTI(iwe->addr.sa_data))
bcopy((void *)&iwe->addr.sa_data, (char *)&key.ea, ETHER_ADDR_LEN);
/* check for key index change */
if (key.len == 0) {
if (iwe->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
WL_WSEC(("Changing the the primary Key to %d\n", key.index));
/* change the key index .... */
key.index = htod32(key.index);
error = dev_wlc_ioctl(dev, WLC_SET_KEY_PRIMARY,
&key.index, sizeof(key.index));
if (error)
return error;
}
/* key delete */
else {
swap_key_from_BE(&key);
error = dev_wlc_ioctl(dev, WLC_SET_KEY, &key, sizeof(key));
if (error)
return error;
}
}
/* This case is used to allow an external 802.1x supplicant
* to pass the PMK to the in-driver supplicant for use in
* the 4-way handshake.
*/
else if (iwe->alg == IW_ENCODE_ALG_PMK) {
int j;
wsec_pmk_t pmk;
char keystring[WSEC_MAX_PSK_LEN + 1];
char* charptr = keystring;
uint len;
/* copy the raw hex key to the appropriate format */
for (j = 0; j < (WSEC_MAX_PSK_LEN / 2); j++) {
sprintf(charptr, "%02x", iwe->key[j]);
charptr += 2;
}
len = strlen(keystring);
pmk.key_len = htod16(len);
bcopy(keystring, pmk.key, len);
pmk.flags = htod16(WSEC_PASSPHRASE);
error = dev_wlc_ioctl(dev, WLC_SET_WSEC_PMK, &pmk, sizeof(pmk));
if (error)
return error;
}
else {
if (iwe->key_len > sizeof(key.data))
return -EINVAL;
WL_WSEC(("Setting the key index %d\n", key.index));
if (iwe->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
WL_WSEC(("key is a Primary Key\n"));
key.flags = WL_PRIMARY_KEY;
}
bcopy((void *)iwe->key, key.data, iwe->key_len);
if (iwe->alg == IW_ENCODE_ALG_TKIP) {
uint8 keybuf[8];
bcopy(&key.data[24], keybuf, sizeof(keybuf));
bcopy(&key.data[16], &key.data[24], sizeof(keybuf));
bcopy(keybuf, &key.data[16], sizeof(keybuf));
}
/* rx iv */
if (iwe->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
uchar *ivptr;
ivptr = (uchar *)iwe->rx_seq;
key.rxiv.hi = (ivptr[5] << 24) | (ivptr[4] << 16) |
(ivptr[3] << 8) | ivptr[2];
key.rxiv.lo = (ivptr[1] << 8) | ivptr[0];
key.iv_initialized = TRUE;
}
switch (iwe->alg) {
case IW_ENCODE_ALG_NONE:
key.algo = CRYPTO_ALGO_OFF;
break;
case IW_ENCODE_ALG_WEP:
if (iwe->key_len == WEP1_KEY_SIZE)
key.algo = CRYPTO_ALGO_WEP1;
else
key.algo = CRYPTO_ALGO_WEP128;
break;
case IW_ENCODE_ALG_TKIP:
key.algo = CRYPTO_ALGO_TKIP;
break;
case IW_ENCODE_ALG_CCMP:
key.algo = CRYPTO_ALGO_AES_CCM;
break;
default:
break;
}
swap_key_from_BE(&key);
dhd_wait_pend8021x(dev);
error = dev_wlc_ioctl(dev, WLC_SET_KEY, &key, sizeof(key));
if (error)
return error;
}
return 0;
}
#if WIRELESS_EXT > 17
struct {
pmkid_list_t pmkids;
pmkid_t foo[MAXPMKID-1];
} pmkid_list;
static int
wl_iw_set_pmksa(
struct net_device *dev,
struct iw_request_info *info,
struct iw_param *vwrq,
char *extra
)
{
struct iw_pmksa *iwpmksa;
uint i;
char eabuf[ETHER_ADDR_STR_LEN];
pmkid_t * pmkid_array = pmkid_list.pmkids.pmkid;
WL_TRACE(("%s: SIOCSIWPMKSA\n", dev->name));
iwpmksa = (struct iw_pmksa *)extra;
bzero((char *)eabuf, ETHER_ADDR_STR_LEN);
if (iwpmksa->cmd == IW_PMKSA_FLUSH) {
WL_TRACE(("wl_iw_set_pmksa - IW_PMKSA_FLUSH\n"));
bzero((char *)&pmkid_list, sizeof(pmkid_list));
}
if (iwpmksa->cmd == IW_PMKSA_REMOVE) {
pmkid_list_t pmkid, *pmkidptr;
pmkidptr = &pmkid;
bcopy(&iwpmksa->bssid.sa_data[0], &pmkidptr->pmkid[0].BSSID, ETHER_ADDR_LEN);
bcopy(&iwpmksa->pmkid[0], &pmkidptr->pmkid[0].PMKID, WPA2_PMKID_LEN);
{
uint j;
WL_TRACE(("wl_iw_set_pmksa,IW_PMKSA_REMOVE - PMKID: %s = ",
bcm_ether_ntoa(&pmkidptr->pmkid[0].BSSID,
eabuf)));
for (j = 0; j < WPA2_PMKID_LEN; j++)
WL_TRACE(("%02x ", pmkidptr->pmkid[0].PMKID[j]));
WL_TRACE(("\n"));
}
for (i = 0; i < pmkid_list.pmkids.npmkid; i++)
if (!bcmp(&iwpmksa->bssid.sa_data[0], &pmkid_array[i].BSSID,
ETHER_ADDR_LEN))
break;
for (; i < pmkid_list.pmkids.npmkid; i++) {
bcopy(&pmkid_array[i+1].BSSID,
&pmkid_array[i].BSSID,
ETHER_ADDR_LEN);
bcopy(&pmkid_array[i+1].PMKID,
&pmkid_array[i].PMKID,
WPA2_PMKID_LEN);
}
pmkid_list.pmkids.npmkid--;
}
if (iwpmksa->cmd == IW_PMKSA_ADD) {
bcopy(&iwpmksa->bssid.sa_data[0],
&pmkid_array[pmkid_list.pmkids.npmkid].BSSID,
ETHER_ADDR_LEN);
bcopy(&iwpmksa->pmkid[0], &pmkid_array[pmkid_list.pmkids.npmkid].PMKID,
WPA2_PMKID_LEN);
{
uint j;
uint k;
k = pmkid_list.pmkids.npmkid;
BCM_REFERENCE(k);
WL_TRACE(("wl_iw_set_pmksa,IW_PMKSA_ADD - PMKID: %s = ",
bcm_ether_ntoa(&pmkid_array[k].BSSID,
eabuf)));
for (j = 0; j < WPA2_PMKID_LEN; j++)
WL_TRACE(("%02x ", pmkid_array[k].PMKID[j]));
WL_TRACE(("\n"));
}
pmkid_list.pmkids.npmkid++;
}
WL_TRACE(("PRINTING pmkid LIST - No of elements %d\n", pmkid_list.pmkids.npmkid));
for (i = 0; i < pmkid_list.pmkids.npmkid; i++) {
uint j;
WL_TRACE(("PMKID[%d]: %s = ", i,
bcm_ether_ntoa(&pmkid_array[i].BSSID,
eabuf)));
for (j = 0; j < WPA2_PMKID_LEN; j++)
WL_TRACE(("%02x ", pmkid_array[i].PMKID[j]));
printf("\n");
}
WL_TRACE(("\n"));
dev_wlc_bufvar_set(dev, "pmkid_info", (char *)&pmkid_list, sizeof(pmkid_list));
return 0;
}
#endif /* WIRELESS_EXT > 17 */
static int
wl_iw_get_encodeext(
struct net_device *dev,
struct iw_request_info *info,
struct iw_param *vwrq,
char *extra
)
{
WL_TRACE(("%s: SIOCGIWENCODEEXT\n", dev->name));
return 0;
}
static int
wl_iw_set_wpaauth(
struct net_device *dev,
struct iw_request_info *info,
struct iw_param *vwrq,
char *extra
)
{
int error = 0;
int paramid;
int paramval;
uint32 cipher_combined;
int val = 0;
wl_iw_t *iw = IW_DEV_IF(dev);
WL_TRACE(("%s: SIOCSIWAUTH\n", dev->name));
paramid = vwrq->flags & IW_AUTH_INDEX;
paramval = vwrq->value;
WL_TRACE(("%s: SIOCSIWAUTH, paramid = 0x%0x, paramval = 0x%0x\n",
dev->name, paramid, paramval));
switch (paramid) {
case IW_AUTH_WPA_VERSION:
/* supported wpa version disabled or wpa or wpa2 */
if (paramval & IW_AUTH_WPA_VERSION_DISABLED)
val = WPA_AUTH_DISABLED;
else if (paramval & (IW_AUTH_WPA_VERSION_WPA))
val = WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED;
else if (paramval & IW_AUTH_WPA_VERSION_WPA2)
val = WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED;
WL_TRACE(("%s: %d: setting wpa_auth to 0x%0x\n", __FUNCTION__, __LINE__, val));
if ((error = dev_wlc_intvar_set(dev, "wpa_auth", val)))
return error;
break;
case IW_AUTH_CIPHER_PAIRWISE:
case IW_AUTH_CIPHER_GROUP: {
int fbt_cap = 0;
if (paramid == IW_AUTH_CIPHER_PAIRWISE) {
iw->pwsec = paramval;
}
else {
iw->gwsec = paramval;
}
if ((error = dev_wlc_intvar_get(dev, "wsec", &val)))
return error;
cipher_combined = iw->gwsec | iw->pwsec;
val &= ~(WEP_ENABLED | TKIP_ENABLED | AES_ENABLED);
if (cipher_combined & (IW_AUTH_CIPHER_WEP40 | IW_AUTH_CIPHER_WEP104))
val |= WEP_ENABLED;
if (cipher_combined & IW_AUTH_CIPHER_TKIP)
val |= TKIP_ENABLED;
if (cipher_combined & IW_AUTH_CIPHER_CCMP)
val |= AES_ENABLED;
if (iw->privacy_invoked && !val) {
WL_WSEC(("%s: %s: 'Privacy invoked' TRUE but clearing wsec, assuming "
"we're a WPS enrollee\n", dev->name, __FUNCTION__));
if ((error = dev_wlc_intvar_set(dev, "is_WPS_enrollee", TRUE))) {
WL_WSEC(("Failed to set iovar is_WPS_enrollee\n"));
return error;
}
} else if (val) {
if ((error = dev_wlc_intvar_set(dev, "is_WPS_enrollee", FALSE))) {
WL_WSEC(("Failed to clear iovar is_WPS_enrollee\n"));
return error;
}
}
if ((error = dev_wlc_intvar_set(dev, "wsec", val)))
return error;
/* Ensure in-dongle supplicant is turned on when FBT wants to do the 4-way
* handshake.
*/
if (dev_wlc_intvar_get(dev, "fbt_cap", &fbt_cap) == 0) {
if (fbt_cap == WLC_FBT_CAP_DRV_4WAY_AND_REASSOC) {
if ((paramid == IW_AUTH_CIPHER_PAIRWISE) && (val & AES_ENABLED)) {
if ((error = dev_wlc_intvar_set(dev, "sup_wpa", 1)))
return error;
}
else if (val == 0) {
if ((error = dev_wlc_intvar_set(dev, "sup_wpa", 0)))
return error;
}
}
}
break;
}
case IW_AUTH_KEY_MGMT:
if ((error = dev_wlc_intvar_get(dev, "wpa_auth", &val)))
return error;
if (val & (WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED)) {
if (paramval & (IW_AUTH_KEY_MGMT_FT_PSK | IW_AUTH_KEY_MGMT_PSK))
val = WPA_AUTH_PSK;
else
val = WPA_AUTH_UNSPECIFIED;
if (paramval & (IW_AUTH_KEY_MGMT_FT_802_1X | IW_AUTH_KEY_MGMT_FT_PSK))
val |= WPA2_AUTH_FT;
}
else if (val & (WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED)) {
if (paramval & (IW_AUTH_KEY_MGMT_FT_PSK | IW_AUTH_KEY_MGMT_PSK))
val = WPA2_AUTH_PSK;
else
val = WPA2_AUTH_UNSPECIFIED;
if (paramval & (IW_AUTH_KEY_MGMT_FT_802_1X | IW_AUTH_KEY_MGMT_FT_PSK))
val |= WPA2_AUTH_FT;
}
WL_TRACE(("%s: %d: setting wpa_auth to %d\n", __FUNCTION__, __LINE__, val));
if ((error = dev_wlc_intvar_set(dev, "wpa_auth", val)))
return error;
break;
case IW_AUTH_TKIP_COUNTERMEASURES:
dev_wlc_bufvar_set(dev, "tkip_countermeasures", (char *)¶mval, 1);
break;
case IW_AUTH_80211_AUTH_ALG:
/* open shared */
WL_ERROR(("Setting the D11auth %d\n", paramval));
if (paramval & IW_AUTH_ALG_OPEN_SYSTEM)
val = 0;
else if (paramval & IW_AUTH_ALG_SHARED_KEY)
val = 1;
else
error = 1;
if (!error && (error = dev_wlc_intvar_set(dev, "auth", val)))
return error;
break;
case IW_AUTH_WPA_ENABLED:
if (paramval == 0) {
val = 0;
WL_TRACE(("%s: %d: setting wpa_auth to %d\n", __FUNCTION__, __LINE__, val));
error = dev_wlc_intvar_set(dev, "wpa_auth", val);
return error;
}
else {
/* If WPA is enabled, wpa_auth is set elsewhere */
}
break;
case IW_AUTH_DROP_UNENCRYPTED:
dev_wlc_bufvar_set(dev, "wsec_restrict", (char *)¶mval, 1);
break;
case IW_AUTH_RX_UNENCRYPTED_EAPOL:
dev_wlc_bufvar_set(dev, "rx_unencrypted_eapol", (char *)¶mval, 1);
break;
#if WIRELESS_EXT > 17
case IW_AUTH_ROAMING_CONTROL:
WL_TRACE(("%s: IW_AUTH_ROAMING_CONTROL\n", __FUNCTION__));
/* driver control or user space app control */
break;
case IW_AUTH_PRIVACY_INVOKED: {
int wsec;
if (paramval == 0) {
iw->privacy_invoked = FALSE;
if ((error = dev_wlc_intvar_set(dev, "is_WPS_enrollee", FALSE))) {
WL_WSEC(("Failed to clear iovar is_WPS_enrollee\n"));
return error;
}
} else {
iw->privacy_invoked = TRUE;
if ((error = dev_wlc_intvar_get(dev, "wsec", &wsec)))
return error;
if (!WSEC_ENABLED(wsec)) {
/* if privacy is true, but wsec is false, we are a WPS enrollee */
if ((error = dev_wlc_intvar_set(dev, "is_WPS_enrollee", TRUE))) {
WL_WSEC(("Failed to set iovar is_WPS_enrollee\n"));
return error;
}
} else {
if ((error = dev_wlc_intvar_set(dev, "is_WPS_enrollee", FALSE))) {
WL_WSEC(("Failed to clear iovar is_WPS_enrollee\n"));
return error;
}
}
}
break;
}
#endif /* WIRELESS_EXT > 17 */
default:
break;
}
return 0;
}
#define VAL_PSK(_val) (((_val) & WPA_AUTH_PSK) || ((_val) & WPA2_AUTH_PSK))
static int
wl_iw_get_wpaauth(
struct net_device *dev,
struct iw_request_info *info,
struct iw_param *vwrq,
char *extra
)
{
int error;
int paramid;
int paramval = 0;
int val;
wl_iw_t *iw = IW_DEV_IF(dev);
WL_TRACE(("%s: SIOCGIWAUTH\n", dev->name));
paramid = vwrq->flags & IW_AUTH_INDEX;
switch (paramid) {
case IW_AUTH_WPA_VERSION:
/* supported wpa version disabled or wpa or wpa2 */
if ((error = dev_wlc_intvar_get(dev, "wpa_auth", &val)))
return error;
if (val & (WPA_AUTH_NONE | WPA_AUTH_DISABLED))
paramval = IW_AUTH_WPA_VERSION_DISABLED;
else if (val & (WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED))
paramval = IW_AUTH_WPA_VERSION_WPA;
else if (val & (WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED))
paramval = IW_AUTH_WPA_VERSION_WPA2;
break;
case IW_AUTH_CIPHER_PAIRWISE:
paramval = iw->pwsec;
break;
case IW_AUTH_CIPHER_GROUP:
paramval = iw->gwsec;
break;
case IW_AUTH_KEY_MGMT:
/* psk, 1x */
if ((error = dev_wlc_intvar_get(dev, "wpa_auth", &val)))
return error;
if (VAL_PSK(val))
paramval = IW_AUTH_KEY_MGMT_PSK;
else
paramval = IW_AUTH_KEY_MGMT_802_1X;
break;
case IW_AUTH_TKIP_COUNTERMEASURES:
dev_wlc_bufvar_get(dev, "tkip_countermeasures", (char *)¶mval, 1);
break;
case IW_AUTH_DROP_UNENCRYPTED:
dev_wlc_bufvar_get(dev, "wsec_restrict", (char *)¶mval, 1);
break;
case IW_AUTH_RX_UNENCRYPTED_EAPOL:
dev_wlc_bufvar_get(dev, "rx_unencrypted_eapol", (char *)¶mval, 1);
break;
case IW_AUTH_80211_AUTH_ALG:
/* open, shared, leap */
if ((error = dev_wlc_intvar_get(dev, "auth", &val)))
return error;
if (!val)
paramval = IW_AUTH_ALG_OPEN_SYSTEM;
else
paramval = IW_AUTH_ALG_SHARED_KEY;
break;
case IW_AUTH_WPA_ENABLED:
if ((error = dev_wlc_intvar_get(dev, "wpa_auth", &val)))
return error;
if (val)
paramval = TRUE;
else
paramval = FALSE;
break;
#if WIRELESS_EXT > 17
case IW_AUTH_ROAMING_CONTROL:
WL_ERROR(("%s: IW_AUTH_ROAMING_CONTROL\n", __FUNCTION__));
/* driver control or user space app control */
break;
case IW_AUTH_PRIVACY_INVOKED:
paramval = iw->privacy_invoked;
break;
#endif /* WIRELESS_EXT > 17 */
}
vwrq->value = paramval;
return 0;
}
#endif /* WIRELESS_EXT > 17 */
static const iw_handler wl_iw_handler[] =
{
(iw_handler) wl_iw_config_commit, /* SIOCSIWCOMMIT */
(iw_handler) wl_iw_get_name, /* SIOCGIWNAME */
(iw_handler) NULL, /* SIOCSIWNWID */
(iw_handler) NULL, /* SIOCGIWNWID */
(iw_handler) wl_iw_set_freq, /* SIOCSIWFREQ */
(iw_handler) wl_iw_get_freq, /* SIOCGIWFREQ */
(iw_handler) wl_iw_set_mode, /* SIOCSIWMODE */
(iw_handler) wl_iw_get_mode, /* SIOCGIWMODE */
(iw_handler) NULL, /* SIOCSIWSENS */
(iw_handler) NULL, /* SIOCGIWSENS */
(iw_handler) NULL, /* SIOCSIWRANGE */
(iw_handler) wl_iw_get_range, /* SIOCGIWRANGE */
(iw_handler) NULL, /* SIOCSIWPRIV */
(iw_handler) NULL, /* SIOCGIWPRIV */
(iw_handler) NULL, /* SIOCSIWSTATS */
(iw_handler) NULL, /* SIOCGIWSTATS */
(iw_handler) wl_iw_set_spy, /* SIOCSIWSPY */
(iw_handler) wl_iw_get_spy, /* SIOCGIWSPY */
(iw_handler) NULL, /* -- hole -- */
(iw_handler) NULL, /* -- hole -- */
(iw_handler) wl_iw_set_wap, /* SIOCSIWAP */
(iw_handler) wl_iw_get_wap, /* SIOCGIWAP */
#if WIRELESS_EXT > 17
(iw_handler) wl_iw_mlme, /* SIOCSIWMLME */
#else
(iw_handler) NULL, /* -- hole -- */
#endif
(iw_handler) wl_iw_iscan_get_aplist, /* SIOCGIWAPLIST */
#if WIRELESS_EXT > 13
(iw_handler) wl_iw_iscan_set_scan, /* SIOCSIWSCAN */
(iw_handler) wl_iw_iscan_get_scan, /* SIOCGIWSCAN */
#else /* WIRELESS_EXT > 13 */
(iw_handler) NULL, /* SIOCSIWSCAN */
(iw_handler) NULL, /* SIOCGIWSCAN */
#endif /* WIRELESS_EXT > 13 */
(iw_handler) wl_iw_set_essid, /* SIOCSIWESSID */
(iw_handler) wl_iw_get_essid, /* SIOCGIWESSID */
(iw_handler) wl_iw_set_nick, /* SIOCSIWNICKN */
(iw_handler) wl_iw_get_nick, /* SIOCGIWNICKN */
(iw_handler) NULL, /* -- hole -- */
(iw_handler) NULL, /* -- hole -- */
(iw_handler) wl_iw_set_rate, /* SIOCSIWRATE */
(iw_handler) wl_iw_get_rate, /* SIOCGIWRATE */
(iw_handler) wl_iw_set_rts, /* SIOCSIWRTS */
(iw_handler) wl_iw_get_rts, /* SIOCGIWRTS */
(iw_handler) wl_iw_set_frag, /* SIOCSIWFRAG */
(iw_handler) wl_iw_get_frag, /* SIOCGIWFRAG */
(iw_handler) wl_iw_set_txpow, /* SIOCSIWTXPOW */
(iw_handler) wl_iw_get_txpow, /* SIOCGIWTXPOW */
#if WIRELESS_EXT > 10
(iw_handler) wl_iw_set_retry, /* SIOCSIWRETRY */
(iw_handler) wl_iw_get_retry, /* SIOCGIWRETRY */
#endif /* WIRELESS_EXT > 10 */
(iw_handler) wl_iw_set_encode, /* SIOCSIWENCODE */
(iw_handler) wl_iw_get_encode, /* SIOCGIWENCODE */
(iw_handler) wl_iw_set_power, /* SIOCSIWPOWER */
(iw_handler) wl_iw_get_power, /* SIOCGIWPOWER */
#if WIRELESS_EXT > 17
(iw_handler) NULL, /* -- hole -- */
(iw_handler) NULL, /* -- hole -- */
(iw_handler) wl_iw_set_wpaie, /* SIOCSIWGENIE */
(iw_handler) wl_iw_get_wpaie, /* SIOCGIWGENIE */
(iw_handler) wl_iw_set_wpaauth, /* SIOCSIWAUTH */
(iw_handler) wl_iw_get_wpaauth, /* SIOCGIWAUTH */
(iw_handler) wl_iw_set_encodeext, /* SIOCSIWENCODEEXT */
(iw_handler) wl_iw_get_encodeext, /* SIOCGIWENCODEEXT */
(iw_handler) wl_iw_set_pmksa, /* SIOCSIWPMKSA */
#endif /* WIRELESS_EXT > 17 */
};
#if WIRELESS_EXT > 12
enum {
WL_IW_SET_LEDDC = SIOCIWFIRSTPRIV,
WL_IW_SET_VLANMODE,
WL_IW_SET_PM,
#if WIRELESS_EXT > 17
#endif /* WIRELESS_EXT > 17 */
WL_IW_SET_LAST
};
static iw_handler wl_iw_priv_handler[] = {
wl_iw_set_leddc,
wl_iw_set_vlanmode,
wl_iw_set_pm,
#if WIRELESS_EXT > 17
#endif /* WIRELESS_EXT > 17 */
NULL
};
static struct iw_priv_args wl_iw_priv_args[] = {
{
WL_IW_SET_LEDDC,
IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
0,
"set_leddc"
},
{
WL_IW_SET_VLANMODE,
IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
0,
"set_vlanmode"
},
{
WL_IW_SET_PM,
IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
0,
"set_pm"
},
#if WIRELESS_EXT > 17
#endif /* WIRELESS_EXT > 17 */
{ 0, 0, 0, { 0 } }
};
const struct iw_handler_def wl_iw_handler_def =
{
.num_standard = ARRAYSIZE(wl_iw_handler),
.num_private = ARRAY_SIZE(wl_iw_priv_handler),
.num_private_args = ARRAY_SIZE(wl_iw_priv_args),
.standard = (iw_handler *) wl_iw_handler,
.private = wl_iw_priv_handler,
.private_args = wl_iw_priv_args,
#if WIRELESS_EXT >= 19
get_wireless_stats: dhd_get_wireless_stats,
#endif /* WIRELESS_EXT >= 19 */
};
#endif /* WIRELESS_EXT > 12 */
int
wl_iw_ioctl(
struct net_device *dev,
struct ifreq *rq,
int cmd
)
{
struct iwreq *wrq = (struct iwreq *) rq;
struct iw_request_info info;
iw_handler handler;
char *extra = NULL;
size_t token_size = 1;
int max_tokens = 0, ret = 0;
if (cmd < SIOCIWFIRST ||
IW_IOCTL_IDX(cmd) >= ARRAYSIZE(wl_iw_handler) ||
!(handler = wl_iw_handler[IW_IOCTL_IDX(cmd)]))
return -EOPNOTSUPP;
switch (cmd) {
case SIOCSIWESSID:
case SIOCGIWESSID:
case SIOCSIWNICKN:
case SIOCGIWNICKN:
max_tokens = IW_ESSID_MAX_SIZE + 1;
break;
case SIOCSIWENCODE:
case SIOCGIWENCODE:
#if WIRELESS_EXT > 17
case SIOCSIWENCODEEXT:
case SIOCGIWENCODEEXT:
#endif
max_tokens = IW_ENCODING_TOKEN_MAX;
break;
case SIOCGIWRANGE:
max_tokens = sizeof(struct iw_range);
break;
case SIOCGIWAPLIST:
token_size = sizeof(struct sockaddr) + sizeof(struct iw_quality);
max_tokens = IW_MAX_AP;
break;
#if WIRELESS_EXT > 13
case SIOCGIWSCAN:
if (g_iscan)
max_tokens = wrq->u.data.length;
else
max_tokens = IW_SCAN_MAX_DATA;
break;
#endif /* WIRELESS_EXT > 13 */
case SIOCSIWSPY:
token_size = sizeof(struct sockaddr);
max_tokens = IW_MAX_SPY;
break;
case SIOCGIWSPY:
token_size = sizeof(struct sockaddr) + sizeof(struct iw_quality);
max_tokens = IW_MAX_SPY;
break;
default:
break;
}
if (max_tokens && wrq->u.data.pointer) {
if (wrq->u.data.length > max_tokens)
return -E2BIG;
if (!(extra = kmalloc(max_tokens * token_size, GFP_KERNEL)))
return -ENOMEM;
if (copy_from_user(extra, wrq->u.data.pointer, wrq->u.data.length * token_size)) {
kfree(extra);
return -EFAULT;
}
}
info.cmd = cmd;
info.flags = 0;
ret = handler(dev, &info, &wrq->u, extra);
if (extra) {
if (copy_to_user(wrq->u.data.pointer, extra, wrq->u.data.length * token_size)) {
kfree(extra);
return -EFAULT;
}
kfree(extra);
}
return ret;
}
/* Convert a connection status event into a connection status string.
* Returns TRUE if a matching connection status string was found.
*/
bool
wl_iw_conn_status_str(uint32 event_type, uint32 status, uint32 reason,
char* stringBuf, uint buflen)
{
typedef struct conn_fail_event_map_t {
uint32 inEvent; /* input: event type to match */
uint32 inStatus; /* input: event status code to match */
uint32 inReason; /* input: event reason code to match */
const char* outName; /* output: failure type */
const char* outCause; /* output: failure cause */
} conn_fail_event_map_t;
/* Map of WLC_E events to connection failure strings */
# define WL_IW_DONT_CARE 9999
const conn_fail_event_map_t event_map [] = {
/* inEvent inStatus inReason */
/* outName outCause */
{WLC_E_SET_SSID, WLC_E_STATUS_SUCCESS, WL_IW_DONT_CARE,
"Conn", "Success"},
{WLC_E_SET_SSID, WLC_E_STATUS_NO_NETWORKS, WL_IW_DONT_CARE,
"Conn", "NoNetworks"},
{WLC_E_SET_SSID, WLC_E_STATUS_FAIL, WL_IW_DONT_CARE,
"Conn", "ConfigMismatch"},
{WLC_E_PRUNE, WL_IW_DONT_CARE, WLC_E_PRUNE_ENCR_MISMATCH,
"Conn", "EncrypMismatch"},
{WLC_E_PRUNE, WL_IW_DONT_CARE, WLC_E_RSN_MISMATCH,
"Conn", "RsnMismatch"},
{WLC_E_AUTH, WLC_E_STATUS_TIMEOUT, WL_IW_DONT_CARE,
"Conn", "AuthTimeout"},
{WLC_E_AUTH, WLC_E_STATUS_FAIL, WL_IW_DONT_CARE,
"Conn", "AuthFail"},
{WLC_E_AUTH, WLC_E_STATUS_NO_ACK, WL_IW_DONT_CARE,
"Conn", "AuthNoAck"},
{WLC_E_REASSOC, WLC_E_STATUS_FAIL, WL_IW_DONT_CARE,
"Conn", "ReassocFail"},
{WLC_E_REASSOC, WLC_E_STATUS_TIMEOUT, WL_IW_DONT_CARE,
"Conn", "ReassocTimeout"},
{WLC_E_REASSOC, WLC_E_STATUS_ABORT, WL_IW_DONT_CARE,
"Conn", "ReassocAbort"},
{WLC_E_PSK_SUP, WLC_SUP_KEYED, WL_IW_DONT_CARE,
"Sup", "ConnSuccess"},
{WLC_E_PSK_SUP, WL_IW_DONT_CARE, WL_IW_DONT_CARE,
"Sup", "WpaHandshakeFail"},
{WLC_E_DEAUTH_IND, WL_IW_DONT_CARE, WL_IW_DONT_CARE,
"Conn", "Deauth"},
{WLC_E_DISASSOC_IND, WL_IW_DONT_CARE, WL_IW_DONT_CARE,
"Conn", "DisassocInd"},
{WLC_E_DISASSOC, WL_IW_DONT_CARE, WL_IW_DONT_CARE,
"Conn", "Disassoc"}
};
const char* name = "";
const char* cause = NULL;
int i;
/* Search the event map table for a matching event */
for (i = 0; i < sizeof(event_map)/sizeof(event_map[0]); i++) {
const conn_fail_event_map_t* row = &event_map[i];
if (row->inEvent == event_type &&
(row->inStatus == status || row->inStatus == WL_IW_DONT_CARE) &&
(row->inReason == reason || row->inReason == WL_IW_DONT_CARE)) {
name = row->outName;
cause = row->outCause;
break;
}
}
/* If found, generate a connection failure string and return TRUE */
if (cause) {
memset(stringBuf, 0, buflen);
snprintf(stringBuf, buflen, "%s %s %02d %02d",
name, cause, status, reason);
WL_TRACE(("Connection status: %s\n", stringBuf));
return TRUE;
} else {
return FALSE;
}
}
#if (WIRELESS_EXT > 14)
/* Check if we have received an event that indicates connection failure
* If so, generate a connection failure report string.
* The caller supplies a buffer to hold the generated string.
*/
static bool
wl_iw_check_conn_fail(wl_event_msg_t *e, char* stringBuf, uint buflen)
{
uint32 event = ntoh32(e->event_type);
uint32 status = ntoh32(e->status);
uint32 reason = ntoh32(e->reason);
if (wl_iw_conn_status_str(event, status, reason, stringBuf, buflen)) {
return TRUE;
} else
{
return FALSE;
}
}
#endif /* WIRELESS_EXT > 14 */
#ifndef IW_CUSTOM_MAX
#define IW_CUSTOM_MAX 256 /* size of extra buffer used for translation of events */
#endif /* IW_CUSTOM_MAX */
void
wl_iw_event(struct net_device *dev, wl_event_msg_t *e, void* data)
{
#if WIRELESS_EXT > 13
union iwreq_data wrqu;
char extra[IW_CUSTOM_MAX + 1];
int cmd = 0;
uint32 event_type = ntoh32(e->event_type);
uint16 flags = ntoh16(e->flags);
uint32 datalen = ntoh32(e->datalen);
uint32 status = ntoh32(e->status);
memset(&wrqu, 0, sizeof(wrqu));
memset(extra, 0, sizeof(extra));
memcpy(wrqu.addr.sa_data, &e->addr, ETHER_ADDR_LEN);
wrqu.addr.sa_family = ARPHRD_ETHER;
switch (event_type) {
case WLC_E_TXFAIL:
cmd = IWEVTXDROP;
break;
#if WIRELESS_EXT > 14
case WLC_E_JOIN:
case WLC_E_ASSOC_IND:
case WLC_E_REASSOC_IND:
cmd = IWEVREGISTERED;
break;
case WLC_E_DEAUTH_IND:
case WLC_E_DISASSOC_IND:
cmd = SIOCGIWAP;
wrqu.data.length = strlen(extra);
bzero(wrqu.addr.sa_data, ETHER_ADDR_LEN);
bzero(&extra, ETHER_ADDR_LEN);
break;
case WLC_E_LINK:
case WLC_E_NDIS_LINK:
cmd = SIOCGIWAP;
wrqu.data.length = strlen(extra);
if (!(flags & WLC_EVENT_MSG_LINK)) {
bzero(wrqu.addr.sa_data, ETHER_ADDR_LEN);
bzero(&extra, ETHER_ADDR_LEN);
}
break;
case WLC_E_ACTION_FRAME:
cmd = IWEVCUSTOM;
if (datalen + 1 <= sizeof(extra)) {
wrqu.data.length = datalen + 1;
extra[0] = WLC_E_ACTION_FRAME;
memcpy(&extra[1], data, datalen);
WL_TRACE(("WLC_E_ACTION_FRAME len %d \n", wrqu.data.length));
}
break;
case WLC_E_ACTION_FRAME_COMPLETE:
cmd = IWEVCUSTOM;
if (sizeof(status) + 1 <= sizeof(extra)) {
wrqu.data.length = sizeof(status) + 1;
extra[0] = WLC_E_ACTION_FRAME_COMPLETE;
memcpy(&extra[1], &status, sizeof(status));
WL_TRACE(("wl_iw_event status %d \n", status));
}
break;
#endif /* WIRELESS_EXT > 14 */
#if WIRELESS_EXT > 17
case WLC_E_MIC_ERROR: {
struct iw_michaelmicfailure *micerrevt = (struct iw_michaelmicfailure *)&extra;
cmd = IWEVMICHAELMICFAILURE;
wrqu.data.length = sizeof(struct iw_michaelmicfailure);
if (flags & WLC_EVENT_MSG_GROUP)
micerrevt->flags |= IW_MICFAILURE_GROUP;
else
micerrevt->flags |= IW_MICFAILURE_PAIRWISE;
memcpy(micerrevt->src_addr.sa_data, &e->addr, ETHER_ADDR_LEN);
micerrevt->src_addr.sa_family = ARPHRD_ETHER;
break;
}
case WLC_E_ASSOC_REQ_IE:
cmd = IWEVASSOCREQIE;
wrqu.data.length = datalen;
if (datalen < sizeof(extra))
memcpy(extra, data, datalen);
break;
case WLC_E_ASSOC_RESP_IE:
cmd = IWEVASSOCRESPIE;
wrqu.data.length = datalen;
if (datalen < sizeof(extra))
memcpy(extra, data, datalen);
break;
case WLC_E_PMKID_CACHE: {
struct iw_pmkid_cand *iwpmkidcand = (struct iw_pmkid_cand *)&extra;
pmkid_cand_list_t *pmkcandlist;
pmkid_cand_t *pmkidcand;
int count;
if (data == NULL)
break;
cmd = IWEVPMKIDCAND;
pmkcandlist = data;
count = ntoh32_ua((uint8 *)&pmkcandlist->npmkid_cand);
wrqu.data.length = sizeof(struct iw_pmkid_cand);
pmkidcand = pmkcandlist->pmkid_cand;
while (count) {
bzero(iwpmkidcand, sizeof(struct iw_pmkid_cand));
if (pmkidcand->preauth)
iwpmkidcand->flags |= IW_PMKID_CAND_PREAUTH;
bcopy(&pmkidcand->BSSID, &iwpmkidcand->bssid.sa_data,
ETHER_ADDR_LEN);
wireless_send_event(dev, cmd, &wrqu, extra);
pmkidcand++;
count--;
}
break;
}
#endif /* WIRELESS_EXT > 17 */
case WLC_E_SCAN_COMPLETE:
#if WIRELESS_EXT > 14
cmd = SIOCGIWSCAN;
#endif
WL_TRACE(("event WLC_E_SCAN_COMPLETE\n"));
if ((g_iscan) && (g_iscan->sysioc_pid >= 0) &&
(g_iscan->iscan_state != ISCAN_STATE_IDLE))
up(&g_iscan->sysioc_sem);
break;
default:
/* Cannot translate event */
break;
}
if (cmd) {
if (cmd == SIOCGIWSCAN)
wireless_send_event(dev, cmd, &wrqu, NULL);
else
wireless_send_event(dev, cmd, &wrqu, extra);
}
#if WIRELESS_EXT > 14
/* Look for WLC events that indicate a connection failure.
* If found, generate an IWEVCUSTOM event.
*/
memset(extra, 0, sizeof(extra));
if (wl_iw_check_conn_fail(e, extra, sizeof(extra))) {
cmd = IWEVCUSTOM;
wrqu.data.length = strlen(extra);
wireless_send_event(dev, cmd, &wrqu, extra);
}
#endif /* WIRELESS_EXT > 14 */
#endif /* WIRELESS_EXT > 13 */
}
int wl_iw_get_wireless_stats(struct net_device *dev, struct iw_statistics *wstats)
{
int res = 0;
wl_cnt_t cnt;
int phy_noise;
int rssi;
scb_val_t scb_val;
phy_noise = 0;
if ((res = dev_wlc_ioctl(dev, WLC_GET_PHY_NOISE, &phy_noise, sizeof(phy_noise))))
goto done;
phy_noise = dtoh32(phy_noise);
WL_TRACE(("wl_iw_get_wireless_stats phy noise=%d\n *****", phy_noise));
scb_val.val = 0;
if ((res = dev_wlc_ioctl(dev, WLC_GET_RSSI, &scb_val, sizeof(scb_val_t))))
goto done;
rssi = dtoh32(scb_val.val);
WL_TRACE(("wl_iw_get_wireless_stats rssi=%d ****** \n", rssi));
if (rssi <= WL_IW_RSSI_NO_SIGNAL)
wstats->qual.qual = 0;
else if (rssi <= WL_IW_RSSI_VERY_LOW)
wstats->qual.qual = 1;
else if (rssi <= WL_IW_RSSI_LOW)
wstats->qual.qual = 2;
else if (rssi <= WL_IW_RSSI_GOOD)
wstats->qual.qual = 3;
else if (rssi <= WL_IW_RSSI_VERY_GOOD)
wstats->qual.qual = 4;
else
wstats->qual.qual = 5;
/* Wraps to 0 if RSSI is 0 */
wstats->qual.level = 0x100 + rssi;
wstats->qual.noise = 0x100 + phy_noise;
#if WIRELESS_EXT > 18
wstats->qual.updated |= (IW_QUAL_ALL_UPDATED | IW_QUAL_DBM);
#else
wstats->qual.updated |= 7;
#endif /* WIRELESS_EXT > 18 */
#if WIRELESS_EXT > 11
WL_TRACE(("wl_iw_get_wireless_stats counters=%d\n *****", (int)sizeof(wl_cnt_t)));
memset(&cnt, 0, sizeof(wl_cnt_t));
res = dev_wlc_bufvar_get(dev, "counters", (char *)&cnt, sizeof(wl_cnt_t));
if (res)
{
WL_ERROR(("wl_iw_get_wireless_stats counters failed error=%d ****** \n", res));
goto done;
}
cnt.version = dtoh16(cnt.version);
if (cnt.version != WL_CNT_T_VERSION) {
WL_TRACE(("\tIncorrect version of counters struct: expected %d; got %d\n",
WL_CNT_T_VERSION, cnt.version));
goto done;
}
wstats->discard.nwid = 0;
wstats->discard.code = dtoh32(cnt.rxundec);
wstats->discard.fragment = dtoh32(cnt.rxfragerr);
wstats->discard.retries = dtoh32(cnt.txfail);
wstats->discard.misc = dtoh32(cnt.rxrunt) + dtoh32(cnt.rxgiant);
wstats->miss.beacon = 0;
WL_TRACE(("wl_iw_get_wireless_stats counters txframe=%d txbyte=%d\n",
dtoh32(cnt.txframe), dtoh32(cnt.txbyte)));
WL_TRACE(("wl_iw_get_wireless_stats counters rxfrmtoolong=%d\n", dtoh32(cnt.rxfrmtoolong)));
WL_TRACE(("wl_iw_get_wireless_stats counters rxbadplcp=%d\n", dtoh32(cnt.rxbadplcp)));
WL_TRACE(("wl_iw_get_wireless_stats counters rxundec=%d\n", dtoh32(cnt.rxundec)));
WL_TRACE(("wl_iw_get_wireless_stats counters rxfragerr=%d\n", dtoh32(cnt.rxfragerr)));
WL_TRACE(("wl_iw_get_wireless_stats counters txfail=%d\n", dtoh32(cnt.txfail)));
WL_TRACE(("wl_iw_get_wireless_stats counters rxrunt=%d\n", dtoh32(cnt.rxrunt)));
WL_TRACE(("wl_iw_get_wireless_stats counters rxgiant=%d\n", dtoh32(cnt.rxgiant)));
#endif /* WIRELESS_EXT > 11 */
done:
return res;
}
static void
wl_iw_timerfunc(ulong data)
{
iscan_info_t *iscan = (iscan_info_t *)data;
iscan->timer_on = 0;
if (iscan->iscan_state != ISCAN_STATE_IDLE) {
WL_TRACE(("timer trigger\n"));
up(&iscan->sysioc_sem);
}
}
static void
wl_iw_set_event_mask(struct net_device *dev)
{
char eventmask[WL_EVENTING_MASK_LEN];
char iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for "event_msgs" + '\0' + bitvec */
dev_iw_iovar_getbuf(dev, "event_msgs", "", 0, iovbuf, sizeof(iovbuf));
bcopy(iovbuf, eventmask, WL_EVENTING_MASK_LEN);
setbit(eventmask, WLC_E_SCAN_COMPLETE);
dev_iw_iovar_setbuf(dev, "event_msgs", eventmask, WL_EVENTING_MASK_LEN,
iovbuf, sizeof(iovbuf));
}
static int
wl_iw_iscan_prep(wl_scan_params_t *params, wlc_ssid_t *ssid)
{
int err = 0;
memcpy(¶ms->bssid, ðer_bcast, ETHER_ADDR_LEN);
params->bss_type = DOT11_BSSTYPE_ANY;
params->scan_type = 0;
params->nprobes = -1;
params->active_time = -1;
params->passive_time = -1;
params->home_time = -1;
params->channel_num = 0;
params->nprobes = htod32(params->nprobes);
params->active_time = htod32(params->active_time);
params->passive_time = htod32(params->passive_time);
params->home_time = htod32(params->home_time);
if (ssid && ssid->SSID_len)
memcpy(¶ms->ssid, ssid, sizeof(wlc_ssid_t));
return err;
}
static int
wl_iw_iscan(iscan_info_t *iscan, wlc_ssid_t *ssid, uint16 action)
{
int params_size = (WL_SCAN_PARAMS_FIXED_SIZE + OFFSETOF(wl_iscan_params_t, params));
wl_iscan_params_t *params;
int err = 0;
if (ssid && ssid->SSID_len) {
params_size += sizeof(wlc_ssid_t);
}
params = (wl_iscan_params_t*)kmalloc(params_size, GFP_KERNEL);
if (params == NULL) {
return -ENOMEM;
}
memset(params, 0, params_size);
ASSERT(params_size < WLC_IOCTL_SMLEN);
err = wl_iw_iscan_prep(¶ms->params, ssid);
if (!err) {
params->version = htod32(ISCAN_REQ_VERSION);
params->action = htod16(action);
params->scan_duration = htod16(0);
/* params_size += OFFSETOF(wl_iscan_params_t, params); */
(void) dev_iw_iovar_setbuf(iscan->dev, "iscan", params, params_size,
iscan->ioctlbuf, WLC_IOCTL_SMLEN);
}
kfree(params);
return err;
}
static uint32
wl_iw_iscan_get(iscan_info_t *iscan)
{
iscan_buf_t * buf;
iscan_buf_t * ptr;
wl_iscan_results_t * list_buf;
wl_iscan_results_t list;
wl_scan_results_t *results;
uint32 status;
/* buffers are allocated on demand */
if (iscan->list_cur) {
buf = iscan->list_cur;
iscan->list_cur = buf->next;
}
else {
buf = kmalloc(sizeof(iscan_buf_t), GFP_KERNEL);
if (!buf)
return WL_SCAN_RESULTS_ABORTED;
buf->next = NULL;
if (!iscan->list_hdr)
iscan->list_hdr = buf;
else {
ptr = iscan->list_hdr;
while (ptr->next) {
ptr = ptr->next;
}
ptr->next = buf;
}
}
memset(buf->iscan_buf, 0, WLC_IW_ISCAN_MAXLEN);
list_buf = (wl_iscan_results_t*)buf->iscan_buf;
results = &list_buf->results;
results->buflen = WL_ISCAN_RESULTS_FIXED_SIZE;
results->version = 0;
results->count = 0;
memset(&list, 0, sizeof(list));
list.results.buflen = htod32(WLC_IW_ISCAN_MAXLEN);
(void) dev_iw_iovar_getbuf(
iscan->dev,
"iscanresults",
&list,
WL_ISCAN_RESULTS_FIXED_SIZE,
buf->iscan_buf,
WLC_IW_ISCAN_MAXLEN);
results->buflen = dtoh32(results->buflen);
results->version = dtoh32(results->version);
results->count = dtoh32(results->count);
WL_TRACE(("results->count = %d\n", results->count));
WL_TRACE(("results->buflen = %d\n", results->buflen));
status = dtoh32(list_buf->status);
return status;
}
static void wl_iw_send_scan_complete(iscan_info_t *iscan)
{
union iwreq_data wrqu;
memset(&wrqu, 0, sizeof(wrqu));
/* wext expects to get no data for SIOCGIWSCAN Event */
wireless_send_event(iscan->dev, SIOCGIWSCAN, &wrqu, NULL);
}
static int
_iscan_sysioc_thread(void *data)
{
uint32 status;
iscan_info_t *iscan = (iscan_info_t *)data;
DAEMONIZE("iscan_sysioc");
status = WL_SCAN_RESULTS_PARTIAL;
while (down_interruptible(&iscan->sysioc_sem) == 0) {
if (iscan->timer_on) {
del_timer(&iscan->timer);
iscan->timer_on = 0;
}
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
rtnl_lock();
#endif
status = wl_iw_iscan_get(iscan);
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
rtnl_unlock();
#endif
switch (status) {
case WL_SCAN_RESULTS_PARTIAL:
WL_TRACE(("iscanresults incomplete\n"));
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
rtnl_lock();
#endif
/* make sure our buffer size is enough before going next round */
wl_iw_iscan(iscan, NULL, WL_SCAN_ACTION_CONTINUE);
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
rtnl_unlock();
#endif
/* Reschedule the timer */
iscan->timer.expires = jiffies + msecs_to_jiffies(iscan->timer_ms);
add_timer(&iscan->timer);
iscan->timer_on = 1;
break;
case WL_SCAN_RESULTS_SUCCESS:
WL_TRACE(("iscanresults complete\n"));
iscan->iscan_state = ISCAN_STATE_IDLE;
wl_iw_send_scan_complete(iscan);
break;
case WL_SCAN_RESULTS_PENDING:
WL_TRACE(("iscanresults pending\n"));
/* Reschedule the timer */
iscan->timer.expires = jiffies + msecs_to_jiffies(iscan->timer_ms);
add_timer(&iscan->timer);
iscan->timer_on = 1;
break;
case WL_SCAN_RESULTS_ABORTED:
WL_TRACE(("iscanresults aborted\n"));
iscan->iscan_state = ISCAN_STATE_IDLE;
wl_iw_send_scan_complete(iscan);
break;
default:
WL_TRACE(("iscanresults returned unknown status %d\n", status));
break;
}
}
complete_and_exit(&iscan->sysioc_exited, 0);
}
int
wl_iw_attach(struct net_device *dev, void * dhdp)
{
iscan_info_t *iscan = NULL;
if (!dev)
return 0;
iscan = kmalloc(sizeof(iscan_info_t), GFP_KERNEL);
if (!iscan)
return -ENOMEM;
memset(iscan, 0, sizeof(iscan_info_t));
iscan->sysioc_pid = -1;
/* we only care about main interface so save a global here */
g_iscan = iscan;
iscan->dev = dev;
iscan->iscan_state = ISCAN_STATE_IDLE;
/* Set up the timer */
iscan->timer_ms = 2000;
init_timer(&iscan->timer);
iscan->timer.data = (ulong)iscan;
iscan->timer.function = wl_iw_timerfunc;
sema_init(&iscan->sysioc_sem, 0);
init_completion(&iscan->sysioc_exited);
iscan->sysioc_pid = kernel_thread(_iscan_sysioc_thread, iscan, 0);
if (iscan->sysioc_pid < 0)
return -ENOMEM;
return 0;
}
void wl_iw_detach(void)
{
iscan_buf_t *buf;
iscan_info_t *iscan = g_iscan;
if (!iscan)
return;
if (iscan->sysioc_pid >= 0) {
KILL_PROC(iscan->sysioc_pid, SIGTERM);
wait_for_completion(&iscan->sysioc_exited);
}
while (iscan->list_hdr) {
buf = iscan->list_hdr->next;
kfree(iscan->list_hdr);
iscan->list_hdr = buf;
}
kfree(iscan);
g_iscan = NULL;
}
#endif /* USE_IW */
|
the_stack_data/234518270.c | struct List {
struct List* next;
};
int test1(struct List* p) {
int count = 0;
for (; p; p = p->next) {
count = count+1;
}
return count;
}
int test2(struct List* p) {
int count = 0;
for (; p; p = p->next) {
count = (count+1) % 10;
}
return count;
}
int test3(struct List* p) {
int count = 0;
for (; p; p = p->next) {
count++;
count = count % 10;
}
return count;
}
int test4() {
int i = 0;
int total = 0;
for (i = 0; i < 2; i = i+1) {
total += i;
}
return total + i;
}
int test5() {
int i = 0;
int total = 0;
for (i = 0; i < 2; i++) {
total += i;
}
return total + i;
}
int test6() {
int i = 0;
int total = 0;
for (i = 0; i+2 < 4; i = i+1) {
total += i;
}
return total + i;
}
int test7(int i) {
if (i < 4) {
if (i < 5) {
return i;
}
}
return 1;
}
int test8(int x, int y) {
if (-1000 < y && y < 10) {
if (x < y-2) {
return x;
}
}
return y;
}
int test9(int x, int y) {
if (y == 0) {
if (x < 4) {
return 0;
}
} else {
if (x < 4) {
return 1;
}
}
return x;
}
int test10(int x, int y) {
if (y > 7) {
if (x < y) {
return 0;
}
return x;
}
return 1;
}
int test11(char *p) {
char c;
c = *p;
if (c != '\0')
*p++ = '\0';
if (c == ':') {
c = *p;
if (c != '\0')
*p++ = '\0';
if (c != ',')
return 1;
}
return 0;
}
typedef unsigned long long size_type;
size_type test12_helper() {
static size_type n = 0;
return n++;
}
int test12() {
size_type Start = 0;
while (Start <= test12_helper()-1)
{
const size_type Length = test12_helper();
Start += Length + 1;
}
return 1;
}
// Tests for overflow conditions.
int test13(char c, int i) {
unsigned char uc = c;
unsigned int x = 0;
unsigned int y = x-1;
int z = i+1;
return (double)(c + i + uc + x + y + z);
}
// Regression test for ODASA-6013.
int test14(int x) {
int x0 = (int)(char)x;
int x1 = (int)(unsigned char)x;
int x2 = (int)(unsigned short)x;
int x3 = (int)(unsigned int)x;
char c0 = x;
unsigned short s0 = x;
return x0 + x1 + x2 + x3 + c0 + s0;
}
long long test15(long long x) {
return (x > 0 && x == (int)x) ? x : -1;
}
// Tests for unary operators.
int test_unary(int a) {
int total = 0;
if (3 <= a && a <= 11) {
int b = +a;
int c = -a;
total += b+c;
}
if (0 <= a && a <= 11) {
int b = +a;
int c = -a;
total += b+c;
}
if (-7 <= a && a <= 11) {
int b = +a;
int c = -a;
total += b+c;
}
if (-7 <= a && a <= 1) {
int b = +a;
int c = -a;
total += b+c;
}
if (-7 <= a && a <= 0) {
int b = +a;
int c = -a;
total += b+c;
}
if (-7 <= a && a <= -2) {
int b = +a;
int c = -a;
total += b+c;
}
return total;
}
// Tests for multiplication.
int test_mult01(int a, int b) {
int total = 0;
if (3 <= a && a <= 11 && 5 <= b && b <= 23) {
int r = a*b; // 15 .. 253
total += r;
}
if (3 <= a && a <= 11 && 0 <= b && b <= 23) {
int r = a*b; // 0 .. 253
total += r;
}
if (3 <= a && a <= 11 && -13 <= b && b <= 23) {
int r = a*b; // -143 .. 253
total += r;
}
if (3 <= a && a <= 11 && -13 <= b && b <= 0) {
int r = a*b; // -143 .. 0
total += r;
}
if (3 <= a && a <= 11 && -13 <= b && b <= -7) {
int r = a*b; // -143 .. -21
total += r;
}
return total;
}
// Tests for multiplication.
int test_mult02(int a, int b) {
int total = 0;
if (0 <= a && a <= 11 && 5 <= b && b <= 23) {
int r = a*b; // 0 .. 253
total += r;
}
if (0 <= a && a <= 11 && 0 <= b && b <= 23) {
int r = a*b; // 0 .. 253
total += r;
}
if (0 <= a && a <= 11 && -13 <= b && b <= 23) {
int r = a*b; // -143 .. 253
total += r;
}
if (0 <= a && a <= 11 && -13 <= b && b <= 0) {
int r = a*b; // -143 .. 0
total += r;
}
if (0 <= a && a <= 11 && -13 <= b && b <= -7) {
int r = a*b; // -143 .. 0
total += r;
}
return total;
}
// Tests for multiplication.
int test_mult03(int a, int b) {
int total = 0;
if (-17 <= a && a <= 11 && 5 <= b && b <= 23) {
int r = a*b; // -391 .. 253
total += r;
}
if (-17 <= a && a <= 11 && 0 <= b && b <= 23) {
int r = a*b; // -391 .. 253
total += r;
}
if (-17 <= a && a <= 11 && -13 <= b && b <= 23) {
int r = a*b; // -391 .. 253
total += r;
}
if (-17 <= a && a <= 11 && -13 <= b && b <= 0) {
int r = a*b; // -143 .. 221
total += r;
}
if (-17 <= a && a <= 11 && -13 <= b && b <= -7) {
int r = a*b; // -143 .. 221
total += r;
}
return total;
}
// Tests for multiplication.
int test_mult04(int a, int b) {
int total = 0;
if (-17 <= a && a <= 0 && 5 <= b && b <= 23) {
int r = a*b; // -391 .. 0
total += r;
}
if (-17 <= a && a <= 0 && 0 <= b && b <= 23) {
int r = a*b; // -391 .. 0
total += r;
}
if (-17 <= a && a <= 0 && -13 <= b && b <= 23) {
int r = a*b; // -391 .. 221
total += r;
}
if (-17 <= a && a <= 0 && -13 <= b && b <= 0) {
int r = a*b; // 0 .. 221
total += r;
}
if (-17 <= a && a <= 0 && -13 <= b && b <= -7) {
int r = a*b; // 0 .. 221
total += r;
}
return total;
}
// Tests for multiplication.
int test_mult05(int a, int b) {
int total = 0;
if (-17 <= a && a <= -2 && 5 <= b && b <= 23) {
int r = a*b; // -391 .. -10
total += r;
}
if (-17 <= a && a <= -2 && 0 <= b && b <= 23) {
int r = a*b; // -391 .. 0
total += r;
}
if (-17 <= a && a <= -2 && -13 <= b && b <= 23) {
int r = a*b; // -391 .. 221
total += r;
}
if (-17 <= a && a <= -2 && -13 <= b && b <= 0) {
int r = a*b; // 0 .. 221
total += r;
}
if (-17 <= a && a <= -2 && -13 <= b && b <= -7) {
int r = a*b; // 14 .. 221
total += r;
}
return total;
}
int test16(int x) {
int d, i = 0;
if (x < 0) {
return -1;
}
while (i < 3) {
i++;
}
d = i;
if (x < 0) { // Comparison is always false.
if (d > -x) { // Unreachable code.
return 1;
}
}
return 0;
}
// Test ternary expression upper bounds.
unsigned int test_ternary01(unsigned int x) {
unsigned int y1, y2, y3, y4, y5, y6, y7, y8;
y1 = x < 100 ? x : 10; // y1 < 100
y2 = x >= 100 ? 10 : x; // y2 < 100
y3 = 0;
y4 = 0;
y5 = 0;
y6 = 0;
y7 = 0;
y8 = 0;
if (x < 300) {
y3 = x ?: 5; // y3 < 300
y4 = x ?: 500; // y4 <= 500
y5 = (x+1) ?: 500; // y5 <= 300
y6 = ((unsigned char)(x+1)) ?: 5; // y6 < 256
y7 = ((unsigned char)(x+1)) ?: 500; // y7 <= 500
y8 = ((unsigned short)(x+1)) ?: 500; // y8 <= 300
}
return y1 + y2 + y3 + y4 + y5 + y6 + y7 + y8;
}
// Test ternary expression lower bounds.
unsigned int test_ternary02(unsigned int x) {
unsigned int y1, y2, y3, y4, y5;
y1 = x > 100 ? x : 110; // y1 > 100
y2 = x <= 100 ? 110 : x; // y2 > 100
y3 = 1000;
y4 = 1000;
y5 = 1000;
if (x >= 300) {
y3 = (x-300) ?: 5; // y3 >= 0
y4 = (x-200) ?: 5; // y4 >= 100
y5 = ((unsigned char)(x-200)) ?: 5; // y6 >= 0
}
return y1 + y2 + y3 + y4 + y5;
}
// Test the comma expression.
unsigned int test_comma01(unsigned int x) {
unsigned int y = x < 100 ? x : 100;
unsigned int y1;
unsigned int y2;
y1 = (++y, y);
y2 = (y++, y += 3, y);
return y1 + y2;
}
void out(int i);
void test17() {
int i, j;
i = 10;
out(i); // 10
i = 10;
i += 10;
out(i); // 20
i = 40;
i -= 10;
out(i); // 30
i = j = 40;
out(i); // 40
i = (j += 10);
out(i); // 50
i = 20 + (j -= 10);
out(i); // 60
}
// Tests for unsigned multiplication.
int test_unsigned_mult01(unsigned int a, unsigned b) {
int total = 0;
if (3 <= a && a <= 11 && 5 <= b && b <= 23) {
int r = a*b; // 15 .. 253
total += r;
}
if (3 <= a && a <= 11 && 0 <= b && b <= 23) {
int r = a*b; // 0 .. 253
total += r;
}
if (3 <= a && a <= 11 && 13 <= b && b <= 23) {
int r = a*b; // 39 .. 253
total += r;
}
return total;
}
int test_unsigned_mult02(unsigned b) {
int total = 0;
if (5 <= b && b <= 23) {
int r = 11*b; // 55 .. 253
total += r;
}
if (0 <= b && b <= 23) {
int r = 11*b; // 0 .. 253
total += r;
}
if (13 <= b && b <= 23) {
int r = 11*b; // 143 .. 253
total += r;
}
return total;
}
unsigned long mult_rounding() {
unsigned long x, y, xy;
x = y = 1000000003UL; // 1e9 + 3
xy = x * y;
return xy; // BUG: upper bound should be >= 1000000006000000009UL
}
unsigned long mult_overflow() {
unsigned long x, y, xy;
x = 274177UL;
y = 67280421310721UL;
xy = x * y;
return xy; // BUG: upper bound should be >= 18446744073709551617UL
}
unsigned long mult_lower_bound(unsigned int ui, unsigned long ul) {
if (ui >= 10) {
unsigned long result = (unsigned long)ui * ui;
return result; // BUG: upper bound should be >= 18446744065119617025
}
if (ul >= 10) {
unsigned long result = ul * ul;
return result; // lower bound is correctly 0 (overflow is possible)
}
return 0;
}
unsigned long mul_assign(unsigned int ui) {
if (ui <= 10 && ui >= 2) {
ui *= ui + 0;
return ui; // 4 .. 100
}
unsigned int uiconst = 10;
uiconst *= 4;
unsigned long ulconst = 10;
ulconst *= 4;
return uiconst + ulconst; // 40 .. 40 for both
}
int mul_by_constant(int i, int j) {
if (i >= -1 && i <= 2) {
i = 5 * i;
out(i); // -5 .. 10
i = i * -3;
out(i); // -30 .. 15
i *= 7;
out(i); // -210 .. 105
i *= -11;
out(i); // -1155 .. 2310
}
if (i == -1) {
i = i * (int)0xffFFffFF; // fully converted literal is -1
out(i); // 1 .. 1
}
i = i * -1;
out( i); // -2^31 .. 2^31-1
signed char sc = 1;
i = (*&sc *= 2);
out(sc); // demonstrate that we couldn't analyze the LHS of the `*=` above...
out(i); // -128 .. 127 // ... but we can still bound its result by its type.
return 0;
}
int notequal_type_endpoint(unsigned n) {
out(n); // 0 ..
if (n > 0) {
out(n); // 1 ..
}
if (n != 0) {
out(n); // 1 ..
} else {
out(n); // 0 .. 0
}
if (!n) {
out(n); // 0 .. 0
} else {
out(n); // 1 ..
}
while (n != 0) {
n--; // 1 ..
}
out(n); // 0 .. 0
}
void notequal_refinement(short n) {
if (n < 0)
return;
if (n == 0) {
out(n); // 0 .. 0
} else {
out(n); // 1 ..
}
if (n) {
out(n); // 1 ..
} else {
out(n); // 0 .. 0
}
while (n != 0) {
n--; // 1 ..
}
out(n); // 0 .. 0
}
void notequal_variations(short n, float f) {
if (n != 0) {
if (n >= 0) {
out(n); // 1 .. [BUG: we can't handle `!=` coming first]
}
}
if (n >= 5) {
if (2 * n - 10 == 0) { // Same as `n == 10/2` (modulo overflow)
return;
}
out(n); // 6 ..
}
if (n != -32768 && n != -32767) {
out(n); // -32766 ..
}
if (n >= 0) {
n ? n : n; // ? 1.. : 0..0
!n ? n : n; // ? 0..0 : 1..
}
}
void two_bounds_from_one_test(short ss, unsigned short us) {
// These tests demonstrate how the range analysis is often able to deduce
// both an upper bound and a lower bound even when there is only one
// inequality in the source. For example `signedInt < 4U` establishes that
// `signedInt >= 0` since if `signedInt` were negative then it would be
// greater than 4 in the unsigned comparison.
if (ss < sizeof(int)) { // Lower bound added in `linearBoundFromGuard`
out(ss); // 0 .. 3
}
if (ss < 0x8001) { // Lower bound removed in `getDefLowerBounds`
out(ss); // -32768 .. 32767
}
if ((short)us >= 0) {
out(us); // 0 .. 32767
}
if ((short)us >= -1) {
out(us); // 0 .. 65535
}
if (ss >= sizeof(int)) { // test is true for negative numbers
out(ss); // -32768 .. 32767
}
if (ss + 1 < sizeof(int)) {
out(ss); // -1 .. 2
}
}
void widen_recursive_expr() {
int s;
for (s = 0; s < 10; s++) {
int result = s + s; // 0 .. 9 [BUG: upper bound is 15 due to widening]
out(result); // 0 .. 18 [BUG: upper bound is 127 due to double widening]
}
}
void guard_bound_out_of_range(void) {
int i = 0;
if (i < 0) {
out(i); // unreachable [BUG: is -max .. +max]
}
unsigned int u = 0;
if (u < 0) {
out(u); // unreachable [BUG: is 0 .. +max]
}
}
void test_mod(int s) {
int s2 = s % 5;
out(s2); // -4 .. 4
}
|
the_stack_data/7950363.c | /*
* COPYRIGHT
*
* fm.c
* Copyright (C) 2014 Exstrom Laboratories LLC
*
* 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.
*
* A copy of the GNU General Public License is available on the internet at:
* http://www.gnu.org/copyleft/gpl.html
*
* or you can write to:
*
* The Free Software Foundation, Inc.
* 675 Mass Ave
* Cambridge, MA 02139, USA
*
* Exstrom Laboratories LLC contact:
* stefan(AT)exstrom.com
*
* Exstrom Laboratories LLC
* Longmont, CO 80503, USA
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
// compile: gcc -lm -o fm fm.c
int main( int argc, char *argv[] )
{
if(argc < 6)
{
printf("Usage: %s f0 f1 r s n\n", argv[0]);
printf(" Produces a frequency modulated sine wave\n");
printf(" f0 = carrier frequency\n");
printf(" f1 = modulation frequency\n");
printf(" r = modulation index\n");
printf(" s = sampling frequency\n");
printf(" n = number of samples\n");
return(-1);
}
double f0 = strtod(argv[1],NULL);
double f1 = strtod(argv[2],NULL);
double r = strtod(argv[3], NULL);
double s = strtod(argv[4], NULL);
unsigned long i, n = atoi(argv[5]);
double p0 = 2.0*M_PI*f0/s;
double p1 = 2.0*M_PI*f1/s;
double y0 = 0.0;
double y1 = -sin(p1);
double y2 = 0.0;
double d = 2.0*cos(p1);
for(i=0; i<n; ++i)
{
printf("%lf\n", sin(p0*i + r*y0));
y2 = y1;
y1 = y0;
y0 = d*y1 - y2;
}
return(0);
}
|
the_stack_data/151705451.c | // for coverage purposes, this test assumes int and double are the same size
union { int i; double d; } id;
int main(void) {
id.d = id.i;
return id.d;
}
// strangely, I think the below is defined
// union { double i; double d; } id;
// int main(void) {
// id.d = (int)id.i;
// }
|
the_stack_data/708217.c | // RUN: %clang_analyze_cc1 %s \
// RUN: -analyzer-checker=core \
// RUN: -analyzer-checker=alpha.unix.cstring.OutOfBounds,alpha.unix.cstring.UninitializedRead \
// RUN: -analyzer-config eagerly-assume=false \
// RUN: -verify
// expected-no-diagnostics
typedef typeof(sizeof(int)) size_t;
void *memmove(void *, const void *, size_t);
typedef struct {
char a[1024];
} b;
int c;
b *invalidate();
int d() {
b *a = invalidate();
if (c < 1024)
return 0;
int f = c & ~3, g = f;
g--;
if (g)
return 0;
// Parent state is already infeasible.
// clang_analyzer_printState();
// "constraints": [
// { "symbol": "(derived_$3{conj_$0{int, LC1, S728, #1},c}) & -4", "range": "{ [1, 1] }" },
// { "symbol": "derived_$3{conj_$0{int, LC1, S728, #1},c}", "range": "{ [1024, 2147483647] }" }
// ],
// This sould not crash!
// It crashes in baseline, since there both true and false states are nullptr!
memmove(a->a, &a->a[f], c - f);
return 0;
}
|
the_stack_data/1121978.c | /* { dg-do compile { target { arm*-*-* || mips*-*-* } } } */
#include <stdlib.h>
#include <stdint.h>
int
main (void)
{
void *p = main;
if ((intptr_t) p & 1)
abort ();
return 0;
}
/* { dg-final { scan-assembler "abort" } } */
|
the_stack_data/14200572.c | // Copyright 2013 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <malloc.h>
const long long max_size = 2000; // max length of strings
const long long N = 40; // number of closest words that will be shown
const long long max_w = 50; // max length of vocabulary entries
#define _max_size 2000
#define _N 40
int main(int argc, char **argv) {
FILE *f;
char st1[_max_size];
char bestw[_N][_max_size];
char file_name[_max_size], st[100][_max_size];
float dist, len, bestd[_N], vec[_max_size];
long long words, size, a, b, c, d, cn, bi[100];
char ch;
float *M;
char *vocab;
if (argc < 2) {
printf("Usage: ./word-analogy <FILE>\nwhere FILE contains word projections in the BINARY FORMAT\n");
return 0;
}
strcpy(file_name, argv[1]);
f = fopen(file_name, "rb");
if (f == NULL) {
printf("Input file not found\n");
return -1;
}
fscanf(f, "%lld", &words);
fscanf(f, "%lld", &size);
vocab = (char *)malloc((long long)words * max_w * sizeof(char));
M = (float *)malloc((long long)words * (long long)size * sizeof(float));
if (M == NULL) {
printf("Cannot allocate memory: %lld MB %lld %lld\n", (long long)words * size * sizeof(float) / 1048576, words, size);
return -1;
}
for (b = 0; b < words; b++) {
a = 0;
while (1) {
vocab[b * max_w + a] = fgetc(f);
if (feof(f) || (vocab[b * max_w + a] == ' ')) break;
if ((a < max_w) && (vocab[b * max_w + a] != '\n')) a++;
}
vocab[b * max_w + a] = 0;
for (a = 0; a < size; a++) fread(&M[a + b * size], sizeof(float), 1, f);
len = 0;
for (a = 0; a < size; a++) len += M[a + b * size] * M[a + b * size];
len = sqrt(len);
for (a = 0; a < size; a++) M[a + b * size] /= len;
}
fclose(f);
while (1) {
for (a = 0; a < N; a++) bestd[a] = 0;
for (a = 0; a < N; a++) bestw[a][0] = 0;
printf("Enter three words (EXIT to break): ");
a = 0;
while (1) {
st1[a] = fgetc(stdin);
if ((st1[a] == '\n') || (a >= max_size - 1)) {
st1[a] = 0;
break;
}
a++;
}
if (!strcmp(st1, "EXIT")) break;
cn = 0;
b = 0;
c = 0;
while (1) {
st[cn][b] = st1[c];
b++;
c++;
st[cn][b] = 0;
if (st1[c] == 0) break;
if (st1[c] == ' ') {
cn++;
b = 0;
c++;
}
}
cn++;
if (cn < 3) {
printf("Only %lld words were entered.. three words are needed at the input to perform the calculation\n", cn);
continue;
}
for (a = 0; a < cn; a++) {
for (b = 0; b < words; b++) if (!strcmp(&vocab[b * max_w], st[a])) break;
if (b == words) b = 0;
bi[a] = b;
printf("\nWord: %s Position in vocabulary: %lld\n", st[a], bi[a]);
if (b == 0) {
printf("Out of dictionary word!\n");
break;
}
}
if (b == 0) continue;
printf("\n Word Distance\n------------------------------------------------------------------------\n");
for (a = 0; a < size; a++) vec[a] = M[a + bi[1] * size] - M[a + bi[0] * size] + M[a + bi[2] * size];
len = 0;
for (a = 0; a < size; a++) len += vec[a] * vec[a];
len = sqrt(len);
for (a = 0; a < size; a++) vec[a] /= len;
for (a = 0; a < N; a++) bestd[a] = 0;
for (a = 0; a < N; a++) bestw[a][0] = 0;
for (c = 0; c < words; c++) {
if (c == bi[0]) continue;
if (c == bi[1]) continue;
if (c == bi[2]) continue;
a = 0;
for (b = 0; b < cn; b++) if (bi[b] == c) a = 1;
if (a == 1) continue;
dist = 0;
for (a = 0; a < size; a++) dist += vec[a] * M[a + c * size];
for (a = 0; a < N; a++) {
if (dist > bestd[a]) {
for (d = N - 1; d > a; d--) {
bestd[d] = bestd[d - 1];
strcpy(bestw[d], bestw[d - 1]);
}
bestd[a] = dist;
strcpy(bestw[a], &vocab[c * max_w]);
break;
}
}
}
for (a = 0; a < N; a++) printf("%50s\t\t%f\n", bestw[a], bestd[a]);
}
return 0;
}
|
the_stack_data/20449924.c | /* chstack - set stack size */
#include <stdio.h>
#define OFF 48L /* offset of stacksize in file */
#define MAX 32768L /* maximum accepted stacksize */
main(argc, argv)
int argc;
char *argv[];
{
char *p;
long n;
int fd;
long current;
long old;
long atol(), lseek();
p = argv[1];
if (argc != 3 || (*p != '=' && *p != '+' && *p != '-')) {
fprintf(stderr, "Usage: %s {=+-}amount file\n", argv[0]);
exit(1);
}
n = atol(p+1);
fd = open(argv[2], 2);
if (fd < 0) {
fprintf(stderr, "%s: cannot open %s\n", argv[0], argv[2]);
exit(1);
}
if (lseek(fd, OFF, 0) < 0 || getlong(fd, ¤t) < 0) {
fprintf(stderr, "%s: cannot read %s\n", argv[0], argv[2]);
exit(1);
}
old = current;
if (*p == '=') current = n;
else if (*p == '-') current -= n;
else current += n;
if (current > MAX || current <= 0) {
fprintf(stderr, "%s: resulting stack size %ld too large or too small\n", argv[0], current);
exit(1);
}
if (lseek(fd, OFF, 0) < 0 || putlong(fd, ¤t) < 0) {
fprintf(stderr, "%s: can't modify %s\n", argv[0], argv[2]);
exit(1);
}
printf("%s: Stack area changed from %ld to %ld bytes.\n",
argv[2], old, current);
exit(0);
}
getlong(fd, l)
long *l;
{
char buf[4];
if (read(fd, buf, 4) < 4) return -1;
*l = ((((long)(buf[3]&0377)<<8)|(long)(buf[2]&0377)<<8)|(long)(buf[1]&0377)<<8)|(long)(buf[0]&0377);
return 0;
}
putlong(fd, l)
long *l;
{
char buf[4];
buf[3] = *l >> 24;
buf[2] = *l >> 16;
buf[1] = *l >> 8;
buf[0] = *l;
if (write(fd, buf, 4) < 4) return -1;
return 0;
}
|
the_stack_data/98575691.c | // Tests for 3C.
//
// Tests properties about rewriter for return type when it is an itype
//
// RUN: 3c -alltypes %s -- | FileCheck -match-full-lines %s
//
static int funcvar;
static int funcdecvar;
// we test propagation with and without function
// declaration.
static int* funcdecl(int *ptr, int *iptr, int *wild);
static int* funcdecl(int *ptr, int *iptr, int *wild) {
if(ptr != 0) {
*ptr = 0;
}
wild = (int*)0xdeadbeef;
return &funcdecvar;
}
//CHECK: static int *funcdecl(_Ptr<int> ptr, int *iptr : itype(_Ptr<int>), int *wild) : itype(_Ptr<int>);
//CHECK-NEXT: static int *funcdecl(_Ptr<int> ptr, int *iptr : itype(_Ptr<int>), int *wild) : itype(_Ptr<int>) {
// ptr is a regular _Ptr
// iptr will be itype
// wild will be a wild ptr.
static int* func(int *ptr, int *iptr, int *wild) {
if(ptr != 0) {
*ptr = 0;
}
wild = (int*)0xdeadbeef;
return &funcvar;
}
//CHECK: static int *func(_Ptr<int> ptr, int *iptr : itype(_Ptr<int>), int *wild) : itype(_Ptr<int>) {
int main() {
int a, b, c;
int *ap = 0;
int *bp = 0;
int *cp = 0;
int *ap1 = 0;
int *bp1 = 0;
int *cp1 = 0;
ap1 = ap = &a;
// we will make this pointer wild.
bp1 = bp = (int*)0xcafeba;
cp = &c;
cp1 = &c;
// we are passing cp
// to a parameter that will be
// treated as WILD in func, so it
// must also be, in main
bp = func(ap, bp, cp);
bp1 = funcdecl(ap1, bp1, cp1);
return 0;
}
//CHECK: int main() {
//CHECK-NEXT: int a, b, c;
//CHECK-NEXT: _Ptr<int> ap = 0;
//CHECK-NEXT: int *bp = 0;
//CHECK-NEXT: int *cp = 0;
//CHECK-NEXT: _Ptr<int> ap1 = 0;
//CHECK-NEXT: int *bp1 = 0;
//CHECK-NEXT: int *cp1 = 0;
|
the_stack_data/103265441.c | #include <stdio.h>
#include <stdlib.h>
int putData(int**, const int, const int);
void printData(const int**, const int, const int);
int main(void)
{
int n, m;
int i;
scanf("%d %d", &n, &m);
int** arr = (int**)malloc(sizeof(int*) * n);
if (arr == NULL) exit(EXIT_FAILURE);
for (i = 0; i < n; i++) // 주의: 'n번' 할당해야 한다. Caution: Allocate spaces for n times
{
arr[i] = (int*)malloc(sizeof(int) * m); // Allocate (m * int) size space
if (arr[i] == NULL) exit(EXIT_FAILURE);
}
putData(arr, n, m);
printData(arr, n, m);
for (i = 0; i < n; i++)
free(arr[i]);
free(arr);
return 0;
}
int putData(int** target, const int n, const int m)
{
int num = 1;
int i, j, x = 0, y = -1;
int direction = 1;
int iEnd = n - 1, jEnd = m;
const int maxNum = n * m;
while (num <= maxNum)
{
for (j = 0; j < jEnd; j++)
{
y += direction;
target[x][y] = num++;
}
jEnd--;
for (i = 0; i < iEnd; i++)
{
x += direction;
target[x][y] = num++;
}
iEnd--;
direction *= -1;
}
return 0;
}
void printData(const int** target, const int n, const int m)
{
int i, j;
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
printf(" %d", target[i][j]);
putchar('\n');
}
}
|
the_stack_data/19194.c | #include <stdlib.h>
int main()
{
double x = 1.0;
double y = 2.0;
if ((y > x--) != 1)
abort ();
exit (0);
}
|
the_stack_data/136363.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* print_bits.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vokrut <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/06 21:22:13 by vokrut #+# #+# */
/* Updated: 2019/03/06 21:23:39 by vokrut ### ########.fr */
/* */
/* ************************************************************************** */
/* Assignment name : print_bits
Expected files : print_bits.c
Allowed functions: write
--------------------------------------------------------------------------------
Write a function that takes a byte, and prints it in binary WITHOUT A NEWLINE
AT THE END.
Your function must be declared as follows:
void print_bits(unsigned char octet);
Example, if you pass 2 to print_bits, it will print "00000010" */
#include <unistd.h>
void print_bits(unsigned char octet)
{
unsigned char num;
num = 128;
while (num)
{
if (octet & num)
write(1, "1", 1);
else
write(1, "0", 1);
num = num >> 1;
}
} |
the_stack_data/111425.c | /* mbed Microcontroller Library
*******************************************************************************
* Copyright (c) 2017, STMicroelectronics
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#if DEVICE_SERIAL
#include "serial_api_hal.h"
#define UART_NUM (9)
uint32_t serial_irq_ids[UART_NUM] = {0};
UART_HandleTypeDef uart_handlers[UART_NUM];
static uart_irq_handler irq_handler;
// Defined in serial_api.c
extern int8_t get_uart_index(UARTName uart_name);
/******************************************************************************
* INTERRUPTS HANDLING
******************************************************************************/
static void uart_irq(UARTName uart_name)
{
int8_t id = get_uart_index(uart_name);
if (id >= 0) {
UART_HandleTypeDef *huart = &uart_handlers[id];
if (serial_irq_ids[id] != 0) {
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_TXE) != RESET) {
if (__HAL_UART_GET_IT(huart, UART_IT_TXE) != RESET && __HAL_UART_GET_IT_SOURCE(huart, UART_IT_TXE)) {
irq_handler(serial_irq_ids[id], TxIrq);
}
}
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_RXNE) != RESET) {
if (__HAL_UART_GET_IT(huart, UART_IT_RXNE) != RESET && __HAL_UART_GET_IT_SOURCE(huart, UART_IT_RXNE)) {
irq_handler(serial_irq_ids[id], RxIrq);
/* Flag has been cleared when reading the content */
}
}
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE) != RESET) {
if (__HAL_UART_GET_IT(huart, UART_IT_ORE) != RESET) {
__HAL_UART_CLEAR_IT(huart, UART_CLEAR_OREF);
}
}
}
}
}
#if defined(USART1_BASE)
static void uart1_irq(void)
{
uart_irq(UART_1);
}
#endif
#if defined(USART2_BASE)
static void uart2_irq(void)
{
uart_irq(UART_2);
}
#endif
#if defined(USART3_BASE)
static void uart3_irq(void)
{
uart_irq(UART_3);
}
#endif
#if defined(UART4_BASE)
static void uart4_irq(void)
{
uart_irq(UART_4);
}
#endif
#if defined(UART5_BASE)
static void uart5_irq(void)
{
uart_irq(UART_5);
}
#endif
#if defined(USART6_BASE)
static void uart6_irq(void)
{
uart_irq(UART_6);
}
#endif
#if defined(UART7_BASE)
static void uart7_irq(void)
{
uart_irq(UART_7);
}
#endif
#if defined(UART8_BASE)
static void uart8_irq(void)
{
uart_irq(UART_8);
}
#endif
#if defined(LPUART1_BASE)
static void lpuart1_irq(void)
{
uart_irq(LPUART_1);
}
#endif
void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id)
{
struct serial_s *obj_s = SERIAL_S(obj);
irq_handler = handler;
serial_irq_ids[obj_s->index] = id;
}
void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
IRQn_Type irq_n = (IRQn_Type)0;
uint32_t vector = 0;
switch (obj_s->uart) {
#if defined(USART1_BASE)
case UART_1:
irq_n = USART1_IRQn;
vector = (uint32_t)&uart1_irq;
break;
#endif
#if defined(USART2_BASE)
case UART_2:
irq_n = USART2_IRQn;
vector = (uint32_t)&uart2_irq;
break;
#endif
#if defined(USART3_BASE)
case UART_3:
irq_n = USART3_IRQn;
vector = (uint32_t)&uart3_irq;
break;
#endif
#if defined(UART4_BASE)
case UART_4:
irq_n = UART4_IRQn;
vector = (uint32_t)&uart4_irq;
break;
#endif
#if defined(UART5_BASE)
case UART_5:
irq_n = UART5_IRQn;
vector = (uint32_t)&uart5_irq;
break;
#endif
#if defined(USART6_BASE)
case UART_6:
irq_n = USART6_IRQn;
vector = (uint32_t)&uart6_irq;
break;
#endif
#if defined(UART7_BASE)
case UART_7:
irq_n = UART7_IRQn;
vector = (uint32_t)&uart7_irq;
break;
#endif
#if defined(UART8_BASE)
case UART_8:
irq_n = UART8_IRQn;
vector = (uint32_t)&uart8_irq;
break;
#endif
#if defined(LPUART1_BASE)
case LPUART_1:
irq_n = LPUART1_IRQn;
vector = (uint32_t)&lpuart1_irq;
break;
#endif
}
if (enable) {
if (irq == RxIrq) {
__HAL_UART_ENABLE_IT(huart, UART_IT_RXNE);
} else { // TxIrq
__HAL_UART_ENABLE_IT(huart, UART_IT_TXE);
}
NVIC_SetVector(irq_n, vector);
NVIC_EnableIRQ(irq_n);
} else { // disable
int all_disabled = 0;
if (irq == RxIrq) {
__HAL_UART_DISABLE_IT(huart, UART_IT_RXNE);
// Check if TxIrq is disabled too
if ((huart->Instance->CR1 & USART_CR1_TXEIE) == 0) {
all_disabled = 1;
}
} else { // TxIrq
__HAL_UART_DISABLE_IT(huart, UART_IT_TXE);
// Check if RxIrq is disabled too
if ((huart->Instance->CR1 & USART_CR1_RXNEIE) == 0) {
all_disabled = 1;
}
}
if (all_disabled) {
NVIC_DisableIRQ(irq_n);
}
}
}
/******************************************************************************
* READ/WRITE
******************************************************************************/
int serial_getc(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
while (!serial_readable(obj));
return (int)(huart->Instance->RDR & 0x1FF);
}
void serial_putc(serial_t *obj, int c)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
while (!serial_writable(obj));
huart->Instance->TDR = (uint32_t)(c & 0x1FF);
}
void serial_clear(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
__HAL_UART_CLEAR_IT(huart, UART_FLAG_TXE);
__HAL_UART_CLEAR_IT(huart, UART_FLAG_RXNE);
}
void serial_break_set(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
HAL_LIN_SendBreak(huart);
}
#if DEVICE_SERIAL_ASYNCH
/******************************************************************************
* LOCAL HELPER FUNCTIONS
******************************************************************************/
/**
* Configure the TX buffer for an asynchronous write serial transaction
*
* @param obj The serial object.
* @param tx The buffer for sending.
* @param tx_length The number of words to transmit.
*/
static void serial_tx_buffer_set(serial_t *obj, void *tx, int tx_length, uint8_t width)
{
(void)width;
// Exit if a transmit is already on-going
if (serial_tx_active(obj)) {
return;
}
obj->tx_buff.buffer = tx;
obj->tx_buff.length = tx_length;
obj->tx_buff.pos = 0;
}
/**
* Configure the RX buffer for an asynchronous write serial transaction
*
* @param obj The serial object.
* @param tx The buffer for sending.
* @param tx_length The number of words to transmit.
*/
static void serial_rx_buffer_set(serial_t *obj, void *rx, int rx_length, uint8_t width)
{
(void)width;
// Exit if a reception is already on-going
if (serial_rx_active(obj)) {
return;
}
obj->rx_buff.buffer = rx;
obj->rx_buff.length = rx_length;
obj->rx_buff.pos = 0;
}
/**
* Configure events
*
* @param obj The serial object
* @param event The logical OR of the events to configure
* @param enable Set to non-zero to enable events, or zero to disable them
*/
static void serial_enable_event(serial_t *obj, int event, uint8_t enable)
{
struct serial_s *obj_s = SERIAL_S(obj);
// Shouldn't have to enable interrupt here, just need to keep track of the requested events.
if (enable) {
obj_s->events |= event;
} else {
obj_s->events &= ~event;
}
}
/**
* Get index of serial object TX IRQ, relating it to the physical peripheral.
*
* @param uart_name i.e. UART_1, UART_2, ...
* @return internal NVIC TX IRQ index of U(S)ART peripheral
*/
static IRQn_Type serial_get_irq_n(UARTName uart_name)
{
IRQn_Type irq_n;
switch (uart_name) {
#if defined(USART1_BASE)
case UART_1:
irq_n = USART1_IRQn;
break;
#endif
#if defined(USART2_BASE)
case UART_2:
irq_n = USART2_IRQn;
break;
#endif
#if defined(USART3_BASE)
case UART_3:
irq_n = USART3_IRQn;
break;
#endif
#if defined(UART4_BASE)
case UART_4:
irq_n = UART4_IRQn;
break;
#endif
#if defined(UART5_BASE)
case UART_5:
irq_n = UART5_IRQn;
break;
#endif
#if defined(USART6_BASE)
case UART_6:
irq_n = USART6_IRQn;
break;
#endif
#if defined(UART7_BASE)
case UART_7:
irq_n = UART7_IRQn;
break;
#endif
#if defined(UART8_BASE)
case UART_8:
irq_n = UART8_IRQn;
break;
#endif
default:
irq_n = (IRQn_Type)0;
}
return irq_n;
}
/******************************************************************************
* MBED API FUNCTIONS
******************************************************************************/
/**
* Begin asynchronous TX transfer. The used buffer is specified in the serial
* object, tx_buff
*
* @param obj The serial object
* @param tx The buffer for sending
* @param tx_length The number of words to transmit
* @param tx_width The bit width of buffer word
* @param handler The serial handler
* @param event The logical OR of events to be registered
* @param hint A suggestion for how to use DMA with this transfer
* @return Returns number of data transfered, or 0 otherwise
*/
int serial_tx_asynch(serial_t *obj, const void *tx, size_t tx_length, uint8_t tx_width, uint32_t handler, uint32_t event, DMAUsage hint)
{
// TODO: DMA usage is currently ignored
(void) hint;
// Check buffer is ok
MBED_ASSERT(tx != (void *)0);
MBED_ASSERT(tx_width == 8); // support only 8b width
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
if (tx_length == 0) {
return 0;
}
// Set up buffer
serial_tx_buffer_set(obj, (void *)tx, tx_length, tx_width);
// Set up events
serial_enable_event(obj, SERIAL_EVENT_TX_ALL, 0); // Clear all events
serial_enable_event(obj, event, 1); // Set only the wanted events
// Enable interrupt
IRQn_Type irq_n = serial_get_irq_n(obj_s->uart);
NVIC_ClearPendingIRQ(irq_n);
NVIC_DisableIRQ(irq_n);
NVIC_SetPriority(irq_n, 1);
NVIC_SetVector(irq_n, (uint32_t)handler);
NVIC_EnableIRQ(irq_n);
// the following function will enable UART_IT_TXE and error interrupts
if (HAL_UART_Transmit_IT(huart, (uint8_t *)tx, tx_length) != HAL_OK) {
return 0;
}
return tx_length;
}
/**
* Begin asynchronous RX transfer (enable interrupt for data collecting)
* The used buffer is specified in the serial object, rx_buff
*
* @param obj The serial object
* @param rx The buffer for sending
* @param rx_length The number of words to transmit
* @param rx_width The bit width of buffer word
* @param handler The serial handler
* @param event The logical OR of events to be registered
* @param handler The serial handler
* @param char_match A character in range 0-254 to be matched
* @param hint A suggestion for how to use DMA with this transfer
*/
void serial_rx_asynch(serial_t *obj, void *rx, size_t rx_length, uint8_t rx_width, uint32_t handler, uint32_t event, uint8_t char_match, DMAUsage hint)
{
// TODO: DMA usage is currently ignored
(void) hint;
/* Sanity check arguments */
MBED_ASSERT(obj);
MBED_ASSERT(rx != (void *)0);
MBED_ASSERT(rx_width == 8); // support only 8b width
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
serial_enable_event(obj, SERIAL_EVENT_RX_ALL, 0);
serial_enable_event(obj, event, 1);
// set CharMatch
obj->char_match = char_match;
serial_rx_buffer_set(obj, rx, rx_length, rx_width);
IRQn_Type irq_n = serial_get_irq_n(obj_s->uart);
NVIC_ClearPendingIRQ(irq_n);
NVIC_DisableIRQ(irq_n);
NVIC_SetPriority(irq_n, 0);
NVIC_SetVector(irq_n, (uint32_t)handler);
NVIC_EnableIRQ(irq_n);
// following HAL function will enable the RXNE interrupt + error interrupts
HAL_UART_Receive_IT(huart, (uint8_t *)rx, rx_length);
}
/**
* Attempts to determine if the serial peripheral is already in use for TX
*
* @param obj The serial object
* @return Non-zero if the TX transaction is ongoing, 0 otherwise
*/
uint8_t serial_tx_active(serial_t *obj)
{
MBED_ASSERT(obj);
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
return (((HAL_UART_GetState(huart) & HAL_UART_STATE_BUSY_TX) == HAL_UART_STATE_BUSY_TX) ? 1 : 0);
}
/**
* Attempts to determine if the serial peripheral is already in use for RX
*
* @param obj The serial object
* @return Non-zero if the RX transaction is ongoing, 0 otherwise
*/
uint8_t serial_rx_active(serial_t *obj)
{
MBED_ASSERT(obj);
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
return (((HAL_UART_GetState(huart) & HAL_UART_STATE_BUSY_RX) == HAL_UART_STATE_BUSY_RX) ? 1 : 0);
}
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
{
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_TC) != RESET) {
__HAL_UART_CLEAR_IT(huart, UART_CLEAR_TCF);
}
}
void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
{
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_PE) != RESET) {
__HAL_UART_CLEAR_IT(huart, UART_CLEAR_PEF);
}
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_FE) != RESET) {
__HAL_UART_CLEAR_IT(huart, UART_CLEAR_FEF);
}
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_NE) != RESET) {
__HAL_UART_CLEAR_IT(huart, UART_CLEAR_NEF);
}
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE) != RESET) {
__HAL_UART_CLEAR_IT(huart, UART_CLEAR_OREF);
}
}
/**
* The asynchronous TX and RX handler.
*
* @param obj The serial object
* @return Returns event flags if a TX/RX transfer termination condition was met or 0 otherwise
*/
int serial_irq_handler_asynch(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
volatile int return_event = 0;
uint8_t *buf = (uint8_t *)(obj->rx_buff.buffer);
uint8_t i = 0;
// TX PART:
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_TC) != RESET) {
if (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_TC) != RESET) {
// Return event SERIAL_EVENT_TX_COMPLETE if requested
if ((obj_s->events & SERIAL_EVENT_TX_COMPLETE) != 0) {
return_event |= (SERIAL_EVENT_TX_COMPLETE & obj_s->events);
}
}
}
// Handle error events
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_PE) != RESET) {
if (__HAL_UART_GET_IT(huart, UART_IT_PE) != RESET) {
return_event |= (SERIAL_EVENT_RX_PARITY_ERROR & obj_s->events);
}
}
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_FE) != RESET) {
if (__HAL_UART_GET_IT(huart, UART_IT_FE) != RESET) {
return_event |= (SERIAL_EVENT_RX_FRAMING_ERROR & obj_s->events);
}
}
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE) != RESET) {
if (__HAL_UART_GET_IT(huart, UART_IT_ORE) != RESET) {
return_event |= (SERIAL_EVENT_RX_OVERRUN_ERROR & obj_s->events);
}
}
HAL_UART_IRQHandler(huart);
// Abort if an error occurs
if ((return_event & SERIAL_EVENT_RX_PARITY_ERROR) ||
(return_event & SERIAL_EVENT_RX_FRAMING_ERROR) ||
(return_event & SERIAL_EVENT_RX_OVERRUN_ERROR)) {
return return_event;
}
//RX PART
if (huart->RxXferSize != 0) {
obj->rx_buff.pos = huart->RxXferSize - huart->RxXferCount;
}
if ((huart->RxXferCount == 0) && (obj->rx_buff.pos >= (obj->rx_buff.length - 1))) {
return_event |= (SERIAL_EVENT_RX_COMPLETE & obj_s->events);
}
// Check if char_match is present
if (obj_s->events & SERIAL_EVENT_RX_CHARACTER_MATCH) {
if (buf != NULL) {
for (i = 0; i < obj->rx_buff.pos; i++) {
if (buf[i] == obj->char_match) {
obj->rx_buff.pos = i;
return_event |= (SERIAL_EVENT_RX_CHARACTER_MATCH & obj_s->events);
serial_rx_abort_asynch(obj);
break;
}
}
}
}
return return_event;
}
/**
* Abort the ongoing TX transaction. It disables the enabled interupt for TX and
* flush TX hardware buffer if TX FIFO is used
*
* @param obj The serial object
*/
void serial_tx_abort_asynch(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
__HAL_UART_DISABLE_IT(huart, UART_IT_TC);
__HAL_UART_DISABLE_IT(huart, UART_IT_TXE);
// clear flags
__HAL_UART_CLEAR_IT(huart, UART_FLAG_TC);
// reset states
huart->TxXferCount = 0;
// update handle state
if (huart->gState == HAL_UART_STATE_BUSY_TX_RX) {
huart->gState = HAL_UART_STATE_BUSY_RX;
} else {
huart->gState = HAL_UART_STATE_READY;
}
}
/**
* Abort the ongoing RX transaction It disables the enabled interrupt for RX and
* flush RX hardware buffer if RX FIFO is used
*
* @param obj The serial object
*/
void serial_rx_abort_asynch(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
// disable interrupts
__HAL_UART_DISABLE_IT(huart, UART_IT_RXNE);
__HAL_UART_DISABLE_IT(huart, UART_IT_PE);
__HAL_UART_DISABLE_IT(huart, UART_IT_ERR);
// clear flags
volatile uint32_t tmpval __attribute__((unused)) = huart->Instance->RDR; // Clear RXNE
__HAL_UART_CLEAR_IT(huart, UART_CLEAR_PEF);
__HAL_UART_CLEAR_IT(huart, UART_CLEAR_FEF);
__HAL_UART_CLEAR_IT(huart, UART_CLEAR_NEF);
__HAL_UART_CLEAR_IT(huart, UART_CLEAR_OREF);
// reset states
huart->RxXferCount = 0;
// update handle state
if (huart->RxState == HAL_UART_STATE_BUSY_TX_RX) {
huart->RxState = HAL_UART_STATE_BUSY_TX;
} else {
huart->RxState = HAL_UART_STATE_READY;
}
}
#endif /* DEVICE_SERIAL_ASYNCH */
#if DEVICE_SERIAL_FC
/**
* Set HW Control Flow
* @param obj The serial object
* @param type The Control Flow type (FlowControlNone, FlowControlRTS, FlowControlCTS, FlowControlRTSCTS)
* @param rxflow Pin for the rxflow
* @param txflow Pin for the txflow
*/
void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow)
{
struct serial_s *obj_s = SERIAL_S(obj);
// Checked used UART name (UART_1, UART_2, ...)
UARTName uart_rts = (UARTName)pinmap_peripheral(rxflow, PinMap_UART_RTS);
UARTName uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS);
if (((UARTName)pinmap_merge(uart_rts, obj_s->uart) == (UARTName)NC) || ((UARTName)pinmap_merge(uart_cts, obj_s->uart) == (UARTName)NC)) {
MBED_ASSERT(0);
return;
}
if (type == FlowControlNone) {
// Disable hardware flow control
obj_s->hw_flow_ctl = UART_HWCONTROL_NONE;
}
if (type == FlowControlRTS) {
// Enable RTS
MBED_ASSERT(uart_rts != (UARTName)NC);
obj_s->hw_flow_ctl = UART_HWCONTROL_RTS;
obj_s->pin_rts = rxflow;
// Enable the pin for RTS function
pinmap_pinout(rxflow, PinMap_UART_RTS);
}
if (type == FlowControlCTS) {
// Enable CTS
MBED_ASSERT(uart_cts != (UARTName)NC);
obj_s->hw_flow_ctl = UART_HWCONTROL_CTS;
obj_s->pin_cts = txflow;
// Enable the pin for CTS function
pinmap_pinout(txflow, PinMap_UART_CTS);
}
if (type == FlowControlRTSCTS) {
// Enable CTS & RTS
MBED_ASSERT(uart_rts != (UARTName)NC);
MBED_ASSERT(uart_cts != (UARTName)NC);
obj_s->hw_flow_ctl = UART_HWCONTROL_RTS_CTS;
obj_s->pin_rts = rxflow;
obj_s->pin_cts = txflow;
// Enable the pin for CTS function
pinmap_pinout(txflow, PinMap_UART_CTS);
// Enable the pin for RTS function
pinmap_pinout(rxflow, PinMap_UART_RTS);
}
init_uart(obj);
}
#endif /* DEVICE_SERIAL_FC */
#endif /* DEVICE_SERIAL */
|
the_stack_data/928.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* _1_aff_first_param.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dakim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/08/10 12:24:44 by dakim #+# #+# */
/* Updated: 2018/08/10 12:45:10 by dakim ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putchar(char c)
{
write(1, &c, 1);
}
char ft_aff_first_param(char *str)
{
int i;
i = 0;
while (str[i] != '\0')
{
ft_putchar(str[i]);
i++;
}
ft_putchar('\n');
return (*str);
}
int main(int argc, char **argv)
{
if (argc < 2)
{
ft_putchar('\n');
}
else
{
ft_aff_first_param(argv[1]);
}
return (0);
}
|
the_stack_data/98574519.c | #include <stdio.h>
#include <assert.h>
#include <string.h>
#include <stdint.h>
/*
* Unions are structs where each field shares the same memory position.
*/
union variant
{ // Bytes:
unsigned char ch; // 1
unsigned short sh; // 2
};
void test_variant()
{
union variant v;
v.ch = 16;
assert(v.ch == 16);
v.sh = 16;
assert(v.ch == 16);
v.sh = 128;
assert(v.ch == 128);
v.sh = 1000;
assert(v.ch == 232);
}
union mixed
{
unsigned char bytes[4];
struct { unsigned short hi, lo; } word;
uint32_t uint;
} m;
void test_mixed()
{
m.uint = 0xF00F00FF;
assert(m.word.lo == 0xF00F);
assert(m.word.hi == 0x00FF);
assert(m.bytes[0] == 0xFF);
assert(m.bytes[1] == 0x00);
assert(m.bytes[2] == 0x0F);
assert(m.bytes[3] == 0xF0);
}
int main(void)
{
test_variant();
test_mixed();
return 0;
} |
the_stack_data/150144070.c | /*str1 = "Sun is out today"
str2 = "soiyt"
Remove all chars in str2 from str1
str1 = "un u da"
*/
#include<stdio.h>
#include<string.h>
#include<stdbool.h>
#define CHARS 256
int remove_s(char str1[], char str2[]) {
if(str1== NULL) {
return -1;
}
if(str2 == NULL) {
printf("%s", str1);
return 0;
}
int len1 = strlen(str1);
int len2 = strlen(str2);
if(len1 == 0) {
return -1;
}
if(len2 == 0) {
printf("%s", str1);
return 0;
}
bool hit[CHARS];
for(int i=0; i<CHARS; i++) {
hit[i] = false;
}
for(int i=0; i<len2; i++) {
hit[str2[i]] = true;
if(str2[i] >='a' && str2[i] <= 'z') {
int index = str2[i] - 'a';
hit['A' + index] = true;
}
if(str2[i] >='A' && str2[i] <= 'Z') {
int index = str2[i] - 'A';
hit['a' + index] = true;
}
}
int end = 0;
for(int i=0; i<len1; i++) {
if(hit[str1[i]] == false) {
str1[end] = str1[i];
end++;
}
}
str1[end] = '\0';
printf("%s", str1);
return 0;
}
void main() {
char str1[] = "Sun is out today";
char str2[] = "soiyt";
remove_s(str1, str2);
}
|
the_stack_data/18888857.c | #include <stdio.h>
/*
* We need some functions that cannot be optimized away by the compiler
* so put them into this separate module so that it cannot see them where they
* are used
*/
extern void** stack_ref_low;
extern void** stack_ref_high;
extern int verbose_gc;
void set_stack_high(void** stack_high)
{
stack_ref_high = stack_high;
if (verbose_gc) {
fprintf(stderr, "stack high = 0x%llx\n", (long long unsigned)stack_high);
}
}
void set_stack_low(void** stack_low)
{
stack_ref_low = stack_low;
if (verbose_gc) {
fprintf(stderr, "stack low = 0x%llx\n", (long long unsigned)stack_low);
}
}
|
the_stack_data/212644077.c | #include <stdio.h>
#include <stdlib.h>
int compareFunc(const void *voidA, const void *voidB) {
int a = (*(int *)voidA);
int b = (*(int *)voidB);
if (a < b) {
return -1;
} else if (a > b) {
return 1;
} else {
return 0;
}
}
double arrayMedian(int intArray[], int ARRAY_SIZE) {
// Call qsort here to ensure the array is sorted before computing median
qsort(intArray, ARRAY_SIZE, sizeof(int), compareFunc);
if (ARRAY_SIZE % 2 == 1) {
printf("Is it divisible by 2? %d\n", ARRAY_SIZE % 2 == 1);
printf("{Median is: %d\n", intArray[ARRAY_SIZE / 2]);
return intArray[ARRAY_SIZE / 2];
} else {
int midpoint = ARRAY_SIZE / 2;
printf("Midpoint is %d\n", midpoint);
printf("Average of %d and %d is %d\n", intArray[midpoint - 1],
intArray[midpoint],
(intArray[midpoint - 1] + intArray[midpoint]) / 2);
return (intArray[midpoint - 1] + intArray[midpoint]) / 2;
}
}
int main() {
int NUM_AGENTS = 3;
int NUM_MONTHS = 12;
int sales[3][12] = {
{1856, 498, 30924, 87478, 328, 2653, 387, 3754, 387587, 2873, 276, 32},
{5865, 5456, 3983, 6464, 9957, 4785, 3875, 3838, 4959, 1122, 7766, 2534},
{23, 55, 67, 99, 265, 376, 232, 223, 4546, 564, 4544, 3434},
};
int w = sizeof(sales) / sizeof(sales[0]);
double highestMedian = arrayMedian(sales[0], 12);
double agentAverage;
int agentWithHighestMedian = 0;
for (int agent = 1; agent < 3; agent++) {
agentAverage = arrayMedian(sales[agent], 12);
if (agentAverage > highestMedian) {
highestMedian = agentAverage;
agentWithHighestMedian = agent;
} else {
printf("Highest monthly median: %g\n", highestMedian);
printf("Highest monthly median comes from: %d\n", agentWithHighestMedian);
}
}
return 0;
} |
the_stack_data/75138808.c | #include <stdio.h>
int main()
{
struct pixel {
int horz;
int vert;
char color;
};
struct pixel center;
center.horz = 320;
center.vert = 240;
center.color = 'r';
printf("The pixel at %d,%d is colored ",
center.horz,
center.vert
);
switch(center.color)
{
case 'r':
puts("red");
break;
case 'g':
puts("green");
break;
case 'b':
puts("blue");
break;
default:
puts("Invalid");
}
return(0);
}
|
the_stack_data/73685.c | // # tst ######################################################################
// @todo: measure time with overrides as well, so it works as benchmark.
// double (*benchmark)() = 0;
// unit() { now = benchmark(); }
// test() { ... }
int unit(const char *name);
int test(int expr);
#ifdef TEST_C
#pragma once
#include <stdio.h>
static __thread int right = 0, wrong = 0;
static __thread const char *suite = "";
int unit(const char *name) {
suite = name;
right = wrong = 0;
return 1;
}
int test(int expr) {
right = right + !!expr;
wrong = wrong + !expr;
char buffer[1024];
sprintf(buffer, "%s%c Unit '%s': test %d/%d %s", // (%5.2f%%)",
!expr ? "!" : "",
"NY"[expr && !wrong],
suite,
right, right+wrong,
!expr ? "FAILED" : "passed"
//,100.f * right / (right+wrong)
);
#if 1
fprintf(stderr, "%s\n", buffer[0] == '!' ? buffer+1 : buffer);
fflush(stderr);
#else
LOG(TEST, "%s", buffer);
#endif
return !!expr;
}
#ifdef TEST_DEMO
int main() {
if( unit( "1st unit" ) ) {
test( 1 < 4 );
test( 2 < 4 );
test( 3 < 4 );
}
if( unit( "2nd unit") ) {
test( 10 < 10 ); // <-- shall fail here
}
if( unit( "3rd unit" ) ) {
test( 1 < 2 );
}
}
#define main main__
#endif // TEST_DEMO
#endif // TEST_C
|
the_stack_data/218892491.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#define BUFFER_SIZE 512
#define PORT 6000
int cree_socket_tcp_client() {
struct sockaddr_in adresse;
int sock;
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
fprintf(stderr, "Erreur socket\n");
return -1;
}
memset(&adresse, 0, sizeof(struct sockaddr_in));
adresse.sin_family = AF_INET;
adresse.sin_port = htons(PORT);
adresse.sin_addr.s_addr = htons(INADDR_ANY);
if (connect(sock, (struct sockaddr*) &adresse, sizeof(struct sockaddr_in)) < 0) {
close(sock);
fprintf(stderr, "Erreur connect\n");
return -1;
}
return sock;
}
int affiche_adresse_socket(int sock) {
struct sockaddr_in adresse;
socklen_t longueur;
longueur = sizeof(struct sockaddr_in);
if (getsockname(sock, (struct sockaddr*)&adresse, &longueur) < 0) {
fprintf(stderr, "Erreur getsockname\n");
return -1;
}
printf("IP = %c, Port = %u\n", inet_ntoa(adresse.sin_addr), ntohs(adresse.sin_port));
return 0;
}
int main(int argc, char**argv) {
char *choix;
int sock;
char buffer[BUFFER_SIZE];
sock = cree_socket_tcp_client();
if (sock < 0) {
puts("Erreur connection socket client");
exit(1);
}
printf("\nBienvenue dans l'application d'achat de billets!\n");
// tant que l'on ne quitte pas l'app, on fait la boucle
do {
printf("Que voulez-vous faire ?\n (r) Réserver un billet\n (a) Annuler une réservation\n (q) Quitter\n");
scanf("%s", choix);
// si on réserve
if (strcmp(choix, "r")==0){
int place;
write(sock, "r", BUFFER_SIZE);
printf("Vous avez choisi de réserver une place, voici la liste des places disponibles : \n");
// on affiche le message du serveur
read(sock, buffer, BUFFER_SIZE);
printf("%s\n", buffer);
buffer[0]='\0';
printf("Quelle place souhaitez-vous réserver? \n");
do {
scanf("%d", &place);
} while(place < 0 || place > 99);
// on envoie la place choisie
sprintf(choix,"%d",place); //pour passer de int à char
strcat(buffer,choix);
write(sock, buffer, BUFFER_SIZE);
// on lit si la place est dispo
read(sock, buffer, BUFFER_SIZE);
if (strcmp(buffer,"1")==0) {
// si la place est libre
buffer[0]='\0';
printf("Entrez votre nom: ");
scanf("%s", choix);
strcat(buffer,choix);
write(sock, buffer, BUFFER_SIZE);
buffer[0]='\0';
printf("Entrez votre prenom: ");
scanf("%s", choix);
strcat(buffer,choix);
write(sock, buffer, BUFFER_SIZE);
buffer[0]='\0';
read(sock, buffer, BUFFER_SIZE);
printf("Place attribuée avec succès!\nVotre n° de dossier est le %s.\n", buffer);
buffer[0]='\0';
}
else printf("place déjà attribuée, veuillez ré-essayer\n" );
buffer[0]='\0';
}
else if (strcmp(choix, "a")==0){
printf("Vous avez choisi d'annuler une réservation.\n");
write(sock, "a", BUFFER_SIZE);
printf("Entrez votre nom: ");
scanf("%s", choix);
strcat(buffer,choix);
write(sock, buffer, BUFFER_SIZE);
buffer[0]='\0';
printf("Entrez votre n° de dossier: ");
scanf("%s", choix);
strcat(buffer,choix);
write(sock, buffer, BUFFER_SIZE);
buffer[0]='\0';
read(sock, buffer, BUFFER_SIZE);
printf("%s\n", buffer);
buffer[0]='\0';
}
else if (strcmp(choix, "q")==0){
printf("Vous quittez l'application\n");
write(sock,"q",BUFFER_SIZE);
}
} while(strcmp(choix, "q")!=0);
return 0;
}
|
the_stack_data/176705635.c | #include <stdio.h>
int main()
{
int fact=1,m,i,n,j,temp,sum=0,sum1=0;
for(i=3;i<1000000;++i)
{
temp=i;
n=i;
sum=0;
while(temp>0)
{
m=temp%10;
fact=1;
for(j=1;j<=m;++j){
fact*=j;
}
sum+=fact;
temp=temp/10;
}
if(sum==n){
sum1+=n;
}
}
printf("%d",sum1);
return 0;
}
|
the_stack_data/113976.c |
/* text version of maze 'mazefiles/binary/Japan2013ef.maz'
generated by mazetool (c) Peter Harrison 2018
o---o---o---o---o---o---o---o---o---o---o---o---o---o---o---o---o
| | | |
o o---o o---o---o---o---o---o---o---o---o---o o o o o
| | | | | | |
o o---o---o o o---o---o---o---o---o---o o---o o o o
| | | | | | | |
o o---o o---o o o---o o---o o---o---o o---o---o o
| | | | | | | | |
o o---o o---o---o o---o o---o o o o o---o o o
| | | | | | | | | |
o o---o o---o o---o---o o---o---o---o o o---o o o
| | | | | | | | | |
o o o---o o---o o---o o---o o o o---o o o o
| | | | | | | | | |
o o o---o---o o o---o o---o---o o---o o o o o
| | | | | | | | | | | |
o o---o---o o o---o o o o o---o o o o o o
| | | | | | | | | | |
o o o---o---o o o---o---o---o---o o---o o o o o
| | | | | | | | | |
o o---o---o o---o---o o o o o---o o---o o o o
| | | | | | | | | | |
o o o---o---o o o---o---o---o---o o o---o o o o
| | | | | | | | |
o o o---o---o---o o o o---o o---o o o---o o o
| | | | | | | | | | |
o o o o o o---o---o---o---o o o---o o o o o
| | | | | | | | | |
o o o---o---o o o---o o o---o---o o o o---o o
| | | | | | | | | |
o o o o o---o---o---o---o---o---o---o---o---o o---o o
| | |
o---o---o---o---o---o---o---o---o---o---o---o---o---o---o---o---o
*/
int Japan2013ef_maz[] ={
0x0E, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x08, 0x08, 0x09,
0x0C, 0x0A, 0x0A, 0x08, 0x08, 0x09, 0x0C, 0x09, 0x0C, 0x08, 0x09, 0x0D, 0x0D, 0x07, 0x05, 0x07,
0x04, 0x0B, 0x0C, 0x03, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00, 0x00, 0x09, 0x06, 0x09,
0x04, 0x0B, 0x06, 0x09, 0x05, 0x06, 0x03, 0x06, 0x03, 0x04, 0x03, 0x07, 0x05, 0x06, 0x09, 0x05,
0x05, 0x0E, 0x08, 0x03, 0x06, 0x09, 0x0C, 0x0A, 0x0A, 0x03, 0x0C, 0x09, 0x06, 0x0A, 0x01, 0x05,
0x05, 0x0C, 0x01, 0x0C, 0x0A, 0x03, 0x04, 0x09, 0x0C, 0x0A, 0x03, 0x06, 0x0A, 0x09, 0x05, 0x05,
0x05, 0x05, 0x07, 0x06, 0x09, 0x0C, 0x03, 0x06, 0x03, 0x0D, 0x0D, 0x0D, 0x0D, 0x05, 0x05, 0x05,
0x05, 0x06, 0x09, 0x0C, 0x01, 0x06, 0x09, 0x0C, 0x08, 0x00, 0x00, 0x00, 0x00, 0x01, 0x05, 0x05,
0x05, 0x0C, 0x03, 0x05, 0x05, 0x0C, 0x03, 0x06, 0x03, 0x05, 0x07, 0x07, 0x07, 0x05, 0x05, 0x05,
0x05, 0x05, 0x0C, 0x02, 0x03, 0x06, 0x09, 0x0C, 0x09, 0x06, 0x09, 0x0C, 0x0A, 0x03, 0x05, 0x05,
0x05, 0x05, 0x04, 0x09, 0x0C, 0x0B, 0x06, 0x03, 0x06, 0x0A, 0x03, 0x06, 0x09, 0x0D, 0x05, 0x05,
0x05, 0x04, 0x03, 0x06, 0x02, 0x0A, 0x09, 0x0C, 0x0B, 0x0C, 0x0A, 0x0A, 0x03, 0x04, 0x03, 0x05,
0x05, 0x06, 0x0A, 0x0A, 0x09, 0x0D, 0x06, 0x02, 0x0A, 0x03, 0x0C, 0x0A, 0x08, 0x03, 0x0E, 0x01,
0x04, 0x0A, 0x08, 0x0B, 0x06, 0x02, 0x0A, 0x0A, 0x0A, 0x0A, 0x03, 0x0D, 0x05, 0x0C, 0x0A, 0x03,
0x05, 0x0D, 0x06, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x02, 0x03, 0x06, 0x0A, 0x09,
0x06, 0x02, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x03,
};
/* end of mazefile */
|
the_stack_data/218893719.c | /* This file auto-generated from COPYING by genstring.py - don't edit it */
static const char* license_msg[] = {
"Yasm is Copyright (c) 2001-2014 Peter Johnson and other Yasm developers.",
"",
"Yasm developers and/or contributors include:",
"Peter Johnson",
"Michael Urman",
"Brian Gladman (Visual Studio build files, other fixes)",
"Stanislav Karchebny (options parser)",
"Mathieu Monnier (SSE4 instruction patches, NASM preprocessor additions)",
"Anonymous \"NASM64\" developer (NASM preprocessor fixes)",
"Stephen Polkowski (x86 instruction patches)",
"Henryk Richter (Mach-O object format)",
"Ben Skeggs (patches, bug reports)",
"Alexei Svitkine (GAS preprocessor)",
"Samuel Thibault (TASM parser and frontend)",
"",
"-----------------------------------",
"Yasm licensing overview and summary",
"-----------------------------------",
"",
"Note: This document does not provide legal advice nor is it the actual",
"license of any part of Yasm. See the individual licenses for complete",
"details. Consult a lawyer for legal advice.",
"",
"The primary license of Yasm is the 2-clause BSD license. Please use this",
"license if you plan on submitting code to the project.",
"",
"Yasm has absolutely no warranty; not even for merchantibility or fitness",
"for a particular purpose.",
"",
"-------",
"Libyasm",
"-------",
"Libyasm is 2-clause or 3-clause BSD licensed, with the exception of",
"bitvect, which is triple-licensed under the Artistic license, GPL, and",
"LGPL. Libyasm is thus GPL and LGPL compatible. In addition, this also",
"means that libyasm is free for binary-only distribution as long as the",
"terms of the 3-clause BSD license and Artistic license (as it applies to",
"bitvect) are fulfilled.",
"",
"-------",
"Modules",
"-------",
"The modules are 2-clause or 3-clause BSD licensed.",
"",
"---------",
"Frontends",
"---------",
"The frontends are 2-clause BSD licensed.",
"",
"-------------",
"License Texts",
"-------------",
"The full text of all licenses are provided in separate files in the source",
"distribution. Each source file may include the entire license (in the case",
"of the BSD and Artistic licenses), or may reference the GPL or LGPL license",
"file.",
"",
"BSD.txt - 2-clause and 3-clause BSD licenses",
"Artistic.txt - Artistic license",
"GNU_GPL-2.0 - GNU General Public License",
"GNU_LGPL-2.0 - GNU Library General Public License",
};
|
the_stack_data/225142208.c | /******************************************************************************
Copyright (c) 1996 - 2004 -- University of Washington
******************************************************************************/
/* MDD */
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include "zlib.h"
int _PRCNT_NUM; /* number of basic bloc counters */
int *_PRCNT_ZPROF;
int _PCCNT_NUM; /* number of call-edge counters */
int *_PCCNT_ZPROF;
int _SRCSAMPL_NUM; /* number of distinct locations in the source code */
/* variable hard-wired in the compiler-generated code */
int _SRC_LOC; /* global variable marking source code locations */
/* it is set at run-time byt the compiled code */
int *_SRCSAMPL_ZPROF; /* statistical data on execution-time spending */
static int _ZPROF_ALARM_TIMING;
/*
* zprof_ds_out: library routine to produce raw profile data
*/
void zprof_ds_out(void) {
int i;
int tot_time = 0;
FILE *outfp;
outfp = fopen(".profiles","w");
fprintf(outfp, "__profiles_\n bbcnt %d\n", _PRCNT_NUM);
for (i=0; i<_PRCNT_NUM; i++)
fprintf(outfp, "%d %d\n", i, _PRCNT_ZPROF[i]);
fprintf(outfp, "call_edge_cnt %d\n", _PCCNT_NUM);
for (i=0; i<_PCCNT_NUM; i++)
fprintf(outfp, "%d %d\n", i, _PCCNT_ZPROF[i]);
for (i=0; i<_SRCSAMPL_NUM; i++)
tot_time += _SRCSAMPL_ZPROF[i];
fprintf(outfp, "timings %d %d\n", _SRCSAMPL_NUM, tot_time);
for (i=0; i<_SRCSAMPL_NUM; i++)
fprintf(outfp, "%d %d\n", i, _SRCSAMPL_ZPROF[i]);
fclose(outfp);
}
static void zprof_alarm_handler(int s) {
_SRCSAMPL_ZPROF[_SRC_LOC] += 1;
ualarm(_ZPROF_ALARM_TIMING, 0);
}
void zprof_alarm_set(void) {
int i;
_SRCSAMPL_ZPROF = (int *) _zmalloc(_SRCSAMPL_NUM*sizeof(int),
"zprof samples");
for (i=0; i<_SRCSAMPL_NUM; i++)
_SRCSAMPL_ZPROF[i] = 0;
_ZPROF_ALARM_TIMING = 10;
signal(SIGALRM, zprof_alarm_handler);
ualarm(_ZPROF_ALARM_TIMING, 0);
}
|
the_stack_data/22945.c | /*
* Benchmarks contributed by Divyesh Unadkat[1,2], Supratik Chakraborty[1], Ashutosh Gupta[1]
* [1] Indian Institute of Technology Bombay, Mumbai
* [2] TCS Innovation labs, Pune
*
*/
extern void __VERIFIER_error() __attribute__ ((__noreturn__));
extern void __VERIFIER_assume(int);
void __VERIFIER_assert(int cond) { if(!(cond)) { ERROR: __VERIFIER_error(); } }
extern int __VERIFIER_nondet_int(void);
int N;
int main()
{
N = __VERIFIER_nondet_int();
if(N <= 0) return 1;
int i;
int sum[1];
int a[N];
for(i=0; i<N; i++)
{
a[i] = i%2;
}
for(i=0; i<N; i++)
{
if(i==0) {
sum[0] = 0;
} else {
sum[0] = sum[0] + a[i];
}
}
__VERIFIER_assert(sum[0] > N);
return 1;
}
|
the_stack_data/11074282.c | int a;
int main() {
a = 5;
return a + 1 + 2 + 3;
}
|
the_stack_data/37637994.c | #include <stdio.h> // For printf function
#include <stdlib.h> // For heap memory functions
#include <string.h> // For strcmp function
void fill(int* matrix, int rows, int columns) {
int counter = 1;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
*(matrix + i * columns + j) = counter;
}
counter++;
}
}
void print_matrix(int* matrix, int rows, int columns) {
int counter = 1;
printf("Matrix:\n");
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
printf("%d ", *(matrix + i * columns + j));
}
printf("\n");
}
}
void print_flat(int* matrix, int rows, int columns) {
printf("Flat matrix: ");
for (int i = 0; i < (rows * columns); i++) {
printf("%d ", *(matrix + i));
}
printf("\n");
}
int friendly_sum(int* matrix, int rows, int columns) {
int sum = 0;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
sum += *(matrix + i * columns + j);
}
}
return sum;
}
int not_friendly_sum(int* matrix, int rows, int columns) {
int sum = 0;
for (int j = 0; j < columns; j++) {
for (int i = 0; i < rows; i++) {
sum += *(matrix + i * columns + j);
}
}
return sum;
}
int main(int argc, char** argv) {
if (argc < 4) {
printf("Usage: %s [print|friendly-sum|not-friendly-sum] ");
printf("[number-of-rows] [number-of-columns]\n", argv[0]);
exit(1);
}
char* operation = argv[1];
int rows = atol(argv[2]);
int columns = atol(argv[3]);
int* matrix = (int*)malloc(rows * columns * sizeof(int));
if (matrix == NULL) {
printf("matrix = NULL \n");
exit(1);
}
fill(matrix, rows, columns);
if (strcmp(operation, "print") == 0) {
print_matrix(matrix, rows, columns);
print_flat(matrix, rows, columns);
}
else if (strcmp(operation, "friendly-sum") == 0) {
int sum = friendly_sum(matrix, rows, columns);
printf("Friendly sum: %d\n", sum);
}
else if (strcmp(operation, "not-friendly-sum") == 0) {
int sum = not_friendly_sum(matrix, rows, columns);
printf("Not friendly sum: %d\n", sum);
}
else {
printf("FATAL: Not supported operation!\n");
exit(1);
}
free(matrix);
return 0;
}
|
the_stack_data/225143180.c | // 5. Practical : Linked List – 1
// Write a menu driven program to implement following operations on the singly linked list. Design a function create to create a link list (which is required to be called only for one time for a link list)
// (a) create [ node * create() ]
// (b) display [ void display(node *start) ]
// (c) length [ int length (node *start) ]
// (d) maximum [int maximum (node *start)]
// (e) merge (to merge two link list in to the third one) [node * merge(node *start1, node *start2)
// (f) sort [void sort(node *start) ]
// (g) reverse [ node * reverse (node *start)]
// (h) Insert a node at the front of the linked list. [ node * insert_front(node *start, int no) ]
// (i) Insert a node at the end of the linked list. [ node * insert_end(node *start, int no) ]
// (j) Insert a node such that linked list is in ascending order.(according to info. Field) [ node * insert_sort(node *start, int no) ]
// (k) Delete a first node of the linked list. [ node * delete_first(node *start) ]
// (l) Delete a node before specified position. [ node * delete_before(node *start, int pos) ]
// (m) Delete a node after specified position. [ node * delete_after(node *, int pos) ]
// (n) No search [ int search (node*, int x) ]
#include <stdio.h>
#include <stdlib.h>
struct node{
int info;
struct node *link;
};
struct node *create();
void display(struct node *start);
int length (struct node *start);
int maximum (struct node *start);
struct node * merge(struct node *start1, struct node *start2);
void sort(struct node *start);
struct node * reverse (struct node *start);
struct node * insert_front(struct node *start, int no);
struct node * insert_end(struct node *start, int no);
struct node * insert_sort(struct node *start, int no);
struct node * delete_first(struct node *start);
struct node * delete_before(struct node *start, int pos);
struct node * delete_after(struct node *start, int pos);
int search (struct node *start, int x);
int isNull(struct node *start);
int isEmpty();
void push(int *stack, int *top, int value);
int pop(int *stack, int *top);
int main(){
int operation, value, ans;
struct node *head = NULL, *head1;
printf("\n Ahmed Aghadi 200420107043\n");
do{
printf("\n****************************\n");
printf("\nEnter operation value\n");
printf("\n1. Create");
printf("\n2. Display");
printf("\n3. Length");
printf("\n4. Maximum");
printf("\n5. Merge");
printf("\n6. Sort");
printf("\n7. Reverse");
printf("\n8. Insert at front");
printf("\n9. insert at end");
printf("\n10. Insert by sort");
printf("\n11. Delete first");
printf("\n12. Delete before");
printf("\n13. Delete after");
printf("\n14. Search");
printf("\n15. Exit");
printf("\n****************************\n");
printf("Operation = ");
scanf("%d",&operation);
printf("\n");
if(operation>1&&operation<15){
if(isNull(head)){
continue;
}
}
switch(operation){
case 1:
head = create();
break;
case 2:
display(head);
break;
case 3:
ans = length(head);
printf("Length = %d", ans);
break;
case 4:
ans = maximum(head);
printf("Maximum = %d", ans);
break;
case 5:
printf("\nFor Second Linked List : \n");
head1 = create();
head = merge(head, head1);
display(head);
break;
case 6:
sort(head);
break;
case 7:
head = reverse(head);
display(head);
break;
case 8:
printf("Enter value to be inserted : ");
scanf("%d",&value);
head = insert_front(head, value);
break;
case 9:
printf("Enter value to be inserted : ");
scanf("%d",&value);
head = insert_end(head, value);
break;
case 10:
printf("Enter value to be inserted : ");
scanf("%d",&value);
head = insert_sort(head, value);
break;
case 11:
head = delete_first(head);
break;
case 12:
printf("Enter position : ");
scanf("%d",&value);
head = delete_before(head,value);
break;
case 13:
printf("Enter position : ");
scanf("%d",&value);
head = delete_after(head,value);
case 14:
printf("Enter value to be searched : ");
scanf("%d",&value);
ans = search(head, value);
if(ans==-1){
printf("Value not found");
break;
}
printf("Value is found at position %d",ans);
break;
case 15:
break;
default:
printf("\nEnter operation value between 1 and 15\n");
}
}while(operation!=15);
}
struct node *create(){
int value;
struct node *first;
first = (struct node *)malloc(sizeof(struct node));
if(first == NULL){
printf("Memory not allocated");
}
printf("Enter value of first node : ");
scanf("%d",&value);
first->info = value;
first->link = NULL;
return first;
}
void display(struct node *start){
while(start != NULL){
printf("\n%d",start->info);
start = start->link;
}
}
int length (struct node *start){
int len = 0;
while(start!=NULL){
len++;
start=start->link;
}
return len;
}
int maximum (struct node *start){
int max = start->info;
start = start->link;
while(start!=NULL){
if(start->info>max){
max = start->info;
}
start = start->link;
}
return max;
}
struct node * merge(struct node *start1, struct node *start2){
struct node *first;
first = (struct node *)malloc(sizeof(struct node));
if(length(start1)==0){
return start2;
}
if(length(start2)==0){
return start1;
}
first = start1;
while(start1->link!=NULL){
start1 = start1->link;
}
start1->link = start2;
return first;
}
void sort(struct node *start){
int i,j,temp,len;
struct node *current, *toCheck;
len = length(start);
current = start;
for(i = 0; i< len-1; i++){
toCheck = current->link;
for(j = i+1; j < len; j++){
if(toCheck->info<current->info){
temp = toCheck->info;
toCheck->info = current->info;
current->info = temp;
}
toCheck = toCheck->link;
}
current = current->link;
}
}
struct node * reverse (struct node *start){
int *stack = (int*)calloc(length(start),sizeof(int)), top = 1, i = 0, j = 0;
struct node *head = (struct node *)malloc(sizeof(struct node)), *temp;
if(length(start)==1){
head = start;
return head;
}
while(start!=NULL){
push(stack,&top,start->info);
start = start->link;
}
// head->info = pop(stack,&top);
temp = head;
while(1){
temp->info=pop(stack,&top);
if(top>1){
temp->link = (struct node *)malloc(sizeof(struct node));
temp = temp->link;
}
else{
temp->link = NULL;
break;
}
}
return head;
}
struct node * insert_front(struct node *start, int no){
struct node *first;
first = (struct node *)malloc(sizeof(struct node));
if(first == NULL){
printf("Memory not allocated");
}
first->info = no;
first->link=start;
return first;
}
struct node * insert_end(struct node *start, int no){
struct node *temp = start, *end;
end = (struct node *)malloc(sizeof(struct node));
end->info = no;
end->link = NULL;
while(temp->link!=NULL){
temp = temp->link;
}
temp->link = end;
return start;
}
struct node * insert_sort(struct node *start, int no){
struct node *toAdd, *temp = start;
toAdd = (struct node *)malloc(sizeof(struct node));
toAdd->info = no;
if(start->info>no){
toAdd->link = start;
return toAdd;
}
while(temp->link!=NULL){
if(temp->link->info>no){
toAdd->link = temp->link;
temp->link= toAdd;
return start;
}
temp = temp->link;
}
temp->link = toAdd;
toAdd->link = NULL;
return start;
}
struct node * delete_first(struct node *start){
struct node *head = start->link;
if(length(start)==1){
printf("\nLength of Linked List is 1 and thus first element can't be deleted.\n");
return start;
}
free(start);
return head;
}
struct node * delete_before(struct node *start, int pos){
struct node *temp = start, *toDelete = temp->link;
if(pos<2||pos>length(start)+1||length(start)==1){
printf("Invalid Position");
return start;
}
while(pos-->3){
temp = temp->link;
}
toDelete = temp->link;
temp->link = toDelete->link;
free(toDelete);
return start;
}
struct node * delete_after(struct node *start, int pos){
struct node *temp = start, *toDelete = temp->link;
if(pos<1||pos>length(start)-1||length(start)==1){
printf("Invalid Position");
return start;
}
while(pos-->1){
temp = temp->link;
}
toDelete = temp->link;
temp->link = toDelete->link;
free(toDelete);
return start;
}
int search (struct node *start, int x){
int i = 1;
while(start!=NULL){
if(start->info==x){
return i;
}
start = start->link;
i++;
}
return -1;
}
int isNull(struct node *start){
if(start == NULL){
printf("\nLinked List not created.\n");
return 1;
}
return 0;
}
int isEmpty(int top){
if(top==-1){
return 1;
}else{
return 0;
}
}
void push(int *stack, int *top, int value){
(*top)++;
stack[*top] = value;
}
int pop(int *stack, int *top){
if(isEmpty(*top)){
printf("Stack is Empty!");
exit(0);
}
(*top)--;
return stack[(*top)+1];
} |
the_stack_data/15762465.c | /**
* @author SANKALP SAXENA
*/
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main()
{
int a, b;
float c, d;
scanf("%d%d%f%f", &a, &b, &c, &d);
printf("%d %d\n", (a + b), (a - b));
printf("%.1f %.1f", (c + d), (c - d));
return 0;
}
|
the_stack_data/782040.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
unsigned char matrix[1024*1024];
unsigned char tmpInv[1024*1024];
unsigned char tmp[1024*1024];
int quickPow[] = {1,2,4,8,16,32,64,128,256,512,1024};
void rec(int n, int target, int r)
{
if (n > target) return;
if (n == 0)
{
matrix[0] = '0';
rec(n+1, target, r);
} else {
int halfSquare = quickPow[n-1]; // OPTIMIZE
int halfSquare2 = halfSquare*halfSquare;
int halfMatrix = halfSquare2*2;
int i;
memcpy(tmp, matrix, halfSquare2);
for (i = 0; i < halfSquare2; i++)
//tmpInv[i] = (tmp[i] == '0') ? '1' : '0';
//tmpInv[i] = '1'-tmp[i]+'0';
tmpInv[i] = 97-tmp[i];
for (i = 0; i < halfSquare; i++)
{
memcpy(matrix+((i*2)*halfSquare), tmp+halfSquare*i, halfSquare);
memcpy(matrix+((i*2+1)*halfSquare), tmp+halfSquare*i, halfSquare);
}
memcpy(matrix+halfMatrix, matrix, halfMatrix);
for (i = 0; i < halfSquare; i++)
{
if (r == 0)
memcpy(matrix+halfMatrix+((i*2+1)*halfSquare),tmpInv+halfSquare*i , halfSquare);
else if (r == 1)
memcpy(matrix+((i*2+1)*halfSquare), tmpInv+halfSquare*i, halfSquare);
else if (r == 2)
memcpy(matrix+((i*2)*halfSquare), tmpInv+halfSquare*i, halfSquare);
else if (r == 3)
memcpy(matrix+halfMatrix+(i*2*halfSquare), tmpInv+halfSquare*i, halfSquare);
}
rec(n+1, target, r);
}
}
int main()
{
int n, r;
int i, squared;
while (scanf("%d %d", &n, &r) != EOF)
{
squared = quickPow[n];
//halfSquare = quickPow[n-1];
rec(0,n,r%4);
for (i = 0; i < squared; i++)
{
//char tmp[1026*1024];
//strncpy(tmp, matrix+(int)(i*pow(2,n)), pow(2,n));
memcpy(tmp, matrix+(i*squared), squared);
tmp[squared] = '\0';
//matrix[i*squared+1] = '\n';
printf("%s\n", tmp);
//fputs(tmp, stdout);
//fwrite(tmp, 1, squared+1, stdout);
}
}
// fwrite(matrix, 1, 40, stdout);
}
|
the_stack_data/179829504.c | /*
* Date: 06/07/2015
* Created by: Ton Chanh Le ([email protected])
*/
typedef enum {false, true} bool;
extern int __VERIFIER_nondet_int(void);
int main()
{
int x;
int y;
x = __VERIFIER_nondet_int();
y = __VERIFIER_nondet_int();
if (x + y > 1) {
while (x > 0) {
x = x + x + y;
y = y - 1;
}
}
return 0;
}
|
the_stack_data/104828786.c | //
// main.c
// Algorithm
//
// Created by 石玉龙 on 2020/12/30.
//
#include <stdio.h>
int main(int argc, const char * argv[]) {
// insert code here...
printf("Hello, World!\n");
return 0;
}
|
the_stack_data/243893008.c | int d[2] = {3, 72};
void MAIN()
{
d[1] -= 70;
print("d 3 2");
printid(d);
}
|
the_stack_data/154828126.c | /*
* Copyright (c) 2017, 2018, Oracle and/or its affiliates.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to
* endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
int a = 2;
int main() {
return a++;
}
|
the_stack_data/62638247.c | // RUN: %clang -target x86_64-apple-macosx10.15 -darwin-target-variant x86_64-apple-ios13.1-macabi -isysroot %S/Inputs/MacOSX10.15.versioned.sdk -c -### %s 2>&1 \
// RUN: | FileCheck %s
// RUN: env SDKROOT=%S/Inputs/MacOSX10.15.versioned.sdk %clang -target x86_64-apple-macosx10.15 -darwin-target-variant x86_64-apple-ios13.1-macabi -c -### %s 2>&1 \
// RUN: | FileCheck %s
// RUN: %clang -target x86_64-apple-ios13.1-macabi -darwin-target-variant x86_64-apple-macosx10.15 -isysroot %S/Inputs/MacOSX10.15.versioned.sdk -c -### %s 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-SWAPPED %s
// RUN: %clang -target x86_64-apple-ios13.1-macabi -isysroot %S/Inputs/MacOSX10.15.versioned.sdk -c -### %s 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-MACCATALYST %s
// CHECK: "-target-sdk-version=10.15" "-darwin-target-variant-sdk-version=13.1"
// CHECK-SWAPPED: "-target-sdk-version=13.1" "-darwin-target-variant-sdk-version=10.15"
// CHECK-MACCATALYST: "-target-sdk-version=13.1"
|
the_stack_data/1020329.c | // WARNING in __brelse
// https://syzkaller.appspot.com/bug?id=61351db7239051679c20d85a6ef78cddadc6ac4f
// status:open
// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <endian.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
uint64_t r[1] = {0xffffffffffffffff};
int main(void)
{
syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0);
long res = 0;
memcpy((void*)0x20000040, "./file0\000", 8);
res = syscall(__NR_creat, 0x20000040, 0);
if (res != -1)
r[0] = res;
*(uint64_t*)0x20000080 = 0x5e4a;
syscall(__NR_ioctl, r[0], 0x40086602, 0x20000080);
memcpy((void*)0x20000240, "threaded\000", 9);
syscall(__NR_write, r[0], 0x20000240, 0xf96d);
syscall(__NR_fallocate, r[0], 3, 0xe0ff, 0xfff9);
return 0;
}
|
the_stack_data/243892380.c | #include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
void error(int line, char* msg) {
char buff[128] = { 0 };
sprintf(buff, "error en linea %d: %s", line, msg);
perror(buff);
exit(EXIT_FAILURE);
}
void * my_malloc(int size, int line) {
void * ret = malloc(size);
if (ret == NULL ) error(line, "malloc");
return ret;
}
int my_write(int fd, void* c, int size, int line) {
int ret = write(fd, c, size);
if (ret < 0) error(line, "write");
return ret;
}
int main (int argc, char **argv)
{
void * heap_begin;
void * heap_end_malloc;
void * heap_end_free;
int *puntero_con_resultado_de_malloc;
heap_begin=sbrk(0);
puntero_con_resultado_de_malloc = (int *) my_malloc (atoi(argv[1]), __LINE__);
heap_end_malloc=sbrk(0);
free(puntero_con_resultado_de_malloc);
heap_end_free=sbrk(0);
char buffer[128]={ 0 };
sprintf (buffer, "begin=%p\nend_malloc=%p\nend_free=%p\nheap size_malloc:%ld\nheap size_free:%ld\n", heap_begin, heap_end_malloc, heap_end_free, heap_end_malloc-heap_begin, heap_end_free-heap_begin);
my_write (STDOUT_FILENO, buffer, strlen(buffer), __LINE__);
getchar();
return (EXIT_SUCCESS);
}
|
the_stack_data/10838.c | #include <stdio.h>
int main(void) {
char *happy[2];
happy[0] = "/bin/sh";
happy[1] = NULL;
return execve(happy[0], happy, NULL);
} |
the_stack_data/168892236.c | #include <stdio.h>
double min(double x, double y);
void chline(char ch, int i, int j);
int main(void)
{
double x, y;
int i, j;
char ch;
printf("Please enter two number: ");
scanf("%lf %lf", &x, &y);
double number = min(x, y);
printf("The mininum between %lf and %lf is %lf \n", x, y, number);
printf("Please enter a character to print: ");
while (getchar() != '\n')
continue;
ch = getchar();
printf("How many lines would like to print %c: ", ch);
scanf("%d", &j);
printf("How many columns would like to print %c: ", ch);
scanf("%d", &i);
chline(ch, i, j);
return 0;
}
double min(double x, double y)
{
return (x > y) ? x : y;
}
void chline(char ch, int i, int j)
{
int n, m;
for (n = 0; n < j; n++)
{
for (m = 0; m < i; m++)
putchar(ch);
printf("\n");
}
} |
the_stack_data/67336.c | /*
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <openssl/des.h>
/* tisk tisk - the test keys don't all have odd parity :-( */
/* test data */
#define NUM_TESTS 34
static uint8_t key_data[NUM_TESTS][8] = {
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
{ 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
{ 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 },
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
{ 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 },
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
{ 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 },
{ 0x7C, 0xA1, 0x10, 0x45, 0x4A, 0x1A, 0x6E, 0x57 },
{ 0x01, 0x31, 0xD9, 0x61, 0x9D, 0xC1, 0x37, 0x6E },
{ 0x07, 0xA1, 0x13, 0x3E, 0x4A, 0x0B, 0x26, 0x86 },
{ 0x38, 0x49, 0x67, 0x4C, 0x26, 0x02, 0x31, 0x9E },
{ 0x04, 0xB9, 0x15, 0xBA, 0x43, 0xFE, 0xB5, 0xB6 },
{ 0x01, 0x13, 0xB9, 0x70, 0xFD, 0x34, 0xF2, 0xCE },
{ 0x01, 0x70, 0xF1, 0x75, 0x46, 0x8F, 0xB5, 0xE6 },
{ 0x43, 0x29, 0x7F, 0xAD, 0x38, 0xE3, 0x73, 0xFE },
{ 0x07, 0xA7, 0x13, 0x70, 0x45, 0xDA, 0x2A, 0x16 },
{ 0x04, 0x68, 0x91, 0x04, 0xC2, 0xFD, 0x3B, 0x2F },
{ 0x37, 0xD0, 0x6B, 0xB5, 0x16, 0xCB, 0x75, 0x46 },
{ 0x1F, 0x08, 0x26, 0x0D, 0x1A, 0xC2, 0x46, 0x5E },
{ 0x58, 0x40, 0x23, 0x64, 0x1A, 0xBA, 0x61, 0x76 },
{ 0x02, 0x58, 0x16, 0x16, 0x46, 0x29, 0xB0, 0x07 },
{ 0x49, 0x79, 0x3E, 0xBC, 0x79, 0xB3, 0x25, 0x8F },
{ 0x4F, 0xB0, 0x5E, 0x15, 0x15, 0xAB, 0x73, 0xA7 },
{ 0x49, 0xE9, 0x5D, 0x6D, 0x4C, 0xA2, 0x29, 0xBF },
{ 0x01, 0x83, 0x10, 0xDC, 0x40, 0x9B, 0x26, 0xD6 },
{ 0x1C, 0x58, 0x7F, 0x1C, 0x13, 0x92, 0x4F, 0xEF },
{ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
{ 0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E },
{ 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE },
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
{ 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }
};
static uint8_t plain_data[NUM_TESTS][8] = {
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
{ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
{ 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 },
{ 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 },
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
{ 0x01, 0xA1, 0xD6, 0xD0, 0x39, 0x77, 0x67, 0x42 },
{ 0x5C, 0xD5, 0x4C, 0xA8, 0x3D, 0xEF, 0x57, 0xDA },
{ 0x02, 0x48, 0xD4, 0x38, 0x06, 0xF6, 0x71, 0x72 },
{ 0x51, 0x45, 0x4B, 0x58, 0x2D, 0xDF, 0x44, 0x0A },
{ 0x42, 0xFD, 0x44, 0x30, 0x59, 0x57, 0x7F, 0xA2 },
{ 0x05, 0x9B, 0x5E, 0x08, 0x51, 0xCF, 0x14, 0x3A },
{ 0x07, 0x56, 0xD8, 0xE0, 0x77, 0x47, 0x61, 0xD2 },
{ 0x76, 0x25, 0x14, 0xB8, 0x29, 0xBF, 0x48, 0x6A },
{ 0x3B, 0xDD, 0x11, 0x90, 0x49, 0x37, 0x28, 0x02 },
{ 0x26, 0x95, 0x5F, 0x68, 0x35, 0xAF, 0x60, 0x9A },
{ 0x16, 0x4D, 0x5E, 0x40, 0x4F, 0x27, 0x52, 0x32 },
{ 0x6B, 0x05, 0x6E, 0x18, 0x75, 0x9F, 0x5C, 0xCA },
{ 0x00, 0x4B, 0xD6, 0xEF, 0x09, 0x17, 0x60, 0x62 },
{ 0x48, 0x0D, 0x39, 0x00, 0x6E, 0xE7, 0x62, 0xF2 },
{ 0x43, 0x75, 0x40, 0xC8, 0x69, 0x8F, 0x3C, 0xFA },
{ 0x07, 0x2D, 0x43, 0xA0, 0x77, 0x07, 0x52, 0x92 },
{ 0x02, 0xFE, 0x55, 0x77, 0x81, 0x17, 0xF1, 0x2A },
{ 0x1D, 0x9D, 0x5C, 0x50, 0x18, 0xF7, 0x28, 0xC2 },
{ 0x30, 0x55, 0x32, 0x28, 0x6D, 0x6F, 0x29, 0x5A },
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
};
static uint8_t cipher_data[NUM_TESTS][8] = {
{ 0x8C, 0xA6, 0x4D, 0xE9, 0xC1, 0xB1, 0x23, 0xA7 },
{ 0x73, 0x59, 0xB2, 0x16, 0x3E, 0x4E, 0xDC, 0x58 },
{ 0x95, 0x8E, 0x6E, 0x62, 0x7A, 0x05, 0x55, 0x7B },
{ 0xF4, 0x03, 0x79, 0xAB, 0x9E, 0x0E, 0xC5, 0x33 },
{ 0x17, 0x66, 0x8D, 0xFC, 0x72, 0x92, 0x53, 0x2D },
{ 0x8A, 0x5A, 0xE1, 0xF8, 0x1A, 0xB8, 0xF2, 0xDD },
{ 0x8C, 0xA6, 0x4D, 0xE9, 0xC1, 0xB1, 0x23, 0xA7 },
{ 0xED, 0x39, 0xD9, 0x50, 0xFA, 0x74, 0xBC, 0xC4 },
{ 0x69, 0x0F, 0x5B, 0x0D, 0x9A, 0x26, 0x93, 0x9B },
{ 0x7A, 0x38, 0x9D, 0x10, 0x35, 0x4B, 0xD2, 0x71 },
{ 0x86, 0x8E, 0xBB, 0x51, 0xCA, 0xB4, 0x59, 0x9A },
{ 0x71, 0x78, 0x87, 0x6E, 0x01, 0xF1, 0x9B, 0x2A },
{ 0xAF, 0x37, 0xFB, 0x42, 0x1F, 0x8C, 0x40, 0x95 },
{ 0x86, 0xA5, 0x60, 0xF1, 0x0E, 0xC6, 0xD8, 0x5B },
{ 0x0C, 0xD3, 0xDA, 0x02, 0x00, 0x21, 0xDC, 0x09 },
{ 0xEA, 0x67, 0x6B, 0x2C, 0xB7, 0xDB, 0x2B, 0x7A },
{ 0xDF, 0xD6, 0x4A, 0x81, 0x5C, 0xAF, 0x1A, 0x0F },
{ 0x5C, 0x51, 0x3C, 0x9C, 0x48, 0x86, 0xC0, 0x88 },
{ 0x0A, 0x2A, 0xEE, 0xAE, 0x3F, 0xF4, 0xAB, 0x77 },
{ 0xEF, 0x1B, 0xF0, 0x3E, 0x5D, 0xFA, 0x57, 0x5A },
{ 0x88, 0xBF, 0x0D, 0xB6, 0xD7, 0x0D, 0xEE, 0x56 },
{ 0xA1, 0xF9, 0x91, 0x55, 0x41, 0x02, 0x0B, 0x56 },
{ 0x6F, 0xBF, 0x1C, 0xAF, 0xCF, 0xFD, 0x05, 0x56 },
{ 0x2F, 0x22, 0xE4, 0x9B, 0xAB, 0x7C, 0xA1, 0xAC },
{ 0x5A, 0x6B, 0x61, 0x2C, 0xC2, 0x6C, 0xCE, 0x4A },
{ 0x5F, 0x4C, 0x03, 0x8E, 0xD1, 0x2B, 0x2E, 0x41 },
{ 0x63, 0xFA, 0xC0, 0xD0, 0x34, 0xD9, 0xF7, 0x93 },
{ 0x61, 0x7B, 0x3A, 0x0C, 0xE8, 0xF0, 0x71, 0x00 },
{ 0xDB, 0x95, 0x86, 0x05, 0xF8, 0xC8, 0xC6, 0x06 },
{ 0xED, 0xBF, 0xD1, 0xC6, 0x6C, 0x29, 0xCC, 0xC7 },
{ 0x35, 0x55, 0x50, 0xB2, 0x15, 0x0E, 0x24, 0x51 },
{ 0xCA, 0xAA, 0xAF, 0x4D, 0xEA, 0xF1, 0xDB, 0xAE },
{ 0xD5, 0xD4, 0x4F, 0xF7, 0x20, 0x68, 0x3D, 0x0D },
{ 0x2A, 0x2B, 0xB0, 0x08, 0xDF, 0x97, 0xC2, 0xF2 }
};
static uint8_t cipher_ecb2[NUM_TESTS - 1][8] = {
{ 0x92, 0x95, 0xB5, 0x9B, 0xB3, 0x84, 0x73, 0x6E },
{ 0x19, 0x9E, 0x9D, 0x6D, 0xF3, 0x9A, 0xA8, 0x16 },
{ 0x2A, 0x4B, 0x4D, 0x24, 0x52, 0x43, 0x84, 0x27 },
{ 0x35, 0x84, 0x3C, 0x01, 0x9D, 0x18, 0xC5, 0xB6 },
{ 0x4A, 0x5B, 0x2F, 0x42, 0xAA, 0x77, 0x19, 0x25 },
{ 0xA0, 0x6B, 0xA9, 0xB8, 0xCA, 0x5B, 0x17, 0x8A },
{ 0xAB, 0x9D, 0xB7, 0xFB, 0xED, 0x95, 0xF2, 0x74 },
{ 0x3D, 0x25, 0x6C, 0x23, 0xA7, 0x25, 0x2F, 0xD6 },
{ 0xB7, 0x6F, 0xAB, 0x4F, 0xBD, 0xBD, 0xB7, 0x67 },
{ 0x8F, 0x68, 0x27, 0xD6, 0x9C, 0xF4, 0x1A, 0x10 },
{ 0x82, 0x57, 0xA1, 0xD6, 0x50, 0x5E, 0x81, 0x85 },
{ 0xA2, 0x0F, 0x0A, 0xCD, 0x80, 0x89, 0x7D, 0xFA },
{ 0xCD, 0x2A, 0x53, 0x3A, 0xDB, 0x0D, 0x7E, 0xF3 },
{ 0xD2, 0xC2, 0xBE, 0x27, 0xE8, 0x1B, 0x68, 0xE3 },
{ 0xE9, 0x24, 0xCF, 0x4F, 0x89, 0x3C, 0x5B, 0x0A },
{ 0xA7, 0x18, 0xC3, 0x9F, 0xFA, 0x9F, 0xD7, 0x69 },
{ 0x77, 0x2C, 0x79, 0xB1, 0xD2, 0x31, 0x7E, 0xB1 },
{ 0x49, 0xAB, 0x92, 0x7F, 0xD0, 0x22, 0x00, 0xB7 },
{ 0xCE, 0x1C, 0x6C, 0x7D, 0x85, 0xE3, 0x4A, 0x6F },
{ 0xBE, 0x91, 0xD6, 0xE1, 0x27, 0xB2, 0xE9, 0x87 },
{ 0x70, 0x28, 0xAE, 0x8F, 0xD1, 0xF5, 0x74, 0x1A },
{ 0xAA, 0x37, 0x80, 0xBB, 0xF3, 0x22, 0x1D, 0xDE },
{ 0xA6, 0xC4, 0xD2, 0x5E, 0x28, 0x93, 0xAC, 0xB3 },
{ 0x22, 0x07, 0x81, 0x5A, 0xE4, 0xB7, 0x1A, 0xAD },
{ 0xDC, 0xCE, 0x05, 0xE7, 0x07, 0xBD, 0xF5, 0x84 },
{ 0x26, 0x1D, 0x39, 0x2C, 0xB3, 0xBA, 0xA5, 0x85 },
{ 0xB4, 0xF7, 0x0F, 0x72, 0xFB, 0x04, 0xF0, 0xDC },
{ 0x95, 0xBA, 0xA9, 0x4E, 0x87, 0x36, 0xF2, 0x89 },
{ 0xD4, 0x07, 0x3A, 0xF1, 0x5A, 0x17, 0x82, 0x0E },
{ 0xEF, 0x6F, 0xAF, 0xA7, 0x66, 0x1A, 0x7E, 0x89 },
{ 0xC1, 0x97, 0xF5, 0x58, 0x74, 0x8A, 0x20, 0xE7 },
{ 0x43, 0x34, 0xCF, 0xDA, 0x22, 0xC4, 0x86, 0xC8 },
{ 0x08, 0xD7, 0xB4, 0xFB, 0x62, 0x9D, 0x08, 0x85 }
};
static uint8_t cbc_key[8] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
static uint8_t cbc2_key[8] = { 0xf1, 0xe0, 0xd3, 0xc2, 0xb5, 0xa4, 0x97, 0x86 };
static uint8_t cbc3_key[8] = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 };
static uint8_t cbc_iv[8] = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 };
/* Changed the following text constant to binary so it will work on ebcdic
* machines :-) */
/* static char cbc_data[40]="7654321 Now is the time for \0001"; */
static uint8_t cbc_data[40] = {
0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x20,
0x4E, 0x6F, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74,
0x68, 0x65, 0x20, 0x74, 0x69, 0x6D, 0x65, 0x20,
0x66, 0x6F, 0x72, 0x20, 0x00, 0x31, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
static uint8_t cbc_ok[32] = {
0xcc, 0xd1, 0x73, 0xff, 0xab, 0x20, 0x39, 0xf4,
0xac, 0xd8, 0xae, 0xfd, 0xdf, 0xd8, 0xa1, 0xeb,
0x46, 0x8e, 0x91, 0x15, 0x78, 0x88, 0xba, 0x68,
0x1d, 0x26, 0x93, 0x97, 0xf7, 0xfe, 0x62, 0xb4
};
static uint8_t cbc3_ok[32] = {
0x3F, 0xE3, 0x01, 0xC9, 0x62, 0xAC, 0x01, 0xD0,
0x22, 0x13, 0x76, 0x3C, 0x1C, 0xBD, 0x4C, 0xDC,
0x79, 0x96, 0x57, 0xC0, 0x64, 0xEC, 0xF5, 0xD4,
0x1C, 0x67, 0x38, 0x12, 0xCF, 0xDE, 0x96, 0x75
};
static uint8_t cfb_key[8] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
static uint8_t cfb_iv[8] = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef };
static uint8_t cfb_buf1[40], cfb_buf2[40], cfb_tmp[8];
static uint8_t plain[24] = {
0x4e, 0x6f, 0x77, 0x20, 0x69, 0x73,
0x20, 0x74, 0x68, 0x65, 0x20, 0x74,
0x69, 0x6d, 0x65, 0x20, 0x66, 0x6f,
0x72, 0x20, 0x61, 0x6c, 0x6c, 0x20
};
static uint8_t cfb_cipher64[24] = {
0xF3, 0x09, 0x62, 0x49, 0xC7, 0xF4, 0x6E, 0x51, 0xA6, 0x9E, 0x83, 0x9B,
0x1A, 0x92, 0xF7, 0x84, 0x03, 0x46, 0x71, 0x33, 0x89, 0x8E, 0xA6, 0x22
};
static char *pt(uint8_t *p);
static int ede_cfb64_test(uint8_t *cfb_cipher);
int main(int argc, char *argv[])
{
int j, err = 0;
unsigned int i;
DES_cblock in, out, outin, iv3;
DES_key_schedule ks, ks2, ks3;
uint8_t cbc_in[40];
uint8_t cbc_out[40];
printf("Doing ecb\n");
for (i = 0; i < NUM_TESTS; i++) {
DES_set_key(&key_data[i], &ks);
memcpy(in, plain_data[i], 8);
memset(out, 0, 8);
memset(outin, 0, 8);
DES_ecb_encrypt(&in, &out, &ks, DES_ENCRYPT);
DES_ecb_encrypt(&out, &outin, &ks, DES_DECRYPT);
if (memcmp(out, cipher_data[i], 8) != 0) {
printf("Encryption error %2d\nk=%s p=%s o=%s act=%s\n",
i + 1, pt(key_data[i]), pt(in), pt(cipher_data[i]),
pt(out));
err = 1;
}
if (memcmp(in, outin, 8) != 0) {
printf("Decryption error %2d\nk=%s p=%s o=%s act=%s\n",
i + 1, pt(key_data[i]), pt(out), pt(in), pt(outin));
err = 1;
}
}
printf("Doing ede ecb\n");
for (i = 0; i < (NUM_TESTS - 2); i++) {
DES_set_key(&key_data[i], &ks);
DES_set_key(&key_data[i + 1], &ks2);
DES_set_key(&key_data[i + 2], &ks3);
memcpy(in, plain_data[i], 8);
memset(out, 0, 8);
memset(outin, 0, 8);
DES_ecb3_encrypt(&in, &out, &ks, &ks2, &ks, DES_ENCRYPT);
DES_ecb3_encrypt(&out, &outin, &ks, &ks2, &ks, DES_DECRYPT);
if (memcmp(out, cipher_ecb2[i], 8) != 0) {
printf("Encryption error %2d\nk=%s p=%s o=%s act=%s\n",
i + 1, pt(key_data[i]), pt(in), pt(cipher_ecb2[i]),
pt(out));
err = 1;
}
if (memcmp(in, outin, 8) != 0) {
printf("Decryption error %2d\nk=%s p=%s o=%s act=%s\n",
i + 1, pt(key_data[i]), pt(out), pt(in), pt(outin));
err = 1;
}
}
printf("Doing cbc\n");
if ((j = DES_set_key(&cbc_key, &ks)) != 0) {
printf("Key error %d\n", j);
err = 1;
}
memset(cbc_out, 0, 40);
memset(cbc_in, 0, 40);
memcpy(iv3, cbc_iv, sizeof(cbc_iv));
DES_ncbc_encrypt(cbc_data, cbc_out, strlen((char *)cbc_data) + 1, &ks,
&iv3, DES_ENCRYPT);
if (memcmp(cbc_out, cbc_ok, 32) != 0) {
printf("cbc_encrypt encrypt error\n");
err = 1;
}
memcpy(iv3, cbc_iv, sizeof(cbc_iv));
DES_ncbc_encrypt(cbc_out, cbc_in, strlen((char *)cbc_data) + 1, &ks,
&iv3, DES_DECRYPT);
if (memcmp(cbc_in, cbc_data, strlen((char *)cbc_data)) != 0) {
printf("cbc_encrypt decrypt error\n");
err = 1;
}
printf("Doing ede cbc\n");
if ((j = DES_set_key(&cbc_key, &ks)) != 0) {
printf("Key error %d\n", j);
err = 1;
}
if ((j = DES_set_key(&cbc2_key, &ks2)) != 0) {
printf("Key error %d\n", j);
err = 1;
}
if ((j = DES_set_key(&cbc3_key, &ks3)) != 0) {
printf("Key error %d\n", j);
err = 1;
}
memset(cbc_out, 0, 40);
memset(cbc_in, 0, 40);
i = strlen((char *)cbc_data) + 1;
/* i=((i+7)/8)*8; */
memcpy(iv3, cbc_iv, sizeof(cbc_iv));
DES_ede3_cbc_encrypt(cbc_data, cbc_out, 16L, &ks, &ks2, &ks3, &iv3,
DES_ENCRYPT);
DES_ede3_cbc_encrypt(&(cbc_data[16]), &(cbc_out[16]), i - 16, &ks, &ks2, &ks3,
&iv3, DES_ENCRYPT);
if (memcmp(cbc_out, cbc3_ok,
(unsigned int)(strlen((char *)cbc_data) + 1 + 7) / 8 * 8) != 0) {
unsigned int n;
printf("des_ede3_cbc_encrypt encrypt error\n");
for (n = 0; n < i; ++n)
printf(" %02x", cbc_out[n]);
printf("\n");
for (n = 0; n < i; ++n)
printf(" %02x", cbc3_ok[n]);
printf("\n");
err = 1;
}
memcpy(iv3, cbc_iv, sizeof(cbc_iv));
DES_ede3_cbc_encrypt(cbc_out, cbc_in, i, &ks, &ks2, &ks3, &iv3, DES_DECRYPT);
if (memcmp(cbc_in, cbc_data, strlen((char *)cbc_data) + 1) != 0) {
unsigned int n;
printf("des_ede3_cbc_encrypt decrypt error\n");
for (n = 0; n < i; ++n)
printf(" %02x", cbc_data[n]);
printf("\n");
for (n = 0; n < i; ++n)
printf(" %02x", cbc_in[n]);
printf("\n");
err = 1;
}
printf("ede_cfb64() ");
err += ede_cfb64_test(cfb_cipher64);
printf("done\n");
printf("input word alignment test");
for (i = 0; i < 4; i++) {
printf(" %d", i);
DES_ncbc_encrypt(&(cbc_out[i]), cbc_in,
strlen((char *)cbc_data) + 1, &ks,
&cbc_iv, DES_ENCRYPT);
}
printf("\noutput word alignment test");
for (i = 0; i < 4; i++) {
printf(" %d", i);
DES_ncbc_encrypt(cbc_out, &(cbc_in[i]),
strlen((char *)cbc_data) + 1, &ks,
&cbc_iv, DES_ENCRYPT);
}
printf("\n");
return (err);
}
static char *pt(uint8_t *p)
{
static char bufs[10][20];
static int bnum = 0;
char *ret;
int i;
static const char *f = "0123456789ABCDEF";
ret = &(bufs[bnum++][0]);
bnum %= 10;
for (i = 0; i < 8; i++) {
ret[i * 2] = f[(p[i] >> 4) & 0xf];
ret[i * 2 + 1] = f[p[i] & 0xf];
}
ret[16] = '\0';
return (ret);
}
static int ede_cfb64_test(uint8_t *cfb_cipher)
{
DES_key_schedule ks;
int err = 0, i, n;
DES_set_key(&cfb_key, &ks);
memcpy(cfb_tmp, cfb_iv, sizeof(cfb_iv));
n = 0;
DES_ede3_cfb64_encrypt(plain, cfb_buf1, 12, &ks, &ks, &ks, &cfb_tmp, &n,
DES_ENCRYPT);
DES_ede3_cfb64_encrypt(&(plain[12]), &(cfb_buf1[12]),
sizeof(plain) - 12, &ks, &ks, &ks,
&cfb_tmp, &n, DES_ENCRYPT);
if (memcmp(cfb_cipher, cfb_buf1, sizeof(plain)) != 0) {
err = 1;
printf("ede_cfb_encrypt encrypt error\n");
for (i = 0; i < 24; i += 8)
printf("%s\n", pt(&(cfb_buf1[i])));
}
memcpy(cfb_tmp, cfb_iv, sizeof(cfb_iv));
n = 0;
DES_ede3_cfb64_encrypt(cfb_buf1, cfb_buf2, (long)17, &ks, &ks, &ks,
&cfb_tmp, &n, DES_DECRYPT);
DES_ede3_cfb64_encrypt(&(cfb_buf1[17]), &(cfb_buf2[17]),
sizeof(plain) - 17, &ks, &ks, &ks,
&cfb_tmp, &n, DES_DECRYPT);
if (memcmp(plain, cfb_buf2, sizeof(plain)) != 0) {
err = 1;
printf("ede_cfb_encrypt decrypt error\n");
for (i = 0; i < 24; i += 8)
printf("%s\n", pt(&(cfb_buf2[i])));
}
return (err);
}
|
the_stack_data/40470.c | #include <math.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <complex.h>
#ifdef complex
#undef complex
#endif
#ifdef I
#undef I
#endif
#if defined(_WIN64)
typedef long long BLASLONG;
typedef unsigned long long BLASULONG;
#else
typedef long BLASLONG;
typedef unsigned long BLASULONG;
#endif
#ifdef LAPACK_ILP64
typedef BLASLONG blasint;
#if defined(_WIN64)
#define blasabs(x) llabs(x)
#else
#define blasabs(x) labs(x)
#endif
#else
typedef int blasint;
#define blasabs(x) abs(x)
#endif
typedef blasint integer;
typedef unsigned int uinteger;
typedef char *address;
typedef short int shortint;
typedef float real;
typedef double doublereal;
typedef struct { real r, i; } complex;
typedef struct { doublereal r, i; } doublecomplex;
#ifdef _MSC_VER
static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
#else
static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
#endif
#define pCf(z) (*_pCf(z))
#define pCd(z) (*_pCd(z))
typedef int logical;
typedef short int shortlogical;
typedef char logical1;
typedef char integer1;
#define TRUE_ (1)
#define FALSE_ (0)
/* Extern is for use with -E */
#ifndef Extern
#define Extern extern
#endif
/* I/O stuff */
typedef int flag;
typedef int ftnlen;
typedef int ftnint;
/*external read, write*/
typedef struct
{ flag cierr;
ftnint ciunit;
flag ciend;
char *cifmt;
ftnint cirec;
} cilist;
/*internal read, write*/
typedef struct
{ flag icierr;
char *iciunit;
flag iciend;
char *icifmt;
ftnint icirlen;
ftnint icirnum;
} icilist;
/*open*/
typedef struct
{ flag oerr;
ftnint ounit;
char *ofnm;
ftnlen ofnmlen;
char *osta;
char *oacc;
char *ofm;
ftnint orl;
char *oblnk;
} olist;
/*close*/
typedef struct
{ flag cerr;
ftnint cunit;
char *csta;
} cllist;
/*rewind, backspace, endfile*/
typedef struct
{ flag aerr;
ftnint aunit;
} alist;
/* inquire */
typedef struct
{ flag inerr;
ftnint inunit;
char *infile;
ftnlen infilen;
ftnint *inex; /*parameters in standard's order*/
ftnint *inopen;
ftnint *innum;
ftnint *innamed;
char *inname;
ftnlen innamlen;
char *inacc;
ftnlen inacclen;
char *inseq;
ftnlen inseqlen;
char *indir;
ftnlen indirlen;
char *infmt;
ftnlen infmtlen;
char *inform;
ftnint informlen;
char *inunf;
ftnlen inunflen;
ftnint *inrecl;
ftnint *innrec;
char *inblank;
ftnlen inblanklen;
} inlist;
#define VOID void
union Multitype { /* for multiple entry points */
integer1 g;
shortint h;
integer i;
/* longint j; */
real r;
doublereal d;
complex c;
doublecomplex z;
};
typedef union Multitype Multitype;
struct Vardesc { /* for Namelist */
char *name;
char *addr;
ftnlen *dims;
int type;
};
typedef struct Vardesc Vardesc;
struct Namelist {
char *name;
Vardesc **vars;
int nvars;
};
typedef struct Namelist Namelist;
#define abs(x) ((x) >= 0 ? (x) : -(x))
#define dabs(x) (fabs(x))
#define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
#define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
#define dmin(a,b) (f2cmin(a,b))
#define dmax(a,b) (f2cmax(a,b))
#define bit_test(a,b) ((a) >> (b) & 1)
#define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
#define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
#define abort_() { sig_die("Fortran abort routine called", 1); }
#define c_abs(z) (cabsf(Cf(z)))
#define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
#ifdef _MSC_VER
#define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
#define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
#else
#define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
#define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
#endif
#define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
#define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
#define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
//#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
#define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
#define d_abs(x) (fabs(*(x)))
#define d_acos(x) (acos(*(x)))
#define d_asin(x) (asin(*(x)))
#define d_atan(x) (atan(*(x)))
#define d_atn2(x, y) (atan2(*(x),*(y)))
#define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
#define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
#define d_cos(x) (cos(*(x)))
#define d_cosh(x) (cosh(*(x)))
#define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
#define d_exp(x) (exp(*(x)))
#define d_imag(z) (cimag(Cd(z)))
#define r_imag(z) (cimagf(Cf(z)))
#define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
#define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
#define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
#define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
#define d_log(x) (log(*(x)))
#define d_mod(x, y) (fmod(*(x), *(y)))
#define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
#define d_nint(x) u_nint(*(x))
#define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
#define d_sign(a,b) u_sign(*(a),*(b))
#define r_sign(a,b) u_sign(*(a),*(b))
#define d_sin(x) (sin(*(x)))
#define d_sinh(x) (sinh(*(x)))
#define d_sqrt(x) (sqrt(*(x)))
#define d_tan(x) (tan(*(x)))
#define d_tanh(x) (tanh(*(x)))
#define i_abs(x) abs(*(x))
#define i_dnnt(x) ((integer)u_nint(*(x)))
#define i_len(s, n) (n)
#define i_nint(x) ((integer)u_nint(*(x)))
#define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
#define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
#define pow_si(B,E) spow_ui(*(B),*(E))
#define pow_ri(B,E) spow_ui(*(B),*(E))
#define pow_di(B,E) dpow_ui(*(B),*(E))
#define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
#define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
#define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
#define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
#define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
#define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
#define sig_die(s, kill) { exit(1); }
#define s_stop(s, n) {exit(0);}
static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
#define z_abs(z) (cabs(Cd(z)))
#define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
#define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
#define myexit_() break;
#define mycycle() continue;
#define myceiling(w) {ceil(w)}
#define myhuge(w) {HUGE_VAL}
//#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
#define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
/* procedure parameter types for -A and -C++ */
#define F2C_proc_par_types 1
#ifdef __cplusplus
typedef logical (*L_fp)(...);
#else
typedef logical (*L_fp)();
#endif
static float spow_ui(float x, integer n) {
float pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static double dpow_ui(double x, integer n) {
double pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
#ifdef _MSC_VER
static _Fcomplex cpow_ui(complex x, integer n) {
complex pow={1.0,0.0}; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
for(u = n; ; ) {
if(u & 01) pow.r *= x.r, pow.i *= x.i;
if(u >>= 1) x.r *= x.r, x.i *= x.i;
else break;
}
}
_Fcomplex p={pow.r, pow.i};
return p;
}
#else
static _Complex float cpow_ui(_Complex float x, integer n) {
_Complex float pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
#endif
#ifdef _MSC_VER
static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
_Dcomplex pow={1.0,0.0}; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
for(u = n; ; ) {
if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
else break;
}
}
_Dcomplex p = {pow._Val[0], pow._Val[1]};
return p;
}
#else
static _Complex double zpow_ui(_Complex double x, integer n) {
_Complex double pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
#endif
static integer pow_ii(integer x, integer n) {
integer pow; unsigned long int u;
if (n <= 0) {
if (n == 0 || x == 1) pow = 1;
else if (x != -1) pow = x == 0 ? 1/x : 0;
else n = -n;
}
if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
u = n;
for(pow = 1; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static integer dmaxloc_(double *w, integer s, integer e, integer *n)
{
double m; integer i, mi;
for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
if (w[i-1]>m) mi=i ,m=w[i-1];
return mi-s+1;
}
static integer smaxloc_(float *w, integer s, integer e, integer *n)
{
float m; integer i, mi;
for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
if (w[i-1]>m) mi=i ,m=w[i-1];
return mi-s+1;
}
static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
#ifdef _MSC_VER
_Fcomplex zdotc = {0.0, 0.0};
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
}
}
pCf(z) = zdotc;
}
#else
_Complex float zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
}
}
pCf(z) = zdotc;
}
#endif
static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
#ifdef _MSC_VER
_Dcomplex zdotc = {0.0, 0.0};
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
}
}
pCd(z) = zdotc;
}
#else
_Complex double zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
}
}
pCd(z) = zdotc;
}
#endif
static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
#ifdef _MSC_VER
_Fcomplex zdotc = {0.0, 0.0};
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
}
}
pCf(z) = zdotc;
}
#else
_Complex float zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cf(&x[i]) * Cf(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
}
}
pCf(z) = zdotc;
}
#endif
static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
#ifdef _MSC_VER
_Dcomplex zdotc = {0.0, 0.0};
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
}
}
pCd(z) = zdotc;
}
#else
_Complex double zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cd(&x[i]) * Cd(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
}
}
pCd(z) = zdotc;
}
#endif
/* -- translated by f2c (version 20000121).
You must link the resulting object file with the libraries:
-lf2c -lm (in that order)
*/
/* Table of constant values */
static integer c__1 = 1;
static logical c_true = TRUE_;
static logical c_false = FALSE_;
/* > \brief \b DTRSNA */
/* =========== DOCUMENTATION =========== */
/* Online html documentation available at */
/* http://www.netlib.org/lapack/explore-html/ */
/* > \htmlonly */
/* > Download DTRSNA + dependencies */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dtrsna.
f"> */
/* > [TGZ]</a> */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dtrsna.
f"> */
/* > [ZIP]</a> */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dtrsna.
f"> */
/* > [TXT]</a> */
/* > \endhtmlonly */
/* Definition: */
/* =========== */
/* SUBROUTINE DTRSNA( JOB, HOWMNY, SELECT, N, T, LDT, VL, LDVL, VR, */
/* LDVR, S, SEP, MM, M, WORK, LDWORK, IWORK, */
/* INFO ) */
/* CHARACTER HOWMNY, JOB */
/* INTEGER INFO, LDT, LDVL, LDVR, LDWORK, M, MM, N */
/* LOGICAL SELECT( * ) */
/* INTEGER IWORK( * ) */
/* DOUBLE PRECISION S( * ), SEP( * ), T( LDT, * ), VL( LDVL, * ), */
/* $ VR( LDVR, * ), WORK( LDWORK, * ) */
/* > \par Purpose: */
/* ============= */
/* > */
/* > \verbatim */
/* > */
/* > DTRSNA estimates reciprocal condition numbers for specified */
/* > eigenvalues and/or right eigenvectors of a real upper */
/* > quasi-triangular matrix T (or of any matrix Q*T*Q**T with Q */
/* > orthogonal). */
/* > */
/* > T must be in Schur canonical form (as returned by DHSEQR), that is, */
/* > block upper triangular with 1-by-1 and 2-by-2 diagonal blocks; each */
/* > 2-by-2 diagonal block has its diagonal elements equal and its */
/* > off-diagonal elements of opposite sign. */
/* > \endverbatim */
/* Arguments: */
/* ========== */
/* > \param[in] JOB */
/* > \verbatim */
/* > JOB is CHARACTER*1 */
/* > Specifies whether condition numbers are required for */
/* > eigenvalues (S) or eigenvectors (SEP): */
/* > = 'E': for eigenvalues only (S); */
/* > = 'V': for eigenvectors only (SEP); */
/* > = 'B': for both eigenvalues and eigenvectors (S and SEP). */
/* > \endverbatim */
/* > */
/* > \param[in] HOWMNY */
/* > \verbatim */
/* > HOWMNY is CHARACTER*1 */
/* > = 'A': compute condition numbers for all eigenpairs; */
/* > = 'S': compute condition numbers for selected eigenpairs */
/* > specified by the array SELECT. */
/* > \endverbatim */
/* > */
/* > \param[in] SELECT */
/* > \verbatim */
/* > SELECT is LOGICAL array, dimension (N) */
/* > If HOWMNY = 'S', SELECT specifies the eigenpairs for which */
/* > condition numbers are required. To select condition numbers */
/* > for the eigenpair corresponding to a real eigenvalue w(j), */
/* > SELECT(j) must be set to .TRUE.. To select condition numbers */
/* > corresponding to a complex conjugate pair of eigenvalues w(j) */
/* > and w(j+1), either SELECT(j) or SELECT(j+1) or both, must be */
/* > set to .TRUE.. */
/* > If HOWMNY = 'A', SELECT is not referenced. */
/* > \endverbatim */
/* > */
/* > \param[in] N */
/* > \verbatim */
/* > N is INTEGER */
/* > The order of the matrix T. N >= 0. */
/* > \endverbatim */
/* > */
/* > \param[in] T */
/* > \verbatim */
/* > T is DOUBLE PRECISION array, dimension (LDT,N) */
/* > The upper quasi-triangular matrix T, in Schur canonical form. */
/* > \endverbatim */
/* > */
/* > \param[in] LDT */
/* > \verbatim */
/* > LDT is INTEGER */
/* > The leading dimension of the array T. LDT >= f2cmax(1,N). */
/* > \endverbatim */
/* > */
/* > \param[in] VL */
/* > \verbatim */
/* > VL is DOUBLE PRECISION array, dimension (LDVL,M) */
/* > If JOB = 'E' or 'B', VL must contain left eigenvectors of T */
/* > (or of any Q*T*Q**T with Q orthogonal), corresponding to the */
/* > eigenpairs specified by HOWMNY and SELECT. The eigenvectors */
/* > must be stored in consecutive columns of VL, as returned by */
/* > DHSEIN or DTREVC. */
/* > If JOB = 'V', VL is not referenced. */
/* > \endverbatim */
/* > */
/* > \param[in] LDVL */
/* > \verbatim */
/* > LDVL is INTEGER */
/* > The leading dimension of the array VL. */
/* > LDVL >= 1; and if JOB = 'E' or 'B', LDVL >= N. */
/* > \endverbatim */
/* > */
/* > \param[in] VR */
/* > \verbatim */
/* > VR is DOUBLE PRECISION array, dimension (LDVR,M) */
/* > If JOB = 'E' or 'B', VR must contain right eigenvectors of T */
/* > (or of any Q*T*Q**T with Q orthogonal), corresponding to the */
/* > eigenpairs specified by HOWMNY and SELECT. The eigenvectors */
/* > must be stored in consecutive columns of VR, as returned by */
/* > DHSEIN or DTREVC. */
/* > If JOB = 'V', VR is not referenced. */
/* > \endverbatim */
/* > */
/* > \param[in] LDVR */
/* > \verbatim */
/* > LDVR is INTEGER */
/* > The leading dimension of the array VR. */
/* > LDVR >= 1; and if JOB = 'E' or 'B', LDVR >= N. */
/* > \endverbatim */
/* > */
/* > \param[out] S */
/* > \verbatim */
/* > S is DOUBLE PRECISION array, dimension (MM) */
/* > If JOB = 'E' or 'B', the reciprocal condition numbers of the */
/* > selected eigenvalues, stored in consecutive elements of the */
/* > array. For a complex conjugate pair of eigenvalues two */
/* > consecutive elements of S are set to the same value. Thus */
/* > S(j), SEP(j), and the j-th columns of VL and VR all */
/* > correspond to the same eigenpair (but not in general the */
/* > j-th eigenpair, unless all eigenpairs are selected). */
/* > If JOB = 'V', S is not referenced. */
/* > \endverbatim */
/* > */
/* > \param[out] SEP */
/* > \verbatim */
/* > SEP is DOUBLE PRECISION array, dimension (MM) */
/* > If JOB = 'V' or 'B', the estimated reciprocal condition */
/* > numbers of the selected eigenvectors, stored in consecutive */
/* > elements of the array. For a complex eigenvector two */
/* > consecutive elements of SEP are set to the same value. If */
/* > the eigenvalues cannot be reordered to compute SEP(j), SEP(j) */
/* > is set to 0; this can only occur when the true value would be */
/* > very small anyway. */
/* > If JOB = 'E', SEP is not referenced. */
/* > \endverbatim */
/* > */
/* > \param[in] MM */
/* > \verbatim */
/* > MM is INTEGER */
/* > The number of elements in the arrays S (if JOB = 'E' or 'B') */
/* > and/or SEP (if JOB = 'V' or 'B'). MM >= M. */
/* > \endverbatim */
/* > */
/* > \param[out] M */
/* > \verbatim */
/* > M is INTEGER */
/* > The number of elements of the arrays S and/or SEP actually */
/* > used to store the estimated condition numbers. */
/* > If HOWMNY = 'A', M is set to N. */
/* > \endverbatim */
/* > */
/* > \param[out] WORK */
/* > \verbatim */
/* > WORK is DOUBLE PRECISION array, dimension (LDWORK,N+6) */
/* > If JOB = 'E', WORK is not referenced. */
/* > \endverbatim */
/* > */
/* > \param[in] LDWORK */
/* > \verbatim */
/* > LDWORK is INTEGER */
/* > The leading dimension of the array WORK. */
/* > LDWORK >= 1; and if JOB = 'V' or 'B', LDWORK >= N. */
/* > \endverbatim */
/* > */
/* > \param[out] IWORK */
/* > \verbatim */
/* > IWORK is INTEGER array, dimension (2*(N-1)) */
/* > If JOB = 'E', IWORK is not referenced. */
/* > \endverbatim */
/* > */
/* > \param[out] INFO */
/* > \verbatim */
/* > INFO is INTEGER */
/* > = 0: successful exit */
/* > < 0: if INFO = -i, the i-th argument had an illegal value */
/* > \endverbatim */
/* Authors: */
/* ======== */
/* > \author Univ. of Tennessee */
/* > \author Univ. of California Berkeley */
/* > \author Univ. of Colorado Denver */
/* > \author NAG Ltd. */
/* > \date November 2017 */
/* > \ingroup doubleOTHERcomputational */
/* > \par Further Details: */
/* ===================== */
/* > */
/* > \verbatim */
/* > */
/* > The reciprocal of the condition number of an eigenvalue lambda is */
/* > defined as */
/* > */
/* > S(lambda) = |v**T*u| / (norm(u)*norm(v)) */
/* > */
/* > where u and v are the right and left eigenvectors of T corresponding */
/* > to lambda; v**T denotes the transpose of v, and norm(u) */
/* > denotes the Euclidean norm. These reciprocal condition numbers always */
/* > lie between zero (very badly conditioned) and one (very well */
/* > conditioned). If n = 1, S(lambda) is defined to be 1. */
/* > */
/* > An approximate error bound for a computed eigenvalue W(i) is given by */
/* > */
/* > EPS * norm(T) / S(i) */
/* > */
/* > where EPS is the machine precision. */
/* > */
/* > The reciprocal of the condition number of the right eigenvector u */
/* > corresponding to lambda is defined as follows. Suppose */
/* > */
/* > T = ( lambda c ) */
/* > ( 0 T22 ) */
/* > */
/* > Then the reciprocal condition number is */
/* > */
/* > SEP( lambda, T22 ) = sigma-f2cmin( T22 - lambda*I ) */
/* > */
/* > where sigma-f2cmin denotes the smallest singular value. We approximate */
/* > the smallest singular value by the reciprocal of an estimate of the */
/* > one-norm of the inverse of T22 - lambda*I. If n = 1, SEP(1) is */
/* > defined to be abs(T(1,1)). */
/* > */
/* > An approximate error bound for a computed right eigenvector VR(i) */
/* > is given by */
/* > */
/* > EPS * norm(T) / SEP(i) */
/* > \endverbatim */
/* > */
/* ===================================================================== */
/* Subroutine */ int dtrsna_(char *job, char *howmny, logical *select,
integer *n, doublereal *t, integer *ldt, doublereal *vl, integer *
ldvl, doublereal *vr, integer *ldvr, doublereal *s, doublereal *sep,
integer *mm, integer *m, doublereal *work, integer *ldwork, integer *
iwork, integer *info)
{
/* System generated locals */
integer t_dim1, t_offset, vl_dim1, vl_offset, vr_dim1, vr_offset,
work_dim1, work_offset, i__1, i__2;
doublereal d__1, d__2;
/* Local variables */
integer kase;
doublereal cond;
extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *,
integer *);
logical pair;
integer ierr;
doublereal dumm, prod;
integer ifst;
doublereal lnrm;
integer ilst;
doublereal rnrm;
extern doublereal dnrm2_(integer *, doublereal *, integer *);
doublereal prod1, prod2;
integer i__, j, k;
doublereal scale, delta;
extern logical lsame_(char *, char *);
integer isave[3];
logical wants;
doublereal dummy[1];
integer n2;
extern /* Subroutine */ int dlacn2_(integer *, doublereal *, doublereal *,
integer *, doublereal *, integer *, integer *);
extern doublereal dlapy2_(doublereal *, doublereal *);
extern /* Subroutine */ int dlabad_(doublereal *, doublereal *);
doublereal cs;
extern doublereal dlamch_(char *);
integer nn, ks;
doublereal sn, mu;
extern /* Subroutine */ int dlacpy_(char *, integer *, integer *,
doublereal *, integer *, doublereal *, integer *),
xerbla_(char *, integer *, ftnlen);
doublereal bignum;
logical wantbh;
extern /* Subroutine */ int dlaqtr_(logical *, logical *, integer *,
doublereal *, integer *, doublereal *, doublereal *, doublereal *,
doublereal *, doublereal *, integer *), dtrexc_(char *, integer *
, doublereal *, integer *, doublereal *, integer *, integer *,
integer *, doublereal *, integer *);
logical somcon;
doublereal smlnum;
logical wantsp;
doublereal eps, est;
/* -- LAPACK computational routine (version 3.8.0) -- */
/* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
/* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
/* November 2017 */
/* ===================================================================== */
/* Decode and test the input parameters */
/* Parameter adjustments */
--select;
t_dim1 = *ldt;
t_offset = 1 + t_dim1 * 1;
t -= t_offset;
vl_dim1 = *ldvl;
vl_offset = 1 + vl_dim1 * 1;
vl -= vl_offset;
vr_dim1 = *ldvr;
vr_offset = 1 + vr_dim1 * 1;
vr -= vr_offset;
--s;
--sep;
work_dim1 = *ldwork;
work_offset = 1 + work_dim1 * 1;
work -= work_offset;
--iwork;
/* Function Body */
wantbh = lsame_(job, "B");
wants = lsame_(job, "E") || wantbh;
wantsp = lsame_(job, "V") || wantbh;
somcon = lsame_(howmny, "S");
*info = 0;
if (! wants && ! wantsp) {
*info = -1;
} else if (! lsame_(howmny, "A") && ! somcon) {
*info = -2;
} else if (*n < 0) {
*info = -4;
} else if (*ldt < f2cmax(1,*n)) {
*info = -6;
} else if (*ldvl < 1 || wants && *ldvl < *n) {
*info = -8;
} else if (*ldvr < 1 || wants && *ldvr < *n) {
*info = -10;
} else {
/* Set M to the number of eigenpairs for which condition numbers */
/* are required, and test MM. */
if (somcon) {
*m = 0;
pair = FALSE_;
i__1 = *n;
for (k = 1; k <= i__1; ++k) {
if (pair) {
pair = FALSE_;
} else {
if (k < *n) {
if (t[k + 1 + k * t_dim1] == 0.) {
if (select[k]) {
++(*m);
}
} else {
pair = TRUE_;
if (select[k] || select[k + 1]) {
*m += 2;
}
}
} else {
if (select[*n]) {
++(*m);
}
}
}
/* L10: */
}
} else {
*m = *n;
}
if (*mm < *m) {
*info = -13;
} else if (*ldwork < 1 || wantsp && *ldwork < *n) {
*info = -16;
}
}
if (*info != 0) {
i__1 = -(*info);
xerbla_("DTRSNA", &i__1, (ftnlen)6);
return 0;
}
/* Quick return if possible */
if (*n == 0) {
return 0;
}
if (*n == 1) {
if (somcon) {
if (! select[1]) {
return 0;
}
}
if (wants) {
s[1] = 1.;
}
if (wantsp) {
sep[1] = (d__1 = t[t_dim1 + 1], abs(d__1));
}
return 0;
}
/* Get machine constants */
eps = dlamch_("P");
smlnum = dlamch_("S") / eps;
bignum = 1. / smlnum;
dlabad_(&smlnum, &bignum);
ks = 0;
pair = FALSE_;
i__1 = *n;
for (k = 1; k <= i__1; ++k) {
/* Determine whether T(k,k) begins a 1-by-1 or 2-by-2 block. */
if (pair) {
pair = FALSE_;
goto L60;
} else {
if (k < *n) {
pair = t[k + 1 + k * t_dim1] != 0.;
}
}
/* Determine whether condition numbers are required for the k-th */
/* eigenpair. */
if (somcon) {
if (pair) {
if (! select[k] && ! select[k + 1]) {
goto L60;
}
} else {
if (! select[k]) {
goto L60;
}
}
}
++ks;
if (wants) {
/* Compute the reciprocal condition number of the k-th */
/* eigenvalue. */
if (! pair) {
/* Real eigenvalue. */
prod = ddot_(n, &vr[ks * vr_dim1 + 1], &c__1, &vl[ks *
vl_dim1 + 1], &c__1);
rnrm = dnrm2_(n, &vr[ks * vr_dim1 + 1], &c__1);
lnrm = dnrm2_(n, &vl[ks * vl_dim1 + 1], &c__1);
s[ks] = abs(prod) / (rnrm * lnrm);
} else {
/* Complex eigenvalue. */
prod1 = ddot_(n, &vr[ks * vr_dim1 + 1], &c__1, &vl[ks *
vl_dim1 + 1], &c__1);
prod1 += ddot_(n, &vr[(ks + 1) * vr_dim1 + 1], &c__1, &vl[(ks
+ 1) * vl_dim1 + 1], &c__1);
prod2 = ddot_(n, &vl[ks * vl_dim1 + 1], &c__1, &vr[(ks + 1) *
vr_dim1 + 1], &c__1);
prod2 -= ddot_(n, &vl[(ks + 1) * vl_dim1 + 1], &c__1, &vr[ks *
vr_dim1 + 1], &c__1);
d__1 = dnrm2_(n, &vr[ks * vr_dim1 + 1], &c__1);
d__2 = dnrm2_(n, &vr[(ks + 1) * vr_dim1 + 1], &c__1);
rnrm = dlapy2_(&d__1, &d__2);
d__1 = dnrm2_(n, &vl[ks * vl_dim1 + 1], &c__1);
d__2 = dnrm2_(n, &vl[(ks + 1) * vl_dim1 + 1], &c__1);
lnrm = dlapy2_(&d__1, &d__2);
cond = dlapy2_(&prod1, &prod2) / (rnrm * lnrm);
s[ks] = cond;
s[ks + 1] = cond;
}
}
if (wantsp) {
/* Estimate the reciprocal condition number of the k-th */
/* eigenvector. */
/* Copy the matrix T to the array WORK and swap the diagonal */
/* block beginning at T(k,k) to the (1,1) position. */
dlacpy_("Full", n, n, &t[t_offset], ldt, &work[work_offset],
ldwork);
ifst = k;
ilst = 1;
dtrexc_("No Q", n, &work[work_offset], ldwork, dummy, &c__1, &
ifst, &ilst, &work[(*n + 1) * work_dim1 + 1], &ierr);
if (ierr == 1 || ierr == 2) {
/* Could not swap because blocks not well separated */
scale = 1.;
est = bignum;
} else {
/* Reordering successful */
if (work[work_dim1 + 2] == 0.) {
/* Form C = T22 - lambda*I in WORK(2:N,2:N). */
i__2 = *n;
for (i__ = 2; i__ <= i__2; ++i__) {
work[i__ + i__ * work_dim1] -= work[work_dim1 + 1];
/* L20: */
}
n2 = 1;
nn = *n - 1;
} else {
/* Triangularize the 2 by 2 block by unitary */
/* transformation U = [ cs i*ss ] */
/* [ i*ss cs ]. */
/* such that the (1,1) position of WORK is complex */
/* eigenvalue lambda with positive imaginary part. (2,2) */
/* position of WORK is the complex eigenvalue lambda */
/* with negative imaginary part. */
mu = sqrt((d__1 = work[(work_dim1 << 1) + 1], abs(d__1)))
* sqrt((d__2 = work[work_dim1 + 2], abs(d__2)));
delta = dlapy2_(&mu, &work[work_dim1 + 2]);
cs = mu / delta;
sn = -work[work_dim1 + 2] / delta;
/* Form */
/* C**T = WORK(2:N,2:N) + i*[rwork(1) ..... rwork(n-1) ] */
/* [ mu ] */
/* [ .. ] */
/* [ .. ] */
/* [ mu ] */
/* where C**T is transpose of matrix C, */
/* and RWORK is stored starting in the N+1-st column of */
/* WORK. */
i__2 = *n;
for (j = 3; j <= i__2; ++j) {
work[j * work_dim1 + 2] = cs * work[j * work_dim1 + 2]
;
work[j + j * work_dim1] -= work[work_dim1 + 1];
/* L30: */
}
work[(work_dim1 << 1) + 2] = 0.;
work[(*n + 1) * work_dim1 + 1] = mu * 2.;
i__2 = *n - 1;
for (i__ = 2; i__ <= i__2; ++i__) {
work[i__ + (*n + 1) * work_dim1] = sn * work[(i__ + 1)
* work_dim1 + 1];
/* L40: */
}
n2 = 2;
nn = *n - 1 << 1;
}
/* Estimate norm(inv(C**T)) */
est = 0.;
kase = 0;
L50:
dlacn2_(&nn, &work[(*n + 2) * work_dim1 + 1], &work[(*n + 4) *
work_dim1 + 1], &iwork[1], &est, &kase, isave);
if (kase != 0) {
if (kase == 1) {
if (n2 == 1) {
/* Real eigenvalue: solve C**T*x = scale*c. */
i__2 = *n - 1;
dlaqtr_(&c_true, &c_true, &i__2, &work[(work_dim1
<< 1) + 2], ldwork, dummy, &dumm, &scale,
&work[(*n + 4) * work_dim1 + 1], &work[(*
n + 6) * work_dim1 + 1], &ierr);
} else {
/* Complex eigenvalue: solve */
/* C**T*(p+iq) = scale*(c+id) in real arithmetic. */
i__2 = *n - 1;
dlaqtr_(&c_true, &c_false, &i__2, &work[(
work_dim1 << 1) + 2], ldwork, &work[(*n +
1) * work_dim1 + 1], &mu, &scale, &work[(*
n + 4) * work_dim1 + 1], &work[(*n + 6) *
work_dim1 + 1], &ierr);
}
} else {
if (n2 == 1) {
/* Real eigenvalue: solve C*x = scale*c. */
i__2 = *n - 1;
dlaqtr_(&c_false, &c_true, &i__2, &work[(
work_dim1 << 1) + 2], ldwork, dummy, &
dumm, &scale, &work[(*n + 4) * work_dim1
+ 1], &work[(*n + 6) * work_dim1 + 1], &
ierr);
} else {
/* Complex eigenvalue: solve */
/* C*(p+iq) = scale*(c+id) in real arithmetic. */
i__2 = *n - 1;
dlaqtr_(&c_false, &c_false, &i__2, &work[(
work_dim1 << 1) + 2], ldwork, &work[(*n +
1) * work_dim1 + 1], &mu, &scale, &work[(*
n + 4) * work_dim1 + 1], &work[(*n + 6) *
work_dim1 + 1], &ierr);
}
}
goto L50;
}
}
sep[ks] = scale / f2cmax(est,smlnum);
if (pair) {
sep[ks + 1] = sep[ks];
}
}
if (pair) {
++ks;
}
L60:
;
}
return 0;
/* End of DTRSNA */
} /* dtrsna_ */
|
the_stack_data/681742.c | #include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <math.h>
#include <float.h>
static int Slfit (double *, double *, double *, int, double *, int *, int,
double **, void (*funcs)(double, double [], int));
static int Sgaussj (double **, int, double **, int);
static void Scovsrt (double **covar, int ma, int ia[], int mfit);
static int *ivector(long nl, long nh);
static void free_ivector(int *v, long nl, long nh);
static void free_dvector(double *v, long nl, long nh);
static double *dvector(long nl, long nh);
static double **dmatrix(long nrl, long nrh, long ncl, long nch);
static void free_dmatrix(double **m, long nrl, long nrh, long ncl, long nch);
static void nrerror(char *);
/*
Polynomial least squares fit.
We use for now Numerical Recipes routines modified to work in
double precision, and to handle a origin-offseted data set, in
order to improve accuracy.
Revision history:
----------------
10 Jan 00 - Implemented (I.Busko)
12 Jan 05 - FitPoly now returns -1 if ndat is too small (Phil Hodge)
*/
/*
Compute basis functions.
*/
void poly (double x, double values[], int n) {
int i;
for (i = 1; i <= n; i++)
values[i] = pow ((double)x, (double)(i-1));
}
/*
Compute polynomial coefficients. The coefficient array must be allocated
with two additional elements besides the ones necessary to hold the
polynomial coefficients themselves. The first two elements in the array
will hold the average of the input x and y arrays, respectively. The
computed coefficients will describe a polynomial relative to these
two averages. Function ComputePoly will properly take care of restoring
the offsets.
The function value (status return) will be -1 if the number of input
data points is less than 1 + the degree of the polynomial.
*/
int FitPoly (double ix[], double iy[], double iw[], int ndat,
int degree, double coeff[]) {
/* arguments:
double ix[]; i: input independent variable
double iy[]; i: input dependent variable
double iw[]; i: input weights, always positive or zero
int ndat; i: number of data points
int degree; i: degree of polynomial to fit
double coeff[]; o: output coefficients
*/
int i, nterm, nav, *ia, status;
double *a, *x, *y, *sig, **covar, avx, avy;
nterm = degree + 1;
if (ndat < nterm)
return -1;
/* Compute averages. */
avx = 0.0;
avy = 0.0;
nav = 0;
for (i = 0; i < ndat; i++) {
if (iw[i] > 0.0) {
avx += ix[i];
avy += iy[i];
nav++;
}
}
if (nav > 0) {
avx /= nav;
avy /= nav;
} else {
avx = 0.0;
avy = 0.0;
}
/* Alloc memory. */
ia = ivector (1, nterm);
a = dvector (1, nterm);
x = dvector (1, ndat);
y = dvector (1, ndat);
sig = dvector (1, ndat);
covar = dmatrix (1, nterm, 1, nterm);
/* Initialize data arrays for fitting routine. */
for (i = 1; i <= ndat; i++) {
x[i] = ix[i-1] - avx;
y[i] = iy[i-1] - avy;
if (iw[i-1] > 0.0)
sig[i] = 1.0 / iw[i-1];
else
sig[i] = 1.0;
}
for (i = 1; i <= nterm; ia[i++] = 1);
/* Solve. */
if ((status = Slfit (x, y, sig, ndat, a, ia, nterm, covar, poly)))
return (status);
/* Store coefficients. */
coeff[0] = avx;
coeff[1] = avy;
for (i = 1; i <= nterm; i++)
coeff[i+1] = a[i];
/* Free memory. */
free_dmatrix (covar, 1, nterm, 1, nterm);
free_dvector (sig, 1, ndat);
free_dvector (y, 1, ndat);
free_dvector (x, 1, ndat);
free_dvector (a, 1, nterm);
free_ivector (ia, 1, nterm);
return (0);
}
/*
Compute fitted values.
*/
void ComputePoly (double ix[], int ndat, double coeff[], int degree,
double oy[]) {
/* arguments:
double ix[]; i: input independent variable
int ndat; i: number of data points
double coeff[]; i: coefficients
int degree; i: degree of polynomial
double oy[]; o: output values
*/
int i, j;
for (i = 0; i < ndat; i++) {
oy[i] = 0.0;
for (j = 0; j <= degree; j++)
oy[i] += coeff[j+2] * pow (ix[i] - coeff[0], (double)j);
oy[i] += coeff[1];
}
}
/*
Numerical Recipes code.
This code was modified from its original form to:
- return an error code instead of aborting plain and simple.
- use double precision throughout.
- chisq computation removed.
*/
static int Slfit (double x[], double y[], double sig[], int ndat, double a[],
int ia[], int ma, double **covar,
void (*funcs)(double, double [], int))
{
int i,j,k,l,m,mfit=0,status;
double ym,wt,sig2i,**beta,*afunc;
beta=dmatrix(1,ma,1,1);
afunc=dvector(1,ma);
for (j=1;j<=ma;j++)
if (ia[j]) mfit++;
if (mfit == 0) {
printf ("lfit: no parameters to be fitted\n");
return (1);
}
for (j=1;j<=mfit;j++) {
for (k=1;k<=mfit;k++) covar[j][k]=0.0;
beta[j][1]=0.0;
}
for (i=1;i<=ndat;i++) {
(*funcs)(x[i],afunc,ma);
ym=y[i];
if (mfit < ma) {
for (j=1;j<=ma;j++)
if (!ia[j]) ym -= a[j]*afunc[j];
}
sig2i=1.0/sqrt(sig[i]);
for (j=0,l=1;l<=ma;l++) {
if (ia[l]) {
wt=afunc[l]*sig2i;
for (j++,k=0,m=1;m<=l;m++)
if (ia[m]) covar[j][++k] += wt*afunc[m];
beta[j][1] += ym*wt;
}
}
}
for (j=2;j<=mfit;j++)
for (k=1;k<j;k++)
covar[k][j]=covar[j][k];
if ((status = Sgaussj(covar,mfit,beta,1)))
return (status);
for (j=0,l=1;l<=ma;l++)
if (ia[l]) a[l]=beta[++j][1];
Scovsrt (covar,ma,ia,mfit);
free_dvector(afunc,1,ma);
free_dmatrix(beta,1,ma,1,1);
return (0);
}
#define SWAP(a,b) {swap=(a);(a)=(b);(b)=swap;}
static void Scovsrt (double **covar, int ma, int ia[], int mfit)
{
int i,j,k;
double swap;
for (i=mfit+1;i<=ma;i++)
for (j=1;j<=i;j++) covar[i][j]=covar[j][i]=0.0;
k=mfit;
for (j=ma;j>=1;j--) {
if (ia[j]) {
for (i=1;i<=ma;i++) SWAP(covar[i][k],covar[i][j])
for (i=1;i<=ma;i++) SWAP(covar[k][i],covar[j][i])
k--;
}
}
}
#undef SWAP
#define SWAP(a,b) {temp=(a);(a)=(b);(b)=temp;}
static int Sgaussj (double **a, int n, double **b, int m)
{
int *indxc,*indxr,*ipiv;
int i,icol,irow,j,k,l,ll;
double big,dum,pivinv,temp;
indxc=ivector(1,n);
indxr=ivector(1,n);
ipiv=ivector(1,n);
for (j=1;j<=n;j++) ipiv[j]=0;
for (i=1;i<=n;i++) {
big=0.0;
for (j=1;j<=n;j++)
if (ipiv[j] != 1)
for (k=1;k<=n;k++) {
if (ipiv[k] == 0) {
if (fabs(a[j][k]) >= big) {
big=fabs(a[j][k]);
irow=j;
icol=k;
}
} else if (ipiv[k] > 1) {
printf
("gaussj: Singular Matrix-1\n");
return (1);
}
}
++(ipiv[icol]);
if (irow != icol) {
for (l=1;l<=n;l++) SWAP(a[irow][l],a[icol][l])
for (l=1;l<=m;l++) SWAP(b[irow][l],b[icol][l])
}
indxr[i]=irow;
indxc[i]=icol;
if (a[icol][icol] == 0.0) {
printf("gaussj: Singular Matrix-2\n");
return (1);
}
pivinv=1.0/a[icol][icol];
a[icol][icol]=1.0;
for (l=1;l<=n;l++) a[icol][l] *= pivinv;
for (l=1;l<=m;l++) b[icol][l] *= pivinv;
for (ll=1;ll<=n;ll++)
if (ll != icol) {
dum=a[ll][icol];
a[ll][icol]=0.0;
for (l=1;l<=n;l++) a[ll][l] -= a[icol][l]*dum;
for (l=1;l<=m;l++) b[ll][l] -= b[icol][l]*dum;
}
}
for (l=n;l>=1;l--) {
if (indxr[l] != indxc[l])
for (k=1;k<=n;k++)
SWAP(a[k][indxr[l]],a[k][indxc[l]]);
}
free_ivector(ipiv,1,n);
free_ivector(indxr,1,n);
free_ivector(indxc,1,n);
return (0);
}
#undef SWAP
static int *ivector(nl,nh)
long nh,nl;
{
int *v;
v=(int *)malloc((unsigned int) ((nh-nl+1+1)*sizeof(int)));
if (!v) nrerror("allocation failure in ivector()");
return v-nl+1;
}
static double *dvector(long nl, long nh)
{
double *v;
v=(double *)malloc((size_t) ((nh-nl+1+1)*sizeof(double)));
if (!v) nrerror("allocation failure in dvector()");
return v-nl+1;
}
static double **dmatrix(nrl,nrh,ncl,nch)
long nch,ncl,nrh,nrl;
{
long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
double **m;
m=(double **) malloc((unsigned int)((nrow+1)*sizeof(double*)));
if (!m) nrerror("allocation failure 1 in matrix()");
m += 1;
m -= nrl;
m[nrl]=(double *) malloc((unsigned int)((nrow*ncol+1)*sizeof(double)));
if (!m[nrl]) nrerror("allocation failure 2 in matrix()");
m[nrl] += 1;
m[nrl] -= ncl;
for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
return m;
}
static void free_ivector(int *v, long nl, long nh)
{
free((char*) (v+nl-1));
}
static void free_dvector(v,nl,nh)
double *v;
long nh,nl;
{
free((char*) (v+nl-1));
}
static void free_dmatrix(double **m, long nrl, long nrh, long ncl, long nch)
{
free((char*) (m[nrl]+ncl-1));
free((char*) (m+nrl-1));
}
static void nrerror(char error_text[])
{
fprintf(stderr,"Numerical Recipes run-time error...\n");
fprintf(stderr,"%s\n",error_text);
fprintf(stderr,"...now exiting to system...\n");
exit(1);
}
|
the_stack_data/1137198.c | #include<stdio.h>
int main()
{
int ar[20];
int i = 0;
for (i=0; i<20; i++)
{
ar[i]=15;
}
return 0;
}
|
the_stack_data/609846.c | #include<stdio.h>
int main()
{
printf("*********\n *******\n *****\n ***\n *\n");
return 0;
}
|
the_stack_data/407498.c | #include <pthread.h> //It Will Create POSIX threads.
#include <unistd.h> //Thread calls sleep for specified number of seconds.
#include <semaphore.h> //This header file is to create semaphores
#include <time.h> //This header file is used for Wait for the random time.
#include <stdlib.h>
#include <stdio.h> //Input Output header file
pthread_t *Students; //N threads running as Students.
pthread_t TA; //Separate Thread for TA.
int ChairsCount = 0; //This is a temp variable for counting the no of chairs avialable
int CurrentIndex = 0; //This is temp variable for giving currentindex of the student
//Declaration of Semaphores and Mutex Lock.
sem_t TA_Sleep;
sem_t Student_Sem;
sem_t ChairsSem[3];
pthread_mutex_t ChairAccess;
//Declared Functions
void *TA_Activity();
void *Student_Activity(void *threadID);
void *TA_Activity()
{
while(1)
{
sem_wait(&TA_Sleep); //TA is currently sleeping as no other student is avialable
printf("---------------------------TA has been awakened by a student.-----------------------------\n");
while(1)
{
// lock the room for help so taht another student will not come
pthread_mutex_lock(&ChairAccess);
if(ChairsCount == 0)
{
//if chairs are empty, break the loop that is no student nis there for help .
pthread_mutex_unlock(&ChairAccess);
break;
}
//TA gets next student on chair.
sem_post(&ChairsSem[CurrentIndex]);
ChairsCount--;
printf("Student left his/her chair. Remaining Chairs %d\n", 3 - ChairsCount);
CurrentIndex = (CurrentIndex + 1) % 3;
pthread_mutex_unlock(&ChairAccess);
// unlock
printf("\t TA is currently helping the student.\n");
sleep(5);
sem_post(&Student_Sem);
usleep(1000);
}
}
}
void *Student_Activity(void *threadID)
{
int ProgrammingTime;
while(1)
{
printf("Student %ld is doing programming assignment.\n", (long)threadID);
ProgrammingTime = rand() % 10 + 1;
sleep(ProgrammingTime); //teacher sleeps for random period Sleep for a random time period.
printf("Student %ld needs help from the TA\n", (long)threadID);
pthread_mutex_lock(&ChairAccess);
int count = ChairsCount;
pthread_mutex_unlock(&ChairAccess);
if(count < 3) //As no more chairs avialable for Student but he again tried to sit on a chair but he is unable to sit.
{
if(count == 0) //If student sits on first empty chair, wake up the TA.
sem_post(&TA_Sleep);
else
printf("Student %ld sat on a chair waiting for the TA to finish. \n", (long)threadID);
// lock
pthread_mutex_lock(&ChairAccess);
int index = (CurrentIndex + ChairsCount) % 3;
ChairsCount++;
printf("Student sat on chair.Chairs Remaining: %d\n", 3 - ChairsCount);
pthread_mutex_unlock(&ChairAccess);
// unlock
sem_wait(&ChairsSem[index]); //Student leaves his/her chair.
printf("\t Student %ld is getting help from the TA. \n", (long)threadID);
sem_wait(&Student_Sem); //Student waits to go next.
printf("Student %ld left TA room.\n",(long)threadID);
}
else
printf("Student %ld will return at another time. \n", (long)threadID);
//If student didn't find any chair to sit on.
}
}
int main(int argc, char* argv[])
{
int number_of_students; //a variable taken from the user to create student threads.
int id; //Default is 5 student threads so that if more than 3 students came its ask next student to come after some time .
srand(time(NULL)); //random time
//Initializing Mutex Lock and Semaphores.
sem_init(&TA_Sleep, 0, 0);
sem_init(&Student_Sem, 0, 0);
for(id = 0; id < 3; ++id) //Chairs array of 3 semaphores.
sem_init(&ChairsSem[id], 0, 0);
pthread_mutex_init(&ChairAccess, NULL);
if(argc<2)
{
printf("Number of Students not specified. Using default (5) students.\n"); // print that suppose there are five student come for the help
//by default one by one
number_of_students = 5;
}
else
{
printf("Number of Students specified. Creating %d threads.\n", number_of_students);
number_of_students = atoi(argv[1]);
}
//Allocate memory for Students
Students = (pthread_t*) malloc(sizeof(pthread_t)*number_of_students);
//Creating TA thread and N Student threads.
pthread_create(&TA, NULL, TA_Activity, NULL);
for(id = 0; id < number_of_students; id++)
pthread_create(&Students[id], NULL, Student_Activity,(void*) (long)id);
//Waiting for TA thread and N Student threads.
pthread_join(TA, NULL);
for(id = 0; id < number_of_students; id++)
pthread_join(Students[id], NULL);
//Free allocated memory
free(Students);
return 0;
}
|
the_stack_data/165764193.c | #include <stdlib.h>
#include <unistd.h>
int read_therm(int fd)
{
char buf[32];
ssize_t size;
if ((size = read(fd, buf, sizeof(buf)-1)) == -1)
return -1;
buf[size] = '\0';
lseek(fd, 0, SEEK_SET);
return atoi(buf)/1000;
}
|
the_stack_data/528023.c | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <sys/timeb.h>
/* read timer in second */
double read_timer() {
struct timeb tm;
ftime(&tm);
return (double) tm.time + (double) tm.millitm / 1000.0;
}
/* read timer in ms */
double read_timer_ms() {
struct timeb tm;
ftime(&tm);
return (double) tm.time * 1000.0 + (double) tm.millitm;
}
#define REAL float
#define VECTOR_LENGTH 512
/* initialize a vector with random floating point numbers */
void init(REAL A[], int N) {
int i;
for (i = 0; i < N; i++) {
A[i] = (double) drand48();
}
}
void mm(int N, int K, int M, REAL * A, REAL * B, REAL * C);
void mm_parallel_row(int N, int K, int M, REAL * A, REAL * B, REAL * C, int num_tasks);
void mm_parallel_col(int N, int K, int M, REAL * A, REAL * B, REAL * C, int num_tasks);
void mm_parallel_rowcol(int N, int K, int M, REAL * A, REAL * B, REAL * C, int num_tasks);
void mm_parallel_for_row(int N, int K, int M, REAL * A, REAL * B, REAL * C, int num_tasks);
void mm_parallel_for_col(int N, int K, int M, REAL * A, REAL * B, REAL * C, int num_tasks);
void mm_parallel_for_rowcol(int N, int K, int M, REAL * A, REAL * B, REAL * C, int num_tasks);
/**
* To compile: gcc mm.c -fopenmp -o mm
*/
int main(int argc, char *argv[]) {
int N = VECTOR_LENGTH;
int M = N;
int K = N;
int num_tasks = 4;
double elapsed; /* for timing */
if (argc < 5) {
fprintf(stderr, "Usage: mm [<N(%d)>] <K(%d) [<M(%d)>] [<#tasks(%d)>]\n", N,K,M,num_tasks);
fprintf(stderr, "\t Example: ./mm %d %d %d %d\n", N,K,M,num_tasks);
} else {
N = atoi(argv[1]);
K = atoi(argv[2]);
M = atoi(argv[3]);
num_tasks = atoi(argv[4]);
}
printf("\tC[%d][%d] = A[%d][%d] * B[%d][%d] with %d tasks\n", N, M, N, K, K, M, num_tasks);
REAL * A = malloc(sizeof(REAL)*N*K);
REAL * B = malloc(sizeof(REAL)*K*M);
REAL * C = malloc(sizeof(REAL)*N*M);
srand48((1 << 12));
init(A, N*K);
init(B, K*M);
/* example run */
double elapsed_mm = read_timer();
mm(N, K, M, A, B, C);
elapsed_mm = (read_timer() - elapsed_mm);
double elapsed_mm_parallel_row = read_timer();
mm_parallel_row(N, K, M, A, B, C, num_tasks);
elapsed_mm_parallel_row = (read_timer() - elapsed_mm_parallel_row);
/* more runs */
/* you should add the call to each function and time the execution */
printf("======================================================================================================\n");
printf("\tC[%d][%d] = A[%d][%d] * B[%d][%d] with %d tasks\n", N, M, N, K, K, M, num_tasks);
printf("------------------------------------------------------------------------------------------------------\n");
printf("Performance:\t\t\t\tRuntime (ms)\t MFLOPS \n");
printf("------------------------------------------------------------------------------------------------------\n");
printf("mm:\t\t%4f\t%4f\n", elapsed_mm * 1.0e3, M*N*K / (1.0e6 * elapsed_mm));
printf("mm_parallel_row:\t\t%4f\t%4f\n", elapsed_mm_parallel_row * 1.0e3, M*N*K / (1.0e6 * elapsed_mm_parallel_row));
free(A);
free(B);
free(C);
return 0;
}
void mm(int N, int K, int M, REAL * A, REAL * B, REAL * C) {
int i, j, w;
for (i=0; i<N; i++)
for (j=0; j<M; j++) {
REAL temp = 0.0;
for (w=0; w<K; w++)
temp += A[i*K+w]*B[w*M+j];
C[i*M+j] = temp;
}
}
/* your implementation of all functions */
void mm_parallel_row(int N, int K, int M, REAL * A, REAL * B, REAL * C, int num_tasks) {
}
|
the_stack_data/87670.c | /*
* Copyright (C) 2015-2018 Alibaba Group Holding Limited
*/
/*
* The following sources were referenced in the design of this implementation
* of the RSA algorithm:
*
* [1] A method for obtaining digital signatures and public-key cryptosystems
* R Rivest, A Shamir, and L Adleman
* http://people.csail.mit.edu/rivest/pubs.html#RSA78
*
* [2] Handbook of Applied Cryptography - 1997, Chapter 8
* Menezes, van Oorschot and Vanstone
*
* [3] Malware Guard Extension: Using SGX to Conceal Cache Attacks
* Michael Schwarz, Samuel Weiser, Daniel Gruss, Clémentine Maurice and
* Stefan Mangard
* https://arxiv.org/abs/1702.08719v2
*
*/
#ifdef SUPPORT_TLS
#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
#else
#include MBEDTLS_CONFIG_FILE
#endif
#if defined(MBEDTLS_RSA_C)
#include "mbedtls/rsa.h"
#include "mbedtls/oid.h"
#include <string.h>
#if defined(MBEDTLS_PKCS1_V21)
#include "mbedtls/md.h"
#endif
#if defined(MBEDTLS_PKCS1_V15) && !defined(__OpenBSD__)
#include <stdlib.h>
#endif
#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#else
#include <stdio.h>
#define mbedtls_printf printf
#define mbedtls_calloc calloc
#define mbedtls_free free
#endif
/* Implementation that should never be optimized out by the compiler */
static void mbedtls_zeroize( void *v, size_t n ) {
volatile unsigned char *p = (unsigned char*)v; while( n-- ) *p++ = 0;
}
/*
* Initialize an RSA context
*/
void mbedtls_rsa_init( mbedtls_rsa_context *ctx,
int padding,
int hash_id )
{
memset( ctx, 0, sizeof( mbedtls_rsa_context ) );
mbedtls_rsa_set_padding( ctx, padding, hash_id );
#if defined(MBEDTLS_THREADING_C)
mbedtls_mutex_init( &ctx->mutex );
#endif
}
/*
* Set padding for an existing RSA context
*/
void mbedtls_rsa_set_padding( mbedtls_rsa_context *ctx, int padding, int hash_id )
{
ctx->padding = padding;
ctx->hash_id = hash_id;
}
#if defined(MBEDTLS_GENPRIME)
/*
* Generate an RSA keypair
*/
int mbedtls_rsa_gen_key( mbedtls_rsa_context *ctx,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng,
unsigned int nbits, int exponent )
{
int ret;
mbedtls_mpi P1, Q1, H, G;
if( f_rng == NULL || nbits < 128 || exponent < 3 )
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
if( nbits % 2 )
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
mbedtls_mpi_init( &P1 ); mbedtls_mpi_init( &Q1 );
mbedtls_mpi_init( &H ); mbedtls_mpi_init( &G );
/*
* find primes P and Q with Q < P so that:
* GCD( E, (P-1)*(Q-1) ) == 1
*/
MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &ctx->E, exponent ) );
do
{
MBEDTLS_MPI_CHK( mbedtls_mpi_gen_prime( &ctx->P, nbits >> 1, 0,
f_rng, p_rng ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_gen_prime( &ctx->Q, nbits >> 1, 0,
f_rng, p_rng ) );
if( mbedtls_mpi_cmp_mpi( &ctx->P, &ctx->Q ) == 0 )
continue;
MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &ctx->N, &ctx->P, &ctx->Q ) );
if( mbedtls_mpi_bitlen( &ctx->N ) != nbits )
continue;
if( mbedtls_mpi_cmp_mpi( &ctx->P, &ctx->Q ) < 0 )
mbedtls_mpi_swap( &ctx->P, &ctx->Q );
MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &P1, &ctx->P, 1 ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &Q1, &ctx->Q, 1 ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &H, &P1, &Q1 ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_gcd( &G, &ctx->E, &H ) );
}
while( mbedtls_mpi_cmp_int( &G, 1 ) != 0 );
/*
* D = E^-1 mod ((P-1)*(Q-1))
* DP = D mod (P - 1)
* DQ = D mod (Q - 1)
* QP = Q^-1 mod P
*/
MBEDTLS_MPI_CHK( mbedtls_mpi_inv_mod( &ctx->D , &ctx->E, &H ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &ctx->DP, &ctx->D, &P1 ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &ctx->DQ, &ctx->D, &Q1 ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_inv_mod( &ctx->QP, &ctx->Q, &ctx->P ) );
ctx->len = ( mbedtls_mpi_bitlen( &ctx->N ) + 7 ) >> 3;
cleanup:
mbedtls_mpi_free( &P1 ); mbedtls_mpi_free( &Q1 ); mbedtls_mpi_free( &H ); mbedtls_mpi_free( &G );
if( ret != 0 )
{
mbedtls_rsa_free( ctx );
return( MBEDTLS_ERR_RSA_KEY_GEN_FAILED + ret );
}
return( 0 );
}
#endif /* MBEDTLS_GENPRIME */
/*
* Check a public RSA key
*/
int mbedtls_rsa_check_pubkey( const mbedtls_rsa_context *ctx )
{
if( !ctx->N.p || !ctx->E.p )
return( MBEDTLS_ERR_RSA_KEY_CHECK_FAILED );
if( ( ctx->N.p[0] & 1 ) == 0 ||
( ctx->E.p[0] & 1 ) == 0 )
return( MBEDTLS_ERR_RSA_KEY_CHECK_FAILED );
if( mbedtls_mpi_bitlen( &ctx->N ) < 128 ||
mbedtls_mpi_bitlen( &ctx->N ) > MBEDTLS_MPI_MAX_BITS )
return( MBEDTLS_ERR_RSA_KEY_CHECK_FAILED );
if( mbedtls_mpi_bitlen( &ctx->E ) < 2 ||
mbedtls_mpi_cmp_mpi( &ctx->E, &ctx->N ) >= 0 )
return( MBEDTLS_ERR_RSA_KEY_CHECK_FAILED );
return( 0 );
}
/*
* Check a private RSA key
*/
int mbedtls_rsa_check_privkey( const mbedtls_rsa_context *ctx )
{
int ret;
mbedtls_mpi PQ, DE, P1, Q1, H, I, G, G2, L1, L2, DP, DQ, QP;
if( ( ret = mbedtls_rsa_check_pubkey( ctx ) ) != 0 )
return( ret );
if( !ctx->P.p || !ctx->Q.p || !ctx->D.p )
return( MBEDTLS_ERR_RSA_KEY_CHECK_FAILED );
mbedtls_mpi_init( &PQ ); mbedtls_mpi_init( &DE ); mbedtls_mpi_init( &P1 ); mbedtls_mpi_init( &Q1 );
mbedtls_mpi_init( &H ); mbedtls_mpi_init( &I ); mbedtls_mpi_init( &G ); mbedtls_mpi_init( &G2 );
mbedtls_mpi_init( &L1 ); mbedtls_mpi_init( &L2 ); mbedtls_mpi_init( &DP ); mbedtls_mpi_init( &DQ );
mbedtls_mpi_init( &QP );
MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &PQ, &ctx->P, &ctx->Q ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &DE, &ctx->D, &ctx->E ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &P1, &ctx->P, 1 ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &Q1, &ctx->Q, 1 ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &H, &P1, &Q1 ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_gcd( &G, &ctx->E, &H ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_gcd( &G2, &P1, &Q1 ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_div_mpi( &L1, &L2, &H, &G2 ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &I, &DE, &L1 ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &DP, &ctx->D, &P1 ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &DQ, &ctx->D, &Q1 ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_inv_mod( &QP, &ctx->Q, &ctx->P ) );
/*
* Check for a valid PKCS1v2 private key
*/
if( mbedtls_mpi_cmp_mpi( &PQ, &ctx->N ) != 0 ||
mbedtls_mpi_cmp_mpi( &DP, &ctx->DP ) != 0 ||
mbedtls_mpi_cmp_mpi( &DQ, &ctx->DQ ) != 0 ||
mbedtls_mpi_cmp_mpi( &QP, &ctx->QP ) != 0 ||
mbedtls_mpi_cmp_int( &L2, 0 ) != 0 ||
mbedtls_mpi_cmp_int( &I, 1 ) != 0 ||
mbedtls_mpi_cmp_int( &G, 1 ) != 0 )
{
ret = MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
}
cleanup:
mbedtls_mpi_free( &PQ ); mbedtls_mpi_free( &DE ); mbedtls_mpi_free( &P1 ); mbedtls_mpi_free( &Q1 );
mbedtls_mpi_free( &H ); mbedtls_mpi_free( &I ); mbedtls_mpi_free( &G ); mbedtls_mpi_free( &G2 );
mbedtls_mpi_free( &L1 ); mbedtls_mpi_free( &L2 ); mbedtls_mpi_free( &DP ); mbedtls_mpi_free( &DQ );
mbedtls_mpi_free( &QP );
if( ret == MBEDTLS_ERR_RSA_KEY_CHECK_FAILED )
return( ret );
if( ret != 0 )
return( MBEDTLS_ERR_RSA_KEY_CHECK_FAILED + ret );
return( 0 );
}
/*
* Check if contexts holding a public and private key match
*/
int mbedtls_rsa_check_pub_priv( const mbedtls_rsa_context *pub, const mbedtls_rsa_context *prv )
{
if( mbedtls_rsa_check_pubkey( pub ) != 0 ||
mbedtls_rsa_check_privkey( prv ) != 0 )
{
return( MBEDTLS_ERR_RSA_KEY_CHECK_FAILED );
}
if( mbedtls_mpi_cmp_mpi( &pub->N, &prv->N ) != 0 ||
mbedtls_mpi_cmp_mpi( &pub->E, &prv->E ) != 0 )
{
return( MBEDTLS_ERR_RSA_KEY_CHECK_FAILED );
}
return( 0 );
}
/*
* Do an RSA public key operation
*/
int mbedtls_rsa_public( mbedtls_rsa_context *ctx,
const unsigned char *input,
unsigned char *output )
{
int ret;
size_t olen;
mbedtls_mpi T;
mbedtls_mpi_init( &T );
#if defined(MBEDTLS_THREADING_C)
if( ( ret = mbedtls_mutex_lock( &ctx->mutex ) ) != 0 )
return( ret );
#endif
MBEDTLS_MPI_CHK( mbedtls_mpi_read_binary( &T, input, ctx->len ) );
if( mbedtls_mpi_cmp_mpi( &T, &ctx->N ) >= 0 )
{
ret = MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
goto cleanup;
}
olen = ctx->len;
MBEDTLS_MPI_CHK( mbedtls_mpi_exp_mod( &T, &T, &ctx->E, &ctx->N, &ctx->RN ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_write_binary( &T, output, olen ) );
cleanup:
#if defined(MBEDTLS_THREADING_C)
if( mbedtls_mutex_unlock( &ctx->mutex ) != 0 )
return( MBEDTLS_ERR_THREADING_MUTEX_ERROR );
#endif
mbedtls_mpi_free( &T );
if( ret != 0 )
return( MBEDTLS_ERR_RSA_PUBLIC_FAILED + ret );
return( 0 );
}
/*
* Generate or update blinding values, see section 10 of:
* KOCHER, Paul C. Timing attacks on implementations of Diffie-Hellman, RSA,
* DSS, and other systems. In : Advances in Cryptology-CRYPTO'96. Springer
* Berlin Heidelberg, 1996. p. 104-113.
*/
static int rsa_prepare_blinding( mbedtls_rsa_context *ctx,
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng )
{
int ret, count = 0;
if( ctx->Vf.p != NULL )
{
/* We already have blinding values, just update them by squaring */
MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &ctx->Vi, &ctx->Vi, &ctx->Vi ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &ctx->Vi, &ctx->Vi, &ctx->N ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &ctx->Vf, &ctx->Vf, &ctx->Vf ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &ctx->Vf, &ctx->Vf, &ctx->N ) );
goto cleanup;
}
/* Unblinding value: Vf = random number, invertible mod N */
do {
if( count++ > 10 )
return( MBEDTLS_ERR_RSA_RNG_FAILED );
MBEDTLS_MPI_CHK( mbedtls_mpi_fill_random( &ctx->Vf, ctx->len - 1, f_rng, p_rng ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_gcd( &ctx->Vi, &ctx->Vf, &ctx->N ) );
} while( mbedtls_mpi_cmp_int( &ctx->Vi, 1 ) != 0 );
/* Blinding value: Vi = Vf^(-e) mod N */
MBEDTLS_MPI_CHK( mbedtls_mpi_inv_mod( &ctx->Vi, &ctx->Vf, &ctx->N ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_exp_mod( &ctx->Vi, &ctx->Vi, &ctx->E, &ctx->N, &ctx->RN ) );
cleanup:
return( ret );
}
/*
* Exponent blinding supposed to prevent side-channel attacks using multiple
* traces of measurements to recover the RSA key. The more collisions are there,
* the more bits of the key can be recovered. See [3].
*
* Collecting n collisions with m bit long blinding value requires 2^(m-m/n)
* observations on avarage.
*
* For example with 28 byte blinding to achieve 2 collisions the adversary has
* to make 2^112 observations on avarage.
*
* (With the currently (as of 2017 April) known best algorithms breaking 2048
* bit RSA requires approximately as much time as trying out 2^112 random keys.
* Thus in this sense with 28 byte blinding the security is not reduced by
* side-channel attacks like the one in [3])
*
* This countermeasure does not help if the key recovery is possible with a
* single trace.
*/
#define RSA_EXPONENT_BLINDING 28
/*
* Do an RSA private key operation
*/
int mbedtls_rsa_private( mbedtls_rsa_context *ctx,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng,
const unsigned char *input,
unsigned char *output )
{
int ret;
size_t olen;
mbedtls_mpi T, T1, T2;
mbedtls_mpi P1, Q1, R;
#if defined(MBEDTLS_RSA_NO_CRT)
mbedtls_mpi D_blind;
mbedtls_mpi *D = &ctx->D;
#else
mbedtls_mpi DP_blind, DQ_blind;
mbedtls_mpi *DP = &ctx->DP;
mbedtls_mpi *DQ = &ctx->DQ;
#endif
/* Make sure we have private key info, prevent possible misuse */
if( ctx->P.p == NULL || ctx->Q.p == NULL || ctx->D.p == NULL )
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
mbedtls_mpi_init( &T ); mbedtls_mpi_init( &T1 ); mbedtls_mpi_init( &T2 );
mbedtls_mpi_init( &P1 ); mbedtls_mpi_init( &Q1 ); mbedtls_mpi_init( &R );
if( f_rng != NULL )
{
#if defined(MBEDTLS_RSA_NO_CRT)
mbedtls_mpi_init( &D_blind );
#else
mbedtls_mpi_init( &DP_blind );
mbedtls_mpi_init( &DQ_blind );
#endif
}
#if defined(MBEDTLS_THREADING_C)
if( ( ret = mbedtls_mutex_lock( &ctx->mutex ) ) != 0 )
return( ret );
#endif
MBEDTLS_MPI_CHK( mbedtls_mpi_read_binary( &T, input, ctx->len ) );
if( mbedtls_mpi_cmp_mpi( &T, &ctx->N ) >= 0 )
{
ret = MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
goto cleanup;
}
if( f_rng != NULL )
{
/*
* Blinding
* T = T * Vi mod N
*/
MBEDTLS_MPI_CHK( rsa_prepare_blinding( ctx, f_rng, p_rng ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &T, &T, &ctx->Vi ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &T, &T, &ctx->N ) );
/*
* Exponent blinding
*/
MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &P1, &ctx->P, 1 ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &Q1, &ctx->Q, 1 ) );
#if defined(MBEDTLS_RSA_NO_CRT)
/*
* D_blind = ( P - 1 ) * ( Q - 1 ) * R + D
*/
MBEDTLS_MPI_CHK( mbedtls_mpi_fill_random( &R, RSA_EXPONENT_BLINDING,
f_rng, p_rng ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &D_blind, &P1, &Q1 ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &D_blind, &D_blind, &R ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_add_mpi( &D_blind, &D_blind, &ctx->D ) );
D = &D_blind;
#else
/*
* DP_blind = ( P - 1 ) * R + DP
*/
MBEDTLS_MPI_CHK( mbedtls_mpi_fill_random( &R, RSA_EXPONENT_BLINDING,
f_rng, p_rng ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &DP_blind, &P1, &R ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_add_mpi( &DP_blind, &DP_blind,
&ctx->DP ) );
DP = &DP_blind;
/*
* DQ_blind = ( Q - 1 ) * R + DQ
*/
MBEDTLS_MPI_CHK( mbedtls_mpi_fill_random( &R, RSA_EXPONENT_BLINDING,
f_rng, p_rng ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &DQ_blind, &Q1, &R ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_add_mpi( &DQ_blind, &DQ_blind,
&ctx->DQ ) );
DQ = &DQ_blind;
#endif /* MBEDTLS_RSA_NO_CRT */
}
#if defined(MBEDTLS_RSA_NO_CRT)
MBEDTLS_MPI_CHK( mbedtls_mpi_exp_mod( &T, &T, D, &ctx->N, &ctx->RN ) );
#else
/*
* Faster decryption using the CRT
*
* T1 = input ^ dP mod P
* T2 = input ^ dQ mod Q
*/
MBEDTLS_MPI_CHK( mbedtls_mpi_exp_mod( &T1, &T, DP, &ctx->P, &ctx->RP ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_exp_mod( &T2, &T, DQ, &ctx->Q, &ctx->RQ ) );
/*
* T = (T1 - T2) * (Q^-1 mod P) mod P
*/
MBEDTLS_MPI_CHK( mbedtls_mpi_sub_mpi( &T, &T1, &T2 ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &T1, &T, &ctx->QP ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &T, &T1, &ctx->P ) );
/*
* T = T2 + T * Q
*/
MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &T1, &T, &ctx->Q ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_add_mpi( &T, &T2, &T1 ) );
#endif /* MBEDTLS_RSA_NO_CRT */
if( f_rng != NULL )
{
/*
* Unblind
* T = T * Vf mod N
*/
MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &T, &T, &ctx->Vf ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &T, &T, &ctx->N ) );
}
olen = ctx->len;
MBEDTLS_MPI_CHK( mbedtls_mpi_write_binary( &T, output, olen ) );
cleanup:
#if defined(MBEDTLS_THREADING_C)
if( mbedtls_mutex_unlock( &ctx->mutex ) != 0 )
return( MBEDTLS_ERR_THREADING_MUTEX_ERROR );
#endif
mbedtls_mpi_free( &T ); mbedtls_mpi_free( &T1 ); mbedtls_mpi_free( &T2 );
mbedtls_mpi_free( &P1 ); mbedtls_mpi_free( &Q1 ); mbedtls_mpi_free( &R );
if( f_rng != NULL )
{
#if defined(MBEDTLS_RSA_NO_CRT)
mbedtls_mpi_free( &D_blind );
#else
mbedtls_mpi_free( &DP_blind );
mbedtls_mpi_free( &DQ_blind );
#endif
}
if( ret != 0 )
return( MBEDTLS_ERR_RSA_PRIVATE_FAILED + ret );
return( 0 );
}
#if defined(MBEDTLS_PKCS1_V21)
/**
* Generate and apply the MGF1 operation (from PKCS#1 v2.1) to a buffer.
*
* \param dst buffer to mask
* \param dlen length of destination buffer
* \param src source of the mask generation
* \param slen length of the source buffer
* \param md_ctx message digest context to use
*/
static void mgf_mask( unsigned char *dst, size_t dlen, unsigned char *src,
size_t slen, mbedtls_md_context_t *md_ctx )
{
unsigned char mask[MBEDTLS_MD_MAX_SIZE];
unsigned char counter[4];
unsigned char *p;
unsigned int hlen;
size_t i, use_len;
memset( mask, 0, MBEDTLS_MD_MAX_SIZE );
memset( counter, 0, 4 );
hlen = mbedtls_md_get_size( md_ctx->md_info );
/* Generate and apply dbMask */
p = dst;
while( dlen > 0 )
{
use_len = hlen;
if( dlen < hlen )
use_len = dlen;
mbedtls_md_starts( md_ctx );
mbedtls_md_update( md_ctx, src, slen );
mbedtls_md_update( md_ctx, counter, 4 );
mbedtls_md_finish( md_ctx, mask );
for( i = 0; i < use_len; ++i )
*p++ ^= mask[i];
counter[3]++;
dlen -= use_len;
}
mbedtls_zeroize( mask, sizeof( mask ) );
}
#endif /* MBEDTLS_PKCS1_V21 */
#if defined(MBEDTLS_PKCS1_V21)
/*
* Implementation of the PKCS#1 v2.1 RSAES-OAEP-ENCRYPT function
*/
int mbedtls_rsa_rsaes_oaep_encrypt( mbedtls_rsa_context *ctx,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng,
int mode,
const unsigned char *label, size_t label_len,
size_t ilen,
const unsigned char *input,
unsigned char *output )
{
size_t olen;
int ret;
unsigned char *p = output;
unsigned int hlen;
const mbedtls_md_info_t *md_info;
mbedtls_md_context_t md_ctx;
if( mode == MBEDTLS_RSA_PRIVATE && ctx->padding != MBEDTLS_RSA_PKCS_V21 )
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
if( f_rng == NULL )
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
md_info = mbedtls_md_info_from_type( (mbedtls_md_type_t) ctx->hash_id );
if( md_info == NULL )
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
olen = ctx->len;
hlen = mbedtls_md_get_size( md_info );
/* first comparison checks for overflow */
if( ilen + 2 * hlen + 2 < ilen || olen < ilen + 2 * hlen + 2 )
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
memset( output, 0, olen );
*p++ = 0;
/* Generate a random octet string seed */
if( ( ret = f_rng( p_rng, p, hlen ) ) != 0 )
return( MBEDTLS_ERR_RSA_RNG_FAILED + ret );
p += hlen;
/* Construct DB */
mbedtls_md( md_info, label, label_len, p );
p += hlen;
p += olen - 2 * hlen - 2 - ilen;
*p++ = 1;
memcpy( p, input, ilen );
mbedtls_md_init( &md_ctx );
if( ( ret = mbedtls_md_setup( &md_ctx, md_info, 0 ) ) != 0 )
{
mbedtls_md_free( &md_ctx );
return( ret );
}
/* maskedDB: Apply dbMask to DB */
mgf_mask( output + hlen + 1, olen - hlen - 1, output + 1, hlen,
&md_ctx );
/* maskedSeed: Apply seedMask to seed */
mgf_mask( output + 1, hlen, output + hlen + 1, olen - hlen - 1,
&md_ctx );
mbedtls_md_free( &md_ctx );
return( ( mode == MBEDTLS_RSA_PUBLIC )
? mbedtls_rsa_public( ctx, output, output )
: mbedtls_rsa_private( ctx, f_rng, p_rng, output, output ) );
}
#endif /* MBEDTLS_PKCS1_V21 */
#if defined(MBEDTLS_PKCS1_V15)
/*
* Implementation of the PKCS#1 v2.1 RSAES-PKCS1-V1_5-ENCRYPT function
*/
int mbedtls_rsa_rsaes_pkcs1_v15_encrypt( mbedtls_rsa_context *ctx,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng,
int mode, size_t ilen,
const unsigned char *input,
unsigned char *output )
{
size_t nb_pad, olen;
int ret;
unsigned char *p = output;
if( mode == MBEDTLS_RSA_PRIVATE && ctx->padding != MBEDTLS_RSA_PKCS_V15 )
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
// We don't check p_rng because it won't be dereferenced here
if( f_rng == NULL || input == NULL || output == NULL )
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
olen = ctx->len;
/* first comparison checks for overflow */
if( ilen + 11 < ilen || olen < ilen + 11 )
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
nb_pad = olen - 3 - ilen;
*p++ = 0;
if( mode == MBEDTLS_RSA_PUBLIC )
{
*p++ = MBEDTLS_RSA_CRYPT;
while( nb_pad-- > 0 )
{
int rng_dl = 100;
do {
ret = f_rng( p_rng, p, 1 );
} while( *p == 0 && --rng_dl && ret == 0 );
/* Check if RNG failed to generate data */
if( rng_dl == 0 || ret != 0 )
return( MBEDTLS_ERR_RSA_RNG_FAILED + ret );
p++;
}
}
else
{
*p++ = MBEDTLS_RSA_SIGN;
while( nb_pad-- > 0 )
*p++ = 0xFF;
}
*p++ = 0;
memcpy( p, input, ilen );
return( ( mode == MBEDTLS_RSA_PUBLIC )
? mbedtls_rsa_public( ctx, output, output )
: mbedtls_rsa_private( ctx, f_rng, p_rng, output, output ) );
}
#endif /* MBEDTLS_PKCS1_V15 */
/*
* Add the message padding, then do an RSA operation
*/
int mbedtls_rsa_pkcs1_encrypt( mbedtls_rsa_context *ctx,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng,
int mode, size_t ilen,
const unsigned char *input,
unsigned char *output )
{
switch( ctx->padding )
{
#if defined(MBEDTLS_PKCS1_V15)
case MBEDTLS_RSA_PKCS_V15:
return mbedtls_rsa_rsaes_pkcs1_v15_encrypt( ctx, f_rng, p_rng, mode, ilen,
input, output );
#endif
#if defined(MBEDTLS_PKCS1_V21)
case MBEDTLS_RSA_PKCS_V21:
return mbedtls_rsa_rsaes_oaep_encrypt( ctx, f_rng, p_rng, mode, NULL, 0,
ilen, input, output );
#endif
default:
return( MBEDTLS_ERR_RSA_INVALID_PADDING );
}
}
#if defined(MBEDTLS_PKCS1_V21)
/*
* Implementation of the PKCS#1 v2.1 RSAES-OAEP-DECRYPT function
*/
int mbedtls_rsa_rsaes_oaep_decrypt( mbedtls_rsa_context *ctx,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng,
int mode,
const unsigned char *label, size_t label_len,
size_t *olen,
const unsigned char *input,
unsigned char *output,
size_t output_max_len )
{
int ret;
size_t ilen, i, pad_len;
unsigned char *p, bad, pad_done;
unsigned char buf[MBEDTLS_MPI_MAX_SIZE];
unsigned char lhash[MBEDTLS_MD_MAX_SIZE];
unsigned int hlen;
const mbedtls_md_info_t *md_info;
mbedtls_md_context_t md_ctx;
/*
* Parameters sanity checks
*/
if( mode == MBEDTLS_RSA_PRIVATE && ctx->padding != MBEDTLS_RSA_PKCS_V21 )
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
ilen = ctx->len;
if( ilen < 16 || ilen > sizeof( buf ) )
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
md_info = mbedtls_md_info_from_type( (mbedtls_md_type_t) ctx->hash_id );
if( md_info == NULL )
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
hlen = mbedtls_md_get_size( md_info );
// checking for integer underflow
if( 2 * hlen + 2 > ilen )
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
/*
* RSA operation
*/
ret = ( mode == MBEDTLS_RSA_PUBLIC )
? mbedtls_rsa_public( ctx, input, buf )
: mbedtls_rsa_private( ctx, f_rng, p_rng, input, buf );
if( ret != 0 )
goto cleanup;
/*
* Unmask data and generate lHash
*/
mbedtls_md_init( &md_ctx );
if( ( ret = mbedtls_md_setup( &md_ctx, md_info, 0 ) ) != 0 )
{
mbedtls_md_free( &md_ctx );
goto cleanup;
}
/* Generate lHash */
mbedtls_md( md_info, label, label_len, lhash );
/* seed: Apply seedMask to maskedSeed */
mgf_mask( buf + 1, hlen, buf + hlen + 1, ilen - hlen - 1,
&md_ctx );
/* DB: Apply dbMask to maskedDB */
mgf_mask( buf + hlen + 1, ilen - hlen - 1, buf + 1, hlen,
&md_ctx );
mbedtls_md_free( &md_ctx );
/*
* Check contents, in "constant-time"
*/
p = buf;
bad = 0;
bad |= *p++; /* First byte must be 0 */
p += hlen; /* Skip seed */
/* Check lHash */
for( i = 0; i < hlen; i++ )
bad |= lhash[i] ^ *p++;
/* Get zero-padding len, but always read till end of buffer
* (minus one, for the 01 byte) */
pad_len = 0;
pad_done = 0;
for( i = 0; i < ilen - 2 * hlen - 2; i++ )
{
pad_done |= p[i];
pad_len += ((pad_done | (unsigned char)-pad_done) >> 7) ^ 1;
}
p += pad_len;
bad |= *p++ ^ 0x01;
/*
* The only information "leaked" is whether the padding was correct or not
* (eg, no data is copied if it was not correct). This meets the
* recommendations in PKCS#1 v2.2: an opponent cannot distinguish between
* the different error conditions.
*/
if( bad != 0 )
{
ret = MBEDTLS_ERR_RSA_INVALID_PADDING;
goto cleanup;
}
if( ilen - ( p - buf ) > output_max_len )
{
ret = MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE;
goto cleanup;
}
*olen = ilen - (p - buf);
memcpy( output, p, *olen );
ret = 0;
cleanup:
mbedtls_zeroize( buf, sizeof( buf ) );
mbedtls_zeroize( lhash, sizeof( lhash ) );
return( ret );
}
#endif /* MBEDTLS_PKCS1_V21 */
#if defined(MBEDTLS_PKCS1_V15)
/*
* Implementation of the PKCS#1 v2.1 RSAES-PKCS1-V1_5-DECRYPT function
*/
int mbedtls_rsa_rsaes_pkcs1_v15_decrypt( mbedtls_rsa_context *ctx,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng,
int mode, size_t *olen,
const unsigned char *input,
unsigned char *output,
size_t output_max_len)
{
int ret;
size_t ilen, pad_count = 0, i;
unsigned char *p, bad, pad_done = 0;
unsigned char buf[MBEDTLS_MPI_MAX_SIZE];
if( mode == MBEDTLS_RSA_PRIVATE && ctx->padding != MBEDTLS_RSA_PKCS_V15 )
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
ilen = ctx->len;
if( ilen < 16 || ilen > sizeof( buf ) )
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
ret = ( mode == MBEDTLS_RSA_PUBLIC )
? mbedtls_rsa_public( ctx, input, buf )
: mbedtls_rsa_private( ctx, f_rng, p_rng, input, buf );
if( ret != 0 )
goto cleanup;
p = buf;
bad = 0;
/*
* Check and get padding len in "constant-time"
*/
bad |= *p++; /* First byte must be 0 */
/* This test does not depend on secret data */
if( mode == MBEDTLS_RSA_PRIVATE )
{
bad |= *p++ ^ MBEDTLS_RSA_CRYPT;
/* Get padding len, but always read till end of buffer
* (minus one, for the 00 byte) */
for( i = 0; i < ilen - 3; i++ )
{
pad_done |= ((p[i] | (unsigned char)-p[i]) >> 7) ^ 1;
pad_count += ((pad_done | (unsigned char)-pad_done) >> 7) ^ 1;
}
p += pad_count;
bad |= *p++; /* Must be zero */
}
else
{
bad |= *p++ ^ MBEDTLS_RSA_SIGN;
/* Get padding len, but always read till end of buffer
* (minus one, for the 00 byte) */
for( i = 0; i < ilen - 3; i++ )
{
pad_done |= ( p[i] != 0xFF );
pad_count += ( pad_done == 0 );
}
p += pad_count;
bad |= *p++; /* Must be zero */
}
bad |= ( pad_count < 8 );
if( bad )
{
ret = MBEDTLS_ERR_RSA_INVALID_PADDING;
goto cleanup;
}
if( ilen - ( p - buf ) > output_max_len )
{
ret = MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE;
goto cleanup;
}
*olen = ilen - (p - buf);
memcpy( output, p, *olen );
ret = 0;
cleanup:
mbedtls_zeroize( buf, sizeof( buf ) );
return( ret );
}
#endif /* MBEDTLS_PKCS1_V15 */
/*
* Do an RSA operation, then remove the message padding
*/
int mbedtls_rsa_pkcs1_decrypt( mbedtls_rsa_context *ctx,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng,
int mode, size_t *olen,
const unsigned char *input,
unsigned char *output,
size_t output_max_len)
{
switch( ctx->padding )
{
#if defined(MBEDTLS_PKCS1_V15)
case MBEDTLS_RSA_PKCS_V15:
return mbedtls_rsa_rsaes_pkcs1_v15_decrypt( ctx, f_rng, p_rng, mode, olen,
input, output, output_max_len );
#endif
#if defined(MBEDTLS_PKCS1_V21)
case MBEDTLS_RSA_PKCS_V21:
return mbedtls_rsa_rsaes_oaep_decrypt( ctx, f_rng, p_rng, mode, NULL, 0,
olen, input, output,
output_max_len );
#endif
default:
return( MBEDTLS_ERR_RSA_INVALID_PADDING );
}
}
#if defined(MBEDTLS_PKCS1_V21)
/*
* Implementation of the PKCS#1 v2.1 RSASSA-PSS-SIGN function
*/
int mbedtls_rsa_rsassa_pss_sign( mbedtls_rsa_context *ctx,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng,
int mode,
mbedtls_md_type_t md_alg,
unsigned int hashlen,
const unsigned char *hash,
unsigned char *sig )
{
size_t olen;
unsigned char *p = sig;
unsigned char salt[MBEDTLS_MD_MAX_SIZE];
unsigned int slen, hlen, offset = 0;
int ret;
size_t msb;
const mbedtls_md_info_t *md_info;
mbedtls_md_context_t md_ctx;
if( mode == MBEDTLS_RSA_PRIVATE && ctx->padding != MBEDTLS_RSA_PKCS_V21 )
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
if( f_rng == NULL )
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
olen = ctx->len;
if( md_alg != MBEDTLS_MD_NONE )
{
/* Gather length of hash to sign */
md_info = mbedtls_md_info_from_type( md_alg );
if( md_info == NULL )
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
hashlen = mbedtls_md_get_size( md_info );
}
md_info = mbedtls_md_info_from_type( (mbedtls_md_type_t) ctx->hash_id );
if( md_info == NULL )
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
hlen = mbedtls_md_get_size( md_info );
slen = hlen;
if( olen < hlen + slen + 2 )
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
memset( sig, 0, olen );
/* Generate salt of length slen */
if( ( ret = f_rng( p_rng, salt, slen ) ) != 0 )
return( MBEDTLS_ERR_RSA_RNG_FAILED + ret );
/* Note: EMSA-PSS encoding is over the length of N - 1 bits */
msb = mbedtls_mpi_bitlen( &ctx->N ) - 1;
p += olen - hlen * 2 - 2;
*p++ = 0x01;
memcpy( p, salt, slen );
p += slen;
mbedtls_md_init( &md_ctx );
if( ( ret = mbedtls_md_setup( &md_ctx, md_info, 0 ) ) != 0 )
{
mbedtls_md_free( &md_ctx );
/* No need to zeroize salt: we didn't use it. */
return( ret );
}
/* Generate H = Hash( M' ) */
mbedtls_md_starts( &md_ctx );
mbedtls_md_update( &md_ctx, p, 8 );
mbedtls_md_update( &md_ctx, hash, hashlen );
mbedtls_md_update( &md_ctx, salt, slen );
mbedtls_md_finish( &md_ctx, p );
mbedtls_zeroize( salt, sizeof( salt ) );
/* Compensate for boundary condition when applying mask */
if( msb % 8 == 0 )
offset = 1;
/* maskedDB: Apply dbMask to DB */
mgf_mask( sig + offset, olen - hlen - 1 - offset, p, hlen, &md_ctx );
mbedtls_md_free( &md_ctx );
msb = mbedtls_mpi_bitlen( &ctx->N ) - 1;
sig[0] &= 0xFF >> ( olen * 8 - msb );
p += hlen;
*p++ = 0xBC;
return( ( mode == MBEDTLS_RSA_PUBLIC )
? mbedtls_rsa_public( ctx, sig, sig )
: mbedtls_rsa_private( ctx, f_rng, p_rng, sig, sig ) );
}
#endif /* MBEDTLS_PKCS1_V21 */
#if defined(MBEDTLS_PKCS1_V15)
/*
* Implementation of the PKCS#1 v2.1 RSASSA-PKCS1-V1_5-SIGN function
*/
/*
* Do an RSA operation to sign the message digest
*/
int mbedtls_rsa_rsassa_pkcs1_v15_sign( mbedtls_rsa_context *ctx,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng,
int mode,
mbedtls_md_type_t md_alg,
unsigned int hashlen,
const unsigned char *hash,
unsigned char *sig )
{
size_t nb_pad, olen, oid_size = 0;
unsigned char *p = sig;
const char *oid = NULL;
unsigned char *sig_try = NULL, *verif = NULL;
size_t i;
unsigned char diff;
volatile unsigned char diff_no_optimize;
int ret;
if( mode == MBEDTLS_RSA_PRIVATE && ctx->padding != MBEDTLS_RSA_PKCS_V15 )
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
olen = ctx->len;
nb_pad = olen - 3;
if( md_alg != MBEDTLS_MD_NONE )
{
const mbedtls_md_info_t *md_info = mbedtls_md_info_from_type( md_alg );
if( md_info == NULL )
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
if( mbedtls_oid_get_oid_by_md( md_alg, &oid, &oid_size ) != 0 )
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
nb_pad -= 10 + oid_size;
hashlen = mbedtls_md_get_size( md_info );
}
nb_pad -= hashlen;
if( ( nb_pad < 8 ) || ( nb_pad > olen ) )
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
*p++ = 0;
*p++ = MBEDTLS_RSA_SIGN;
memset( p, 0xFF, nb_pad );
p += nb_pad;
*p++ = 0;
if( md_alg == MBEDTLS_MD_NONE )
{
memcpy( p, hash, hashlen );
}
else
{
/*
* DigestInfo ::= SEQUENCE {
* digestAlgorithm DigestAlgorithmIdentifier,
* digest Digest }
*
* DigestAlgorithmIdentifier ::= AlgorithmIdentifier
*
* Digest ::= OCTET STRING
*/
*p++ = MBEDTLS_ASN1_SEQUENCE | MBEDTLS_ASN1_CONSTRUCTED;
*p++ = (unsigned char) ( 0x08 + oid_size + hashlen );
*p++ = MBEDTLS_ASN1_SEQUENCE | MBEDTLS_ASN1_CONSTRUCTED;
*p++ = (unsigned char) ( 0x04 + oid_size );
*p++ = MBEDTLS_ASN1_OID;
*p++ = oid_size & 0xFF;
memcpy( p, oid, oid_size );
p += oid_size;
*p++ = MBEDTLS_ASN1_NULL;
*p++ = 0x00;
*p++ = MBEDTLS_ASN1_OCTET_STRING;
*p++ = hashlen;
memcpy( p, hash, hashlen );
}
if( mode == MBEDTLS_RSA_PUBLIC )
return( mbedtls_rsa_public( ctx, sig, sig ) );
/*
* In order to prevent Lenstra's attack, make the signature in a
* temporary buffer and check it before returning it.
*/
sig_try = mbedtls_calloc( 1, ctx->len );
if( sig_try == NULL )
return( MBEDTLS_ERR_MPI_ALLOC_FAILED );
verif = mbedtls_calloc( 1, ctx->len );
if( verif == NULL )
{
mbedtls_free( sig_try );
return( MBEDTLS_ERR_MPI_ALLOC_FAILED );
}
MBEDTLS_MPI_CHK( mbedtls_rsa_private( ctx, f_rng, p_rng, sig, sig_try ) );
MBEDTLS_MPI_CHK( mbedtls_rsa_public( ctx, sig_try, verif ) );
/* Compare in constant time just in case */
for( diff = 0, i = 0; i < ctx->len; i++ )
diff |= verif[i] ^ sig[i];
diff_no_optimize = diff;
if( diff_no_optimize != 0 )
{
ret = MBEDTLS_ERR_RSA_PRIVATE_FAILED;
goto cleanup;
}
memcpy( sig, sig_try, ctx->len );
cleanup:
mbedtls_free( sig_try );
mbedtls_free( verif );
return( ret );
}
#endif /* MBEDTLS_PKCS1_V15 */
/*
* Do an RSA operation to sign the message digest
*/
int mbedtls_rsa_pkcs1_sign( mbedtls_rsa_context *ctx,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng,
int mode,
mbedtls_md_type_t md_alg,
unsigned int hashlen,
const unsigned char *hash,
unsigned char *sig )
{
switch( ctx->padding )
{
#if defined(MBEDTLS_PKCS1_V15)
case MBEDTLS_RSA_PKCS_V15:
return mbedtls_rsa_rsassa_pkcs1_v15_sign( ctx, f_rng, p_rng, mode, md_alg,
hashlen, hash, sig );
#endif
#if defined(MBEDTLS_PKCS1_V21)
case MBEDTLS_RSA_PKCS_V21:
return mbedtls_rsa_rsassa_pss_sign( ctx, f_rng, p_rng, mode, md_alg,
hashlen, hash, sig );
#endif
default:
return( MBEDTLS_ERR_RSA_INVALID_PADDING );
}
}
#if defined(MBEDTLS_PKCS1_V21)
/*
* Implementation of the PKCS#1 v2.1 RSASSA-PSS-VERIFY function
*/
int mbedtls_rsa_rsassa_pss_verify_ext( mbedtls_rsa_context *ctx,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng,
int mode,
mbedtls_md_type_t md_alg,
unsigned int hashlen,
const unsigned char *hash,
mbedtls_md_type_t mgf1_hash_id,
int expected_salt_len,
const unsigned char *sig )
{
int ret;
size_t siglen;
unsigned char *p;
unsigned char result[MBEDTLS_MD_MAX_SIZE];
unsigned char zeros[8];
unsigned int hlen;
size_t slen, msb;
const mbedtls_md_info_t *md_info;
mbedtls_md_context_t md_ctx;
unsigned char buf[MBEDTLS_MPI_MAX_SIZE];
if( mode == MBEDTLS_RSA_PRIVATE && ctx->padding != MBEDTLS_RSA_PKCS_V21 )
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
siglen = ctx->len;
if( siglen < 16 || siglen > sizeof( buf ) )
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
ret = ( mode == MBEDTLS_RSA_PUBLIC )
? mbedtls_rsa_public( ctx, sig, buf )
: mbedtls_rsa_private( ctx, f_rng, p_rng, sig, buf );
if( ret != 0 )
return( ret );
p = buf;
if( buf[siglen - 1] != 0xBC )
return( MBEDTLS_ERR_RSA_INVALID_PADDING );
if( md_alg != MBEDTLS_MD_NONE )
{
/* Gather length of hash to sign */
md_info = mbedtls_md_info_from_type( md_alg );
if( md_info == NULL )
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
hashlen = mbedtls_md_get_size( md_info );
}
md_info = mbedtls_md_info_from_type( mgf1_hash_id );
if( md_info == NULL )
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
hlen = mbedtls_md_get_size( md_info );
slen = siglen - hlen - 1; /* Currently length of salt + padding */
memset( zeros, 0, 8 );
/*
* Note: EMSA-PSS verification is over the length of N - 1 bits
*/
msb = mbedtls_mpi_bitlen( &ctx->N ) - 1;
/* Compensate for boundary condition when applying mask */
if( msb % 8 == 0 )
{
p++;
siglen -= 1;
}
if( buf[0] >> ( 8 - siglen * 8 + msb ) )
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
mbedtls_md_init( &md_ctx );
if( ( ret = mbedtls_md_setup( &md_ctx, md_info, 0 ) ) != 0 )
{
mbedtls_md_free( &md_ctx );
return( ret );
}
mgf_mask( p, siglen - hlen - 1, p + siglen - hlen - 1, hlen, &md_ctx );
buf[0] &= 0xFF >> ( siglen * 8 - msb );
while( p < buf + siglen && *p == 0 )
p++;
if( p == buf + siglen ||
*p++ != 0x01 )
{
mbedtls_md_free( &md_ctx );
return( MBEDTLS_ERR_RSA_INVALID_PADDING );
}
/* Actual salt len */
slen -= p - buf;
if( expected_salt_len != MBEDTLS_RSA_SALT_LEN_ANY &&
slen != (size_t) expected_salt_len )
{
mbedtls_md_free( &md_ctx );
return( MBEDTLS_ERR_RSA_INVALID_PADDING );
}
/*
* Generate H = Hash( M' )
*/
mbedtls_md_starts( &md_ctx );
mbedtls_md_update( &md_ctx, zeros, 8 );
mbedtls_md_update( &md_ctx, hash, hashlen );
mbedtls_md_update( &md_ctx, p, slen );
mbedtls_md_finish( &md_ctx, result );
mbedtls_md_free( &md_ctx );
if( memcmp( p + slen, result, hlen ) == 0 )
return( 0 );
else
return( MBEDTLS_ERR_RSA_VERIFY_FAILED );
}
/*
* Simplified PKCS#1 v2.1 RSASSA-PSS-VERIFY function
*/
int mbedtls_rsa_rsassa_pss_verify( mbedtls_rsa_context *ctx,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng,
int mode,
mbedtls_md_type_t md_alg,
unsigned int hashlen,
const unsigned char *hash,
const unsigned char *sig )
{
mbedtls_md_type_t mgf1_hash_id = ( ctx->hash_id != MBEDTLS_MD_NONE )
? (mbedtls_md_type_t) ctx->hash_id
: md_alg;
return( mbedtls_rsa_rsassa_pss_verify_ext( ctx, f_rng, p_rng, mode,
md_alg, hashlen, hash,
mgf1_hash_id, MBEDTLS_RSA_SALT_LEN_ANY,
sig ) );
}
#endif /* MBEDTLS_PKCS1_V21 */
#if defined(MBEDTLS_PKCS1_V15)
/*
* Implementation of the PKCS#1 v2.1 RSASSA-PKCS1-v1_5-VERIFY function
*/
int mbedtls_rsa_rsassa_pkcs1_v15_verify( mbedtls_rsa_context *ctx,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng,
int mode,
mbedtls_md_type_t md_alg,
unsigned int hashlen,
const unsigned char *hash,
const unsigned char *sig )
{
int ret;
size_t len, siglen, asn1_len;
unsigned char *p, *end;
mbedtls_md_type_t msg_md_alg;
const mbedtls_md_info_t *md_info;
mbedtls_asn1_buf oid;
unsigned char buf[MBEDTLS_MPI_MAX_SIZE];
if( mode == MBEDTLS_RSA_PRIVATE && ctx->padding != MBEDTLS_RSA_PKCS_V15 )
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
siglen = ctx->len;
if( siglen < 16 || siglen > sizeof( buf ) )
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
ret = ( mode == MBEDTLS_RSA_PUBLIC )
? mbedtls_rsa_public( ctx, sig, buf )
: mbedtls_rsa_private( ctx, f_rng, p_rng, sig, buf );
if( ret != 0 )
return( ret );
p = buf;
if( *p++ != 0 || *p++ != MBEDTLS_RSA_SIGN )
return( MBEDTLS_ERR_RSA_INVALID_PADDING );
while( *p != 0 )
{
if( p >= buf + siglen - 1 || *p != 0xFF )
return( MBEDTLS_ERR_RSA_INVALID_PADDING );
p++;
}
p++;
len = siglen - ( p - buf );
if( len == hashlen && md_alg == MBEDTLS_MD_NONE )
{
if( memcmp( p, hash, hashlen ) == 0 )
return( 0 );
else
return( MBEDTLS_ERR_RSA_VERIFY_FAILED );
}
md_info = mbedtls_md_info_from_type( md_alg );
if( md_info == NULL )
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
hashlen = mbedtls_md_get_size( md_info );
end = p + len;
/*
* Parse the ASN.1 structure inside the PKCS#1 v1.5 structure
*/
if( ( ret = mbedtls_asn1_get_tag( &p, end, &asn1_len,
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
return( MBEDTLS_ERR_RSA_VERIFY_FAILED );
if( asn1_len + 2 != len )
return( MBEDTLS_ERR_RSA_VERIFY_FAILED );
if( ( ret = mbedtls_asn1_get_tag( &p, end, &asn1_len,
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
return( MBEDTLS_ERR_RSA_VERIFY_FAILED );
if( asn1_len + 6 + hashlen != len )
return( MBEDTLS_ERR_RSA_VERIFY_FAILED );
if( ( ret = mbedtls_asn1_get_tag( &p, end, &oid.len, MBEDTLS_ASN1_OID ) ) != 0 )
return( MBEDTLS_ERR_RSA_VERIFY_FAILED );
oid.p = p;
p += oid.len;
if( mbedtls_oid_get_md_alg( &oid, &msg_md_alg ) != 0 )
return( MBEDTLS_ERR_RSA_VERIFY_FAILED );
if( md_alg != msg_md_alg )
return( MBEDTLS_ERR_RSA_VERIFY_FAILED );
/*
* assume the algorithm parameters must be NULL
*/
if( ( ret = mbedtls_asn1_get_tag( &p, end, &asn1_len, MBEDTLS_ASN1_NULL ) ) != 0 )
return( MBEDTLS_ERR_RSA_VERIFY_FAILED );
if( ( ret = mbedtls_asn1_get_tag( &p, end, &asn1_len, MBEDTLS_ASN1_OCTET_STRING ) ) != 0 )
return( MBEDTLS_ERR_RSA_VERIFY_FAILED );
if( asn1_len != hashlen )
return( MBEDTLS_ERR_RSA_VERIFY_FAILED );
if( memcmp( p, hash, hashlen ) != 0 )
return( MBEDTLS_ERR_RSA_VERIFY_FAILED );
p += hashlen;
if( p != end )
return( MBEDTLS_ERR_RSA_VERIFY_FAILED );
return( 0 );
}
#endif /* MBEDTLS_PKCS1_V15 */
/*
* Do an RSA operation and check the message digest
*/
int mbedtls_rsa_pkcs1_verify( mbedtls_rsa_context *ctx,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng,
int mode,
mbedtls_md_type_t md_alg,
unsigned int hashlen,
const unsigned char *hash,
const unsigned char *sig )
{
switch( ctx->padding )
{
#if defined(MBEDTLS_PKCS1_V15)
case MBEDTLS_RSA_PKCS_V15:
return mbedtls_rsa_rsassa_pkcs1_v15_verify( ctx, f_rng, p_rng, mode, md_alg,
hashlen, hash, sig );
#endif
#if defined(MBEDTLS_PKCS1_V21)
case MBEDTLS_RSA_PKCS_V21:
return mbedtls_rsa_rsassa_pss_verify( ctx, f_rng, p_rng, mode, md_alg,
hashlen, hash, sig );
#endif
default:
return( MBEDTLS_ERR_RSA_INVALID_PADDING );
}
}
/*
* Copy the components of an RSA key
*/
int mbedtls_rsa_copy( mbedtls_rsa_context *dst, const mbedtls_rsa_context *src )
{
int ret;
dst->ver = src->ver;
dst->len = src->len;
MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &dst->N, &src->N ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &dst->E, &src->E ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &dst->D, &src->D ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &dst->P, &src->P ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &dst->Q, &src->Q ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &dst->DP, &src->DP ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &dst->DQ, &src->DQ ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &dst->QP, &src->QP ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &dst->RN, &src->RN ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &dst->RP, &src->RP ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &dst->RQ, &src->RQ ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &dst->Vi, &src->Vi ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &dst->Vf, &src->Vf ) );
dst->padding = src->padding;
dst->hash_id = src->hash_id;
cleanup:
if( ret != 0 )
mbedtls_rsa_free( dst );
return( ret );
}
/*
* Free the components of an RSA key
*/
void mbedtls_rsa_free( mbedtls_rsa_context *ctx )
{
mbedtls_mpi_free( &ctx->Vi ); mbedtls_mpi_free( &ctx->Vf );
mbedtls_mpi_free( &ctx->RQ ); mbedtls_mpi_free( &ctx->RP ); mbedtls_mpi_free( &ctx->RN );
mbedtls_mpi_free( &ctx->QP ); mbedtls_mpi_free( &ctx->DQ ); mbedtls_mpi_free( &ctx->DP );
mbedtls_mpi_free( &ctx->Q ); mbedtls_mpi_free( &ctx->P ); mbedtls_mpi_free( &ctx->D );
mbedtls_mpi_free( &ctx->E ); mbedtls_mpi_free( &ctx->N );
#if defined(MBEDTLS_THREADING_C)
mbedtls_mutex_free( &ctx->mutex );
#endif
}
#if defined(MBEDTLS_SELF_TEST)
#include "mbedtls/sha1.h"
/*
* Example RSA-1024 keypair, for test purposes
*/
#define KEY_LEN 128
#define RSA_N "9292758453063D803DD603D5E777D788" \
"8ED1D5BF35786190FA2F23EBC0848AEA" \
"DDA92CA6C3D80B32C4D109BE0F36D6AE" \
"7130B9CED7ACDF54CFC7555AC14EEBAB" \
"93A89813FBF3C4F8066D2D800F7C38A8" \
"1AE31942917403FF4946B0A83D3D3E05" \
"EE57C6F5F5606FB5D4BC6CD34EE0801A" \
"5E94BB77B07507233A0BC7BAC8F90F79"
#define RSA_E "10001"
#define RSA_D "24BF6185468786FDD303083D25E64EFC" \
"66CA472BC44D253102F8B4A9D3BFA750" \
"91386C0077937FE33FA3252D28855837" \
"AE1B484A8A9A45F7EE8C0C634F99E8CD" \
"DF79C5CE07EE72C7F123142198164234" \
"CABB724CF78B8173B9F880FC86322407" \
"AF1FEDFDDE2BEB674CA15F3E81A1521E" \
"071513A1E85B5DFA031F21ECAE91A34D"
#define RSA_P "C36D0EB7FCD285223CFB5AABA5BDA3D8" \
"2C01CAD19EA484A87EA4377637E75500" \
"FCB2005C5C7DD6EC4AC023CDA285D796" \
"C3D9E75E1EFC42488BB4F1D13AC30A57"
#define RSA_Q "C000DF51A7C77AE8D7C7370C1FF55B69" \
"E211C2B9E5DB1ED0BF61D0D9899620F4" \
"910E4168387E3C30AA1E00C339A79508" \
"8452DD96A9A5EA5D9DCA68DA636032AF"
#define RSA_DP "C1ACF567564274FB07A0BBAD5D26E298" \
"3C94D22288ACD763FD8E5600ED4A702D" \
"F84198A5F06C2E72236AE490C93F07F8" \
"3CC559CD27BC2D1CA488811730BB5725"
#define RSA_DQ "4959CBF6F8FEF750AEE6977C155579C7" \
"D8AAEA56749EA28623272E4F7D0592AF" \
"7C1F1313CAC9471B5C523BFE592F517B" \
"407A1BD76C164B93DA2D32A383E58357"
#define RSA_QP "9AE7FBC99546432DF71896FC239EADAE" \
"F38D18D2B2F0E2DD275AA977E2BF4411" \
"F5A3B2A5D33605AEBBCCBA7FEB9F2D2F" \
"A74206CEC169D74BF5A8C50D6F48EA08"
#define PT_LEN 24
#define RSA_PT "\xAA\xBB\xCC\x03\x02\x01\x00\xFF\xFF\xFF\xFF\xFF" \
"\x11\x22\x33\x0A\x0B\x0C\xCC\xDD\xDD\xDD\xDD\xDD"
#if defined(MBEDTLS_PKCS1_V15)
static int myrand( void *rng_state, unsigned char *output, size_t len )
{
#if !defined(__OpenBSD__)
size_t i;
if( rng_state != NULL )
rng_state = NULL;
for( i = 0; i < len; ++i )
output[i] = rand();
#else
if( rng_state != NULL )
rng_state = NULL;
arc4random_buf( output, len );
#endif /* !OpenBSD */
return( 0 );
}
#endif /* MBEDTLS_PKCS1_V15 */
/*
* Checkup routine
*/
int mbedtls_rsa_self_test( int verbose )
{
int ret = 0;
#if defined(MBEDTLS_PKCS1_V15)
size_t len;
mbedtls_rsa_context rsa;
unsigned char rsa_plaintext[PT_LEN];
unsigned char rsa_decrypted[PT_LEN];
unsigned char rsa_ciphertext[KEY_LEN];
#if defined(MBEDTLS_SHA1_C)
unsigned char sha1sum[20];
#endif
mbedtls_rsa_init( &rsa, MBEDTLS_RSA_PKCS_V15, 0 );
rsa.len = KEY_LEN;
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &rsa.N , 16, RSA_N ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &rsa.E , 16, RSA_E ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &rsa.D , 16, RSA_D ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &rsa.P , 16, RSA_P ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &rsa.Q , 16, RSA_Q ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &rsa.DP, 16, RSA_DP ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &rsa.DQ, 16, RSA_DQ ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &rsa.QP, 16, RSA_QP ) );
if( verbose != 0 )
mbedtls_printf( " RSA key validation: " );
if( mbedtls_rsa_check_pubkey( &rsa ) != 0 ||
mbedtls_rsa_check_privkey( &rsa ) != 0 )
{
if( verbose != 0 )
mbedtls_printf( "failed\n" );
return( 1 );
}
if( verbose != 0 )
mbedtls_printf( "passed\n PKCS#1 encryption : " );
memcpy( rsa_plaintext, RSA_PT, PT_LEN );
if( mbedtls_rsa_pkcs1_encrypt( &rsa, myrand, NULL, MBEDTLS_RSA_PUBLIC, PT_LEN,
rsa_plaintext, rsa_ciphertext ) != 0 )
{
if( verbose != 0 )
mbedtls_printf( "failed\n" );
return( 1 );
}
if( verbose != 0 )
mbedtls_printf( "passed\n PKCS#1 decryption : " );
if( mbedtls_rsa_pkcs1_decrypt( &rsa, myrand, NULL, MBEDTLS_RSA_PRIVATE, &len,
rsa_ciphertext, rsa_decrypted,
sizeof(rsa_decrypted) ) != 0 )
{
if( verbose != 0 )
mbedtls_printf( "failed\n" );
return( 1 );
}
if( memcmp( rsa_decrypted, rsa_plaintext, len ) != 0 )
{
if( verbose != 0 )
mbedtls_printf( "failed\n" );
return( 1 );
}
if( verbose != 0 )
mbedtls_printf( "passed\n" );
#if defined(MBEDTLS_SHA1_C)
if( verbose != 0 )
mbedtls_printf( " PKCS#1 data sign : " );
mbedtls_sha1( rsa_plaintext, PT_LEN, sha1sum );
if( mbedtls_rsa_pkcs1_sign( &rsa, myrand, NULL, MBEDTLS_RSA_PRIVATE, MBEDTLS_MD_SHA1, 0,
sha1sum, rsa_ciphertext ) != 0 )
{
if( verbose != 0 )
mbedtls_printf( "failed\n" );
return( 1 );
}
if( verbose != 0 )
mbedtls_printf( "passed\n PKCS#1 sig. verify: " );
if( mbedtls_rsa_pkcs1_verify( &rsa, NULL, NULL, MBEDTLS_RSA_PUBLIC, MBEDTLS_MD_SHA1, 0,
sha1sum, rsa_ciphertext ) != 0 )
{
if( verbose != 0 )
mbedtls_printf( "failed\n" );
return( 1 );
}
if( verbose != 0 )
mbedtls_printf( "passed\n" );
#endif /* MBEDTLS_SHA1_C */
if( verbose != 0 )
mbedtls_printf( "\n" );
cleanup:
mbedtls_rsa_free( &rsa );
#else /* MBEDTLS_PKCS1_V15 */
((void) verbose);
#endif /* MBEDTLS_PKCS1_V15 */
return( ret );
}
#endif /* MBEDTLS_SELF_TEST */
#endif /* MBEDTLS_RSA_C */
#endif |
the_stack_data/661204.c | #include <stdio.h>
int sdsll2str(char *s, long long value) {
char *p, aux;
unsigned long long v;
size_t l;
/* Generate the string representation, this method produces
* * an reversed string. */
/* 通过取余数得到原字符串的逆转形式 */
v = (value < 0) ? -value : value;
p = s;
do {
*p++ = '0'+(v%10);
v /= 10;
} while(v);
if (value < 0) *p++ = '-';
/* Compute length and add null term. */
l = p-s;
*p = '\0';
/* Reverse the string. */
/* 反转字符串 */
p--;
while(s < p) {
aux = *s;
*s = *p;
*p = aux;
s++;
p--;
}
return l;
}
int main()
{
int num = 1234567890;
char str[21];
// 整数
int len = sdsll2str(str, num);
printf("len: %d string %s\n", len, str);
// 负数
num = -1234567890;
len = sdsll2str(str, num);
printf("len: %d string %s\n", len, str);
// 超出21,会溢出
num = 1234567890123456789011;
len = sdsll2str(str, num);
printf("len: %d string %s\n", len, str);
return 0;
} |
the_stack_data/173578869.c | /* Author: Tim Siwula
*
* File: ll_sorted
*
* Purpose: Implement a sorted linked list with ops Insert
* and Print.
*
* Input: Single character lower case letters to indicate operations,
* followed by arguments needed by operations.
*
* Output: Results of operations.
*
* Compile: gcc -g -Wall -o lls ll_sorted.c
* Run: ./lls
*
* Notes:
* 1. Repeated values are allowed in the list
* 2. Program assumes an int will be entered when prompted
* for one.
* 3. The insert function is missing some code ...
*/
#include <stdio.h>
#include <stdlib.h>
struct list_node_s {
int data;
struct list_node_s* next_p;
};
struct list_node_s* Insert(struct list_node_s* head_p, int val);
void Print(struct list_node_s* head_p);
char Get_command(void);
int Get_value(void);
/*-----------------------------------------------------------------*/
int main(void) {
char command;
int value;
struct list_node_s* head_p = NULL;
/* start with empty list */
// test
command = Get_command();
while (command != 'q' && command != 'Q') {
switch (command) {
case 'i':
case 'I':
value = Get_value();
head_p = Insert(head_p, value);
break;
case 'p':
case 'P':
Print(head_p);
break;
default:
printf("There is no %c command\n", command);
printf("Please try again\n");
}
command = Get_command();
}
return 0;
} /* main */
/*-----------------------------------------------------------------*/
struct list_node_s* Insert(struct list_node_s* head_p, int val) {
struct list_node_s* curr_p = head_p;
struct list_node_s* pred_p = NULL;
struct list_node_s* temp_p;
// go through the list and compare until inserting value finds the right place to insert value
while (curr_p != NULL) {
if (curr_p->data >= val)
break;
pred_p = curr_p; //
curr_p = curr_p->next_p;
}
// insert in the front of the list or insert into an empty list
if (pred_p == NULL)
{
temp_p = malloc(sizeof(struct list_node_s)); // sets temp_p size
temp_p->data = val;
temp_p->next_p = curr_p;
return temp_p;
}
// normal case: insert nums in the middle of list or at the tail of list
temp_p = malloc(sizeof(struct list_node_s)); // sets temp_p size
temp_p->data = val; // sets inserted value to temp_p's data
temp_p->next_p = curr_p;
pred_p->next_p = temp_p;
return head_p;
} /* Insert */
/*-----------------------------------------------------------------
* Function: Print
* Purpose: print list on a single line of stdout
* Input arg: head_p
*/
void Print(struct list_node_s* head_p) {
struct list_node_s* curr_p = head_p;
printf("list = ");
while (curr_p != NULL) {
printf("%d ", curr_p->data);
curr_p = curr_p->next_p;
}
printf("\n");
} /* Print */
/*-----------------------------------------------------------------
* Function: Get_command
* Purpose: Get a single character command from stdin
* Return value: The first non-whitespace character from stdin
*/
char Get_command(void) {
char c;
printf("Please enter a command (i, p, q): ");
/* Put the space before the %c so scanf will skip white space */
scanf(" %c", &c);
return c;
} /* Get_command */
/*-----------------------------------------------------------------
* Function: Get_value
* Purpose: Get an int from stdin
* Return val: The next int in stdin
* Note: Behavior unpredictable if an int isn't entered
*/
int Get_value(void) {
int val;
printf("Please enter a value: ");
scanf("%d", &val);
return val;
} /* Get_value */ |
the_stack_data/149249.c | #include <stdio.h>
void main()
{
int i,j,k,A;
int c=0;
for(i=0;i<=4;i++)
{
for(j=0;j<=2;j++)
{
for(k=0;k<=j-1;k++)
{
c++;
printf("A");
}
}
}
printf("\n%d",c);
}
//o/p
//AAAAAAAAAAAAAAA
//15
|
the_stack_data/48574345.c | #include <stdio.h>
int main() {
int a = 10;
int b, c;
printf("\n&a = %p, a = %d\n", &a, a);
printf("&b = %p, b = %d\n", &b, b);
printf("&c = %p, c = %d\n\n", &c, c);
b = 20;
c = a + b;
printf("&a = %p, a = %d\n", &a, a);
printf("&b = %p, b = %d\n", &b, b);
printf("&c = %p, c = %d\n\n", &c, c);
return 0;
} |
the_stack_data/123558.c | #include<stdio.h>
int GCD(int a,int b)
{
int gcd,s;
if(a==0) return a;
else if(b==0) return b;
else
{
while(b!=0)
{
s=b;
b=a%b;
a=s;
}
return a;
}
}
int main()
{
int i,j,N,G;
while(scanf("%d",&N)==1 && N!=0)
{
G=0;
for(i=1; i<N; i++)
{
for(j=i+1; j<=N; j++)
{
G+=GCD(i,j);
}
}
printf("%d\n",G);
}
return 0;
}
|
the_stack_data/192329478.c | #include <stdio.h>
#include <stdlib.h>
int sumDigits(int n);
int main()
{
int sum = 0;
int length = 0;
scanf("%d", &length);
char n[length];
scanf("%s", n);
if (length == 1)
{
printf("0\n");
return 0;
}
for (int i = 0; i < length; i++)
sum += ((int)(n[i]))-48;
int timesSpellUsed = 1;
while (sum > 9)
{
sum = sumDigits(sum);
timesSpellUsed++;
}
printf("%d\n", timesSpellUsed);
}
int sumDigits(int n)
{
int sum = 0;
while (n > 0)
{
sum += n % 10;
n /= 10;
}
return sum;
}
|
the_stack_data/90764046.c | /* Copyright 2014-2019 Free Software Foundation, Inc.
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 3 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, see <http://www.gnu.org/licenses/>. */
volatile int i;
volatile int condition;
int
main (void)
{
i = 0;
i = 1;
i = 2;
i = 3;
return 0; /* break here */
}
|
the_stack_data/42923.c | /**
******************************************************************************
* @file stm32f0xx_ll_tim.c
* @author MCD Application Team
* @version V1.4.0
* @date 27-May-2016
* @brief TIM LL module driver.
******************************************************************************
* @attention
*
* <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
#if defined(USE_FULL_LL_DRIVER)
/* Includes ------------------------------------------------------------------*/
#include "stm32f0xx_ll_tim.h"
#include "stm32f0xx_ll_bus.h"
#ifdef USE_FULL_ASSERT
#include "stm32_assert.h"
#else
#define assert_param(expr) ((void)0U)
#endif
/** @addtogroup STM32F0xx_LL_Driver
* @{
*/
#if defined (TIM1) || defined (TIM2) || defined (TIM3) || defined (TIM14) || defined (TIM15) || defined (TIM16) || defined (TIM17) || defined (TIM6) || defined (TIM7)
/** @addtogroup TIM_LL
* @{
*/
/* Private types -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private constants ---------------------------------------------------------*/
/* Private macros ------------------------------------------------------------*/
/** @addtogroup TIM_LL_Private_Macros
* @{
*/
#define IS_LL_TIM_COUNTERMODE(__VALUE__) (((__VALUE__) == LL_TIM_COUNTERMODE_UP) \
|| ((__VALUE__) == LL_TIM_COUNTERMODE_DOWN) \
|| ((__VALUE__) == LL_TIM_COUNTERMODE_CENTER_UP) \
|| ((__VALUE__) == LL_TIM_COUNTERMODE_CENTER_DOWN) \
|| ((__VALUE__) == LL_TIM_COUNTERMODE_CENTER_UP_DOWN))
#define IS_LL_TIM_CLOCKDIVISION(__VALUE__) (((__VALUE__) == LL_TIM_CLOCKDIVISION_DIV1) \
|| ((__VALUE__) == LL_TIM_CLOCKDIVISION_DIV2) \
|| ((__VALUE__) == LL_TIM_CLOCKDIVISION_DIV4))
#define IS_LL_TIM_OCMODE(__VALUE__) (((__VALUE__) == LL_TIM_OCMODE_FROZEN) \
|| ((__VALUE__) == LL_TIM_OCMODE_ACTIVE) \
|| ((__VALUE__) == LL_TIM_OCMODE_INACTIVE) \
|| ((__VALUE__) == LL_TIM_OCMODE_TOGGLE) \
|| ((__VALUE__) == LL_TIM_OCMODE_FORCED_INACTIVE) \
|| ((__VALUE__) == LL_TIM_OCMODE_FORCED_ACTIVE) \
|| ((__VALUE__) == LL_TIM_OCMODE_PWM1) \
|| ((__VALUE__) == LL_TIM_OCMODE_PWM2))
#define IS_LL_TIM_OCSTATE(__VALUE__) (((__VALUE__) == LL_TIM_OCSTATE_DISABLE) \
|| ((__VALUE__) == LL_TIM_OCSTATE_ENABLE))
#define IS_LL_TIM_OCPOLARITY(__VALUE__) (((__VALUE__) == LL_TIM_OCPOLARITY_HIGH) \
|| ((__VALUE__) == LL_TIM_OCPOLARITY_LOW))
#define IS_LL_TIM_OCIDLESTATE(__VALUE__) (((__VALUE__) == LL_TIM_OCIDLESTATE_LOW) \
|| ((__VALUE__) == LL_TIM_OCIDLESTATE_HIGH))
#define IS_LL_TIM_ACTIVEINPUT(__VALUE__) (((__VALUE__) == LL_TIM_ACTIVEINPUT_DIRECTTI) \
|| ((__VALUE__) == LL_TIM_ACTIVEINPUT_INDIRECTTI) \
|| ((__VALUE__) == LL_TIM_ACTIVEINPUT_TRC))
#define IS_LL_TIM_ICPSC(__VALUE__) (((__VALUE__) == LL_TIM_ICPSC_DIV1) \
|| ((__VALUE__) == LL_TIM_ICPSC_DIV2) \
|| ((__VALUE__) == LL_TIM_ICPSC_DIV4) \
|| ((__VALUE__) == LL_TIM_ICPSC_DIV8))
#define IS_LL_TIM_IC_FILTER(__VALUE__) (((__VALUE__) == LL_TIM_IC_FILTER_FDIV1) \
|| ((__VALUE__) == LL_TIM_IC_FILTER_FDIV1_N2) \
|| ((__VALUE__) == LL_TIM_IC_FILTER_FDIV1_N4) \
|| ((__VALUE__) == LL_TIM_IC_FILTER_FDIV1_N8) \
|| ((__VALUE__) == LL_TIM_IC_FILTER_FDIV2_N6) \
|| ((__VALUE__) == LL_TIM_IC_FILTER_FDIV2_N8) \
|| ((__VALUE__) == LL_TIM_IC_FILTER_FDIV4_N6) \
|| ((__VALUE__) == LL_TIM_IC_FILTER_FDIV4_N8) \
|| ((__VALUE__) == LL_TIM_IC_FILTER_FDIV8_N6) \
|| ((__VALUE__) == LL_TIM_IC_FILTER_FDIV8_N8) \
|| ((__VALUE__) == LL_TIM_IC_FILTER_FDIV16_N5) \
|| ((__VALUE__) == LL_TIM_IC_FILTER_FDIV16_N6) \
|| ((__VALUE__) == LL_TIM_IC_FILTER_FDIV16_N8) \
|| ((__VALUE__) == LL_TIM_IC_FILTER_FDIV32_N5) \
|| ((__VALUE__) == LL_TIM_IC_FILTER_FDIV32_N6) \
|| ((__VALUE__) == LL_TIM_IC_FILTER_FDIV32_N8))
#define IS_LL_TIM_IC_POLARITY(__VALUE__) (((__VALUE__) == LL_TIM_IC_POLARITY_RISING) \
|| ((__VALUE__) == LL_TIM_IC_POLARITY_FALLING) \
|| ((__VALUE__) == LL_TIM_IC_POLARITY_BOTHEDGE))
#define IS_LL_TIM_ENCODERMODE(__VALUE__) (((__VALUE__) == LL_TIM_ENCODERMODE_X2_TI1) \
|| ((__VALUE__) == LL_TIM_ENCODERMODE_X2_TI2) \
|| ((__VALUE__) == LL_TIM_ENCODERMODE_X4_TI12))
#define IS_LL_TIM_IC_POLARITY_ENCODER(__VALUE__) (((__VALUE__) == LL_TIM_IC_POLARITY_RISING) \
|| ((__VALUE__) == LL_TIM_IC_POLARITY_FALLING))
/**
* @}
*/
/* Private function prototypes -----------------------------------------------*/
/** @defgroup TIM_LL_Private_Functions TIM Private Functions
* @{
*/
static ErrorStatus OC1Config(TIM_TypeDef *TIMx, LL_TIM_OC_InitTypeDef *TIM_OCInitStruct);
static ErrorStatus OC2Config(TIM_TypeDef *TIMx, LL_TIM_OC_InitTypeDef *TIM_OCInitStruct);
static ErrorStatus OC3Config(TIM_TypeDef *TIMx, LL_TIM_OC_InitTypeDef *TIM_OCInitStruct);
static ErrorStatus OC4Config(TIM_TypeDef *TIMx, LL_TIM_OC_InitTypeDef *TIM_OCInitStruct);
static ErrorStatus IC1Config(TIM_TypeDef *TIMx, LL_TIM_IC_InitTypeDef *TIM_ICInitStruct);
static ErrorStatus IC2Config(TIM_TypeDef *TIMx, LL_TIM_IC_InitTypeDef *TIM_ICInitStruct);
static ErrorStatus IC3Config(TIM_TypeDef *TIMx, LL_TIM_IC_InitTypeDef *TIM_ICInitStruct);
static ErrorStatus IC4Config(TIM_TypeDef *TIMx, LL_TIM_IC_InitTypeDef *TIM_ICInitStruct);
/**
* @}
*/
/* Exported functions --------------------------------------------------------*/
/** @addtogroup TIM_LL_Exported_Functions
* @{
*/
/** @addtogroup TIM_LL_EF_Init
* @{
*/
/**
* @brief Set TIMx registers to their reset values.
* @param TIMx Timer instance
* @retval An ErrorStatus enumeration value:
* - SUCCESS: TIMx registers are de-initialized
* - ERROR: invalid TIMx instance
*/
ErrorStatus LL_TIM_DeInit(TIM_TypeDef *TIMx)
{
ErrorStatus result = SUCCESS;
/* Check the parameters */
assert_param(IS_TIM_INSTANCE(TIMx));
if (TIMx == TIM1)
{
LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_TIM1);
LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_TIM1);
}
#if defined (TIM2)
else if (TIMx == TIM2)
{
LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_TIM2);
LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_TIM2);
}
#endif
#if defined(TIM3)
else if (TIMx == TIM3)
{
LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_TIM3);
LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_TIM3);
}
#endif
#if defined(TIM5)
else if (TIMx == TIM5)
{
LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_TIM5);
LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_TIM5);
}
#endif
#if defined (TIM6)
else if (TIMx == TIM6)
{
LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_TIM6);
LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_TIM6);
}
#endif
#if defined (TIM7)
else if (TIMx == TIM7)
{
LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_TIM7);
LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_TIM7);
}
#endif
#if defined(TIM8)
else if (TIMx == TIM8)
{
LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_TIM8);
LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_TIM8);
}
#endif
#if defined (TIM14)
else if (TIMx == TIM14)
{
LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_TIM14);
LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_TIM14);
}
#endif
#if defined (TIM15)
else if (TIMx == TIM15)
{
LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_TIM15);
LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_TIM15);
}
#endif
#if defined (TIM16)
else if (TIMx == TIM16)
{
LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_TIM16);
LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_TIM16);
}
#endif
#if defined(TIM17)
else if (TIMx == TIM17)
{
LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_TIM17);
LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_TIM17);
}
#endif
else
{
result = ERROR;
}
return result;
}
/**
* @brief Set the fields of the time base unit configuration data structure
* to their default values.
* @param TIM_InitStruct pointer to a @ref LL_TIM_InitTypeDef structure (time base unit configuration data structure)
* @retval None
*/
void LL_TIM_StructInit(LL_TIM_InitTypeDef *TIM_InitStruct)
{
/* Set the default configuration */
TIM_InitStruct->Prescaler = (uint16_t)0x0000U;
TIM_InitStruct->CounterMode = LL_TIM_COUNTERMODE_UP;
TIM_InitStruct->Autoreload = (uint32_t)0xFFFFFFFFU;
TIM_InitStruct->ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
TIM_InitStruct->RepetitionCounter = (uint8_t)0x00U;
}
/**
* @brief Configure the TIMx time base unit.
* @param TIMx Timer Instance
* @param TIM_InitStruct pointer to a @ref LL_TIM_InitTypeDef structure (TIMx time base unit configuration data structure)
* @retval An ErrorStatus enumeration value:
* - SUCCESS: TIMx registers are de-initialized
* - ERROR: not applicable
*/
ErrorStatus LL_TIM_Init(TIM_TypeDef *TIMx, LL_TIM_InitTypeDef *TIM_InitStruct)
{
uint32_t tmpcr1 = 0U;
/* Check the parameters */
assert_param(IS_TIM_INSTANCE(TIMx));
assert_param(IS_LL_TIM_COUNTERMODE(TIM_InitStruct->CounterMode));
assert_param(IS_LL_TIM_CLOCKDIVISION(TIM_InitStruct->ClockDivision));
tmpcr1 = LL_TIM_ReadReg(TIMx, CR1);
if (IS_TIM_COUNTER_MODE_SELECT_INSTANCE(TIMx))
{
/* Select the Counter Mode */
MODIFY_REG(tmpcr1, (TIM_CR1_DIR | TIM_CR1_CMS), TIM_InitStruct->CounterMode);
}
if (IS_TIM_CLOCK_DIVISION_INSTANCE(TIMx))
{
/* Set the clock division */
MODIFY_REG(tmpcr1, TIM_CR1_CKD, TIM_InitStruct->ClockDivision);
}
/* Write to TIMx CR1 */
LL_TIM_WriteReg(TIMx, CR1, tmpcr1);
/* Set the Autoreload value */
LL_TIM_SetAutoReload(TIMx, TIM_InitStruct->Autoreload);
/* Set the Prescaler value */
LL_TIM_SetPrescaler(TIMx, TIM_InitStruct->Prescaler);
if (IS_TIM_REPETITION_COUNTER_INSTANCE(TIMx))
{
/* Set the Repetition Counter value */
LL_TIM_SetRepetitionCounter(TIMx, TIM_InitStruct->RepetitionCounter);
}
/* Generate an update event to reload the Prescaler
and the repetition counter value (if applicable) immediately */
LL_TIM_GenerateEvent_UPDATE(TIMx);
return SUCCESS;
}
/**
* @brief Set the fields of the TIMx output channel configuration data
* structure to their default values.
* @param TIM_OC_InitStruct pointer to a @ref LL_TIM_OC_InitTypeDef structure (the output channel configuration data structure)
* @retval None
*/
void LL_TIM_OC_StructInit(LL_TIM_OC_InitTypeDef *TIM_OC_InitStruct)
{
/* Set the default configuration */
TIM_OC_InitStruct->OCMode = LL_TIM_OCMODE_FROZEN;
TIM_OC_InitStruct->OCState = LL_TIM_OCSTATE_DISABLE;
TIM_OC_InitStruct->OCNState = LL_TIM_OCSTATE_DISABLE;
TIM_OC_InitStruct->CompareValue = (uint32_t)0x00000000U;
TIM_OC_InitStruct->OCPolarity = LL_TIM_OCPOLARITY_HIGH;
TIM_OC_InitStruct->OCNPolarity = LL_TIM_OCPOLARITY_HIGH;
TIM_OC_InitStruct->OCIdleState = LL_TIM_OCIDLESTATE_LOW;
TIM_OC_InitStruct->OCNIdleState = LL_TIM_OCIDLESTATE_LOW;
}
/**
* @brief Configure the TIMx output channel.
* @param TIMx Timer Instance
* @param Channel This parameter can be one of the following values:
* @arg @ref LL_TIM_CHANNEL_CH1
* @arg @ref LL_TIM_CHANNEL_CH2
* @arg @ref LL_TIM_CHANNEL_CH3
* @arg @ref LL_TIM_CHANNEL_CH4
* @param TIM_OC_InitStruct pointer to a @ref LL_TIM_OC_InitTypeDef structure (TIMx output channel configuration data structure)
* @retval An ErrorStatus enumeration value:
* - SUCCESS: TIMx output channel is initialized
* - ERROR: TIMx output channel is not initialized
*/
ErrorStatus LL_TIM_OC_Init(TIM_TypeDef *TIMx, uint32_t Channel, LL_TIM_OC_InitTypeDef *TIM_OC_InitStruct)
{
ErrorStatus result = ERROR;
switch (Channel)
{
case LL_TIM_CHANNEL_CH1:
result = OC1Config(TIMx, TIM_OC_InitStruct);
break;
case LL_TIM_CHANNEL_CH2:
result = OC2Config(TIMx, TIM_OC_InitStruct);
break;
case LL_TIM_CHANNEL_CH3:
result = OC3Config(TIMx, TIM_OC_InitStruct);
break;
case LL_TIM_CHANNEL_CH4:
result = OC4Config(TIMx, TIM_OC_InitStruct);
break;
default:
break;
}
return result;
}
/**
* @brief Set the fields of the TIMx input channel configuration data
* structure to their default values.
* @param TIM_ICInitStruct pointer to a @ref LL_TIM_IC_InitTypeDef structure (the input channel configuration data structure)
* @retval None
*/
void LL_TIM_IC_StructInit(LL_TIM_IC_InitTypeDef *TIM_ICInitStruct)
{
/* Set the default configuration */
TIM_ICInitStruct->ICPolarity = LL_TIM_IC_POLARITY_RISING;
TIM_ICInitStruct->ICActiveInput = LL_TIM_ACTIVEINPUT_DIRECTTI;
TIM_ICInitStruct->ICPrescaler = LL_TIM_ICPSC_DIV1;
TIM_ICInitStruct->ICFilter = LL_TIM_IC_FILTER_FDIV1;
}
/**
* @brief Configure the TIMx input channel.
* @param TIMx Timer Instance
* @param Channel This parameter can be one of the following values:
* @arg @ref LL_TIM_CHANNEL_CH1
* @arg @ref LL_TIM_CHANNEL_CH2
* @arg @ref LL_TIM_CHANNEL_CH3
* @arg @ref LL_TIM_CHANNEL_CH4
* @param TIM_IC_InitStruct pointer to a @ref LL_TIM_IC_InitTypeDef structure (TIMx input channel configuration data structure)
* @retval An ErrorStatus enumeration value:
* - SUCCESS: TIMx output channel is initialized
* - ERROR: TIMx output channel is not initialized
*/
ErrorStatus LL_TIM_IC_Init(TIM_TypeDef *TIMx, uint32_t Channel, LL_TIM_IC_InitTypeDef *TIM_IC_InitStruct)
{
ErrorStatus result = ERROR;
switch (Channel)
{
case LL_TIM_CHANNEL_CH1:
result = IC1Config(TIMx, TIM_IC_InitStruct);
break;
case LL_TIM_CHANNEL_CH2:
result = IC2Config(TIMx, TIM_IC_InitStruct);
break;
case LL_TIM_CHANNEL_CH3:
result = IC3Config(TIMx, TIM_IC_InitStruct);
break;
case LL_TIM_CHANNEL_CH4:
result = IC4Config(TIMx, TIM_IC_InitStruct);
break;
default:
break;
}
return result;
}
/**
* @brief Fills each TIM_EncoderInitStruct field with its default value
* @param TIM_EncoderInitStruct pointer to a @ref LL_TIM_ENCODER_InitTypeDef structure (encoder interface configuration data structure)
* @retval None
*/
void LL_TIM_ENCODER_StructInit(LL_TIM_ENCODER_InitTypeDef *TIM_EncoderInitStruct)
{
/* Set the default configuration */
TIM_EncoderInitStruct->EncoderMode = LL_TIM_ENCODERMODE_X2_TI1;
TIM_EncoderInitStruct->IC1Polarity = LL_TIM_IC_POLARITY_RISING;
TIM_EncoderInitStruct->IC1ActiveInput = LL_TIM_ACTIVEINPUT_DIRECTTI;
TIM_EncoderInitStruct->IC1Prescaler = LL_TIM_ICPSC_DIV1;
TIM_EncoderInitStruct->IC1Filter = LL_TIM_IC_FILTER_FDIV1;
TIM_EncoderInitStruct->IC2Polarity = LL_TIM_IC_POLARITY_RISING;
TIM_EncoderInitStruct->IC2ActiveInput = LL_TIM_ACTIVEINPUT_DIRECTTI;
TIM_EncoderInitStruct->IC2Prescaler = LL_TIM_ICPSC_DIV1;
TIM_EncoderInitStruct->IC2Filter = LL_TIM_IC_FILTER_FDIV1;
}
/**
* @brief Configure the encoder interface of the timer instance.
* @param TIMx Timer Instance
* @param TIM_EncoderInitStruct pointer to a @ref LL_TIM_ENCODER_InitTypeDef structure (TIMx encoder interface configuration data structure)
* @retval An ErrorStatus enumeration value:
* - SUCCESS: TIMx registers are de-initialized
* - ERROR: not applicable
*/
ErrorStatus LL_TIM_ENCODER_Init(TIM_TypeDef *TIMx, LL_TIM_ENCODER_InitTypeDef *TIM_EncoderInitStruct)
{
uint32_t tmpccmr1 = 0U;
uint32_t tmpccer = 0U;
/* Check the parameters */
assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(TIMx));
assert_param(IS_LL_TIM_ENCODERMODE(TIM_EncoderInitStruct->EncoderMode));
assert_param(IS_LL_TIM_IC_POLARITY_ENCODER(TIM_EncoderInitStruct->IC1Polarity));
assert_param(IS_LL_TIM_ACTIVEINPUT(TIM_EncoderInitStruct->IC1ActiveInput));
assert_param(IS_LL_TIM_ICPSC(TIM_EncoderInitStruct->IC1Prescaler));
assert_param(IS_LL_TIM_IC_FILTER(TIM_EncoderInitStruct->IC1Filter));
assert_param(IS_LL_TIM_IC_POLARITY_ENCODER(TIM_EncoderInitStruct->IC2Polarity));
assert_param(IS_LL_TIM_ACTIVEINPUT(TIM_EncoderInitStruct->IC2ActiveInput));
assert_param(IS_LL_TIM_ICPSC(TIM_EncoderInitStruct->IC2Prescaler));
assert_param(IS_LL_TIM_IC_FILTER(TIM_EncoderInitStruct->IC2Filter));
/* Disable the CC1 and CC2: Reset the CC1E and CC2E Bits */
TIMx->CCER &= (uint32_t)~(TIM_CCER_CC1E | TIM_CCER_CC2E);
/* Get the TIMx CCMR1 register value */
tmpccmr1 = LL_TIM_ReadReg(TIMx, CCMR1);
/* Get the TIMx CCER register value */
tmpccer = LL_TIM_ReadReg(TIMx, CCER);
/* Configure TI1 */
tmpccmr1 &= (uint32_t)~(TIM_CCMR1_CC1S | TIM_CCMR1_IC1F | TIM_CCMR1_IC1PSC);
tmpccmr1 |= (uint32_t)(TIM_EncoderInitStruct->IC1ActiveInput >> 16U);
tmpccmr1 |= (uint32_t)(TIM_EncoderInitStruct->IC1Filter >> 16U);
tmpccmr1 |= (uint32_t)(TIM_EncoderInitStruct->IC1Prescaler >> 16U);
/* Configure TI2 */
tmpccmr1 &= (uint32_t)~(TIM_CCMR1_CC2S | TIM_CCMR1_IC2F | TIM_CCMR1_IC2PSC);
tmpccmr1 |= (uint32_t)(TIM_EncoderInitStruct->IC2ActiveInput >> 8U);
tmpccmr1 |= (uint32_t)(TIM_EncoderInitStruct->IC2Filter >> 8U);
tmpccmr1 |= (uint32_t)(TIM_EncoderInitStruct->IC2Prescaler >> 8U);
/* Set TI1 and TI2 polarity and enable TI1 and TI2 */
tmpccer &= (uint32_t)~(TIM_CCER_CC1P | TIM_CCER_CC1NP | TIM_CCER_CC2P | TIM_CCER_CC2NP);
tmpccer |= (uint32_t)(TIM_EncoderInitStruct->IC1Polarity);
tmpccer |= (uint32_t)(TIM_EncoderInitStruct->IC2Polarity << 4U);
tmpccer |= (uint32_t)(TIM_CCER_CC1E | TIM_CCER_CC2E);
/* Set encoder mode */
LL_TIM_SetEncoderMode(TIMx, TIM_EncoderInitStruct->EncoderMode);
/* Write to TIMx CCMR1 */
LL_TIM_WriteReg(TIMx, CCMR1, tmpccmr1);
/* Write to TIMx CCER */
LL_TIM_WriteReg(TIMx, CCER, tmpccer);
return SUCCESS;
}
/**
* @brief Set the fields of the TIMx Hall sensor interface configuration data
* structure to their default values.
* @param TIM_HallSensorInitStruct pointer to a @ref LL_TIM_HALLSENSOR_InitTypeDef structure (HALL sensor interface configuration data structure)
* @retval None
*/
void LL_TIM_HALLSENSOR_StructInit(LL_TIM_HALLSENSOR_InitTypeDef *TIM_HallSensorInitStruct)
{
/* Set the default configuration */
TIM_HallSensorInitStruct->IC1Polarity = LL_TIM_IC_POLARITY_RISING;
TIM_HallSensorInitStruct->IC1Prescaler = LL_TIM_ICPSC_DIV1;
TIM_HallSensorInitStruct->IC1Filter = LL_TIM_IC_FILTER_FDIV1;
TIM_HallSensorInitStruct->CommutationDelay = (uint32_t)0U;
}
/**
* @brief Configure the Hall sensor interface of the timer instance.
* @note TIMx CH1, CH2 and CH3 inputs connected through a XOR
* to the TI1 input channel
* @note TIMx slave mode controller is configured in reset mode.
Selected internal trigger is TI1F_ED.
* @note Channel 1 is configured as input, IC1 is mapped on TRC.
* @note Captured value stored in TIMx_CCR1 correspond to the time elapsed
* between 2 changes on the inputs. It gives information about motor speed.
* @note Channel 2 is configured in output PWM 2 mode.
* @note Compare value stored in TIMx_CCR2 corresponds to the commutation delay.
* @note OC2REF is selected as trigger output on TRGO.
* @note LL_TIM_IC_POLARITY_BOTHEDGE must not be used for TI1 when it is used
* when TIMx operates in Hall sensor interface mode.
* @param TIMx Timer Instance
* @param TIM_HallSensorInitStruct pointer to a @ref LL_TIM_HALLSENSOR_InitTypeDef structure (TIMx HALL sensor interface configuration data structure)
* @retval An ErrorStatus enumeration value:
* - SUCCESS: TIMx registers are de-initialized
* - ERROR: not applicable
*/
ErrorStatus LL_TIM_HALLSENSOR_Init(TIM_TypeDef *TIMx, LL_TIM_HALLSENSOR_InitTypeDef *TIM_HallSensorInitStruct)
{
uint32_t tmpcr2 = 0U;
uint32_t tmpccmr1 = 0U;
uint32_t tmpccer = 0U;
uint32_t tmpsmcr = 0U;
/* Check the parameters */
assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(TIMx));
assert_param(IS_LL_TIM_IC_POLARITY_ENCODER(TIM_HallSensorInitStruct->IC1Polarity));
assert_param(IS_LL_TIM_ICPSC(TIM_HallSensorInitStruct->IC1Prescaler));
assert_param(IS_LL_TIM_IC_FILTER(TIM_HallSensorInitStruct->IC1Filter));
/* Disable the CC1 and CC2: Reset the CC1E and CC2E Bits */
TIMx->CCER &= (uint32_t)~(TIM_CCER_CC1E | TIM_CCER_CC2E);
/* Get the TIMx CR2 register value */
tmpcr2 = LL_TIM_ReadReg(TIMx, CR2);
/* Get the TIMx CCMR1 register value */
tmpccmr1 = LL_TIM_ReadReg(TIMx, CCMR1);
/* Get the TIMx CCER register value */
tmpccer = LL_TIM_ReadReg(TIMx, CCER);
/* Get the TIMx SMCR register value */
tmpsmcr = LL_TIM_ReadReg(TIMx, SMCR);
/* Connect TIMx_CH1, CH2 and CH3 pins to the TI1 input */
tmpcr2 |= TIM_CR2_TI1S;
/* OC2REF signal is used as trigger output (TRGO) */
tmpcr2 |= LL_TIM_TRGO_OC2REF;
/* Configure the slave mode controller */
tmpsmcr &= (uint32_t)~(TIM_SMCR_TS | TIM_SMCR_SMS);
tmpsmcr |= LL_TIM_TS_TI1F_ED;
tmpsmcr |= LL_TIM_SLAVEMODE_RESET;
/* Configure input channel 1 */
tmpccmr1 &= (uint32_t)~(TIM_CCMR1_CC1S | TIM_CCMR1_IC1F | TIM_CCMR1_IC1PSC);
tmpccmr1 |= (uint32_t)(LL_TIM_ACTIVEINPUT_TRC >> 16U);
tmpccmr1 |= (uint32_t)(TIM_HallSensorInitStruct->IC1Filter >> 16U);
tmpccmr1 |= (uint32_t)(TIM_HallSensorInitStruct->IC1Prescaler >> 16U);
/* Configure input channel 2 */
tmpccmr1 &= (uint32_t)~(TIM_CCMR1_OC2M | TIM_CCMR1_OC2FE | TIM_CCMR1_OC2PE | TIM_CCMR1_OC2CE);
tmpccmr1 |= (uint32_t)(LL_TIM_OCMODE_PWM2 << 8U);
/* Set Channel 1 polarity and enable Channel 1 and Channel2 */
tmpccer &= (uint32_t)~(TIM_CCER_CC1P | TIM_CCER_CC1NP | TIM_CCER_CC2P | TIM_CCER_CC2NP);
tmpccer |= (uint32_t)(TIM_HallSensorInitStruct->IC1Polarity);
tmpccer |= (uint32_t)(TIM_CCER_CC1E | TIM_CCER_CC2E);
/* Write to TIMx CR2 */
LL_TIM_WriteReg(TIMx, CR2, tmpcr2);
/* Write to TIMx SMCR */
LL_TIM_WriteReg(TIMx, SMCR, tmpsmcr);
/* Write to TIMx CCMR1 */
LL_TIM_WriteReg(TIMx, CCMR1, tmpccmr1);
/* Write to TIMx CCER */
LL_TIM_WriteReg(TIMx, CCER, tmpccer);
/* Write to TIMx CCR2 */
LL_TIM_OC_SetCompareCH2(TIMx, TIM_HallSensorInitStruct->CommutationDelay);
return SUCCESS;
}
/**
* @}
*/
/**
* @}
*/
/** @addtogroup TIM_LL_Private_Functions TIM Private Functions
* @brief Private functions
* @{
*/
/**
* @brief Configure the TIMx output channel 1.
* @param TIMx Timer Instance
* @param TIM_OCInitStruct pointer to the the TIMx output channel 1 configuration data structure
* @retval An ErrorStatus enumeration value:
* - SUCCESS: TIMx registers are de-initialized
* - ERROR: not applicable
*/
static ErrorStatus OC1Config(TIM_TypeDef *TIMx, LL_TIM_OC_InitTypeDef *TIM_OCInitStruct)
{
uint32_t tmpccmr1 = 0U;
uint32_t tmpccer = 0U;
uint32_t tmpcr2 = 0U;
/* Check the parameters */
assert_param(IS_TIM_CC1_INSTANCE(TIMx));
assert_param(IS_LL_TIM_OCMODE(TIM_OCInitStruct->OCMode));
assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCState));
assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCPolarity));
assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCNState));
assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCNPolarity));
/* Disable the Channel 1: Reset the CC1E Bit */
CLEAR_BIT(TIMx->CCER, TIM_CCER_CC1E);
/* Get the TIMx CCER register value */
tmpccer = LL_TIM_ReadReg(TIMx, CCER);
/* Get the TIMx CR2 register value */
tmpcr2 = LL_TIM_ReadReg(TIMx, CR2);
/* Get the TIMx CCMR1 register value */
tmpccmr1 = LL_TIM_ReadReg(TIMx, CCMR1);
/* Reset Capture/Compare selection Bits */
CLEAR_BIT(tmpccmr1, TIM_CCMR1_CC1S);
/* Set the Output Compare Mode */
MODIFY_REG(tmpccmr1, TIM_CCMR1_OC1M, TIM_OCInitStruct->OCMode);
/* Set the Output Compare Polarity */
MODIFY_REG(tmpccer, TIM_CCER_CC1P, TIM_OCInitStruct->OCPolarity);
/* Set the Output State */
MODIFY_REG(tmpccer, TIM_CCER_CC1E, TIM_OCInitStruct->OCState);
if (IS_TIM_BREAK_INSTANCE(TIMx))
{
assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCNIdleState));
assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCIdleState));
/* Set the complementary output Polarity */
MODIFY_REG(tmpccer, TIM_CCER_CC1NP, TIM_OCInitStruct->OCNPolarity << 2U);
/* Set the complementary output State */
MODIFY_REG(tmpccer, TIM_CCER_CC1NE, TIM_OCInitStruct->OCNState << 2U);
/* Set the Output Idle state */
MODIFY_REG(tmpcr2, TIM_CR2_OIS1, TIM_OCInitStruct->OCIdleState);
/* Set the complementary output Idle state */
MODIFY_REG(tmpcr2, TIM_CR2_OIS1N, TIM_OCInitStruct->OCNIdleState << 1U);
}
/* Write to TIMx CR2 */
LL_TIM_WriteReg(TIMx, CR2, tmpcr2);
/* Write to TIMx CCMR1 */
LL_TIM_WriteReg(TIMx, CCMR1, tmpccmr1);
/* Set the Capture Compare Register value */
LL_TIM_OC_SetCompareCH1(TIMx, TIM_OCInitStruct->CompareValue);
/* Write to TIMx CCER */
LL_TIM_WriteReg(TIMx, CCER, tmpccer);
return SUCCESS;
}
/**
* @brief Configure the TIMx output channel 2.
* @param TIMx Timer Instance
* @param TIM_OCInitStruct pointer to the the TIMx output channel 2 configuration data structure
* @retval An ErrorStatus enumeration value:
* - SUCCESS: TIMx registers are de-initialized
* - ERROR: not applicable
*/
static ErrorStatus OC2Config(TIM_TypeDef *TIMx, LL_TIM_OC_InitTypeDef *TIM_OCInitStruct)
{
uint32_t tmpccmr1 = 0U;
uint32_t tmpccer = 0U;
uint32_t tmpcr2 = 0U;
/* Check the parameters */
assert_param(IS_TIM_CC2_INSTANCE(TIMx));
assert_param(IS_LL_TIM_OCMODE(TIM_OCInitStruct->OCMode));
assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCState));
assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCPolarity));
assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCNState));
assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCNPolarity));
/* Disable the Channel 2: Reset the CC2E Bit */
CLEAR_BIT(TIMx->CCER, TIM_CCER_CC2E);
/* Get the TIMx CCER register value */
tmpccer = LL_TIM_ReadReg(TIMx, CCER);
/* Get the TIMx CR2 register value */
tmpcr2 = LL_TIM_ReadReg(TIMx, CR2);
/* Get the TIMx CCMR1 register value */
tmpccmr1 = LL_TIM_ReadReg(TIMx, CCMR1);
/* Reset Capture/Compare selection Bits */
CLEAR_BIT(tmpccmr1, TIM_CCMR1_CC2S);
/* Select the Output Compare Mode */
MODIFY_REG(tmpccmr1, TIM_CCMR1_OC2M, TIM_OCInitStruct->OCMode << 8U);
/* Set the Output Compare Polarity */
MODIFY_REG(tmpccer, TIM_CCER_CC2P, TIM_OCInitStruct->OCPolarity << 4U);
/* Set the Output State */
MODIFY_REG(tmpccer, TIM_CCER_CC2E, TIM_OCInitStruct->OCState << 4U);
if (IS_TIM_BREAK_INSTANCE(TIMx))
{
assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCNIdleState));
assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCIdleState));
/* Set the complementary output Polarity */
MODIFY_REG(tmpccer, TIM_CCER_CC2NP, TIM_OCInitStruct->OCNPolarity << 6U);
/* Set the complementary output State */
MODIFY_REG(tmpccer, TIM_CCER_CC2NE, TIM_OCInitStruct->OCNState << 6U);
/* Set the Output Idle state */
MODIFY_REG(tmpcr2, TIM_CR2_OIS2, TIM_OCInitStruct->OCIdleState << 2U);
/* Set the complementary output Idle state */
MODIFY_REG(tmpcr2, TIM_CR2_OIS2N, TIM_OCInitStruct->OCNIdleState << 3U);
}
/* Write to TIMx CR2 */
LL_TIM_WriteReg(TIMx, CR2, tmpcr2);
/* Write to TIMx CCMR1 */
LL_TIM_WriteReg(TIMx, CCMR1, tmpccmr1);
/* Set the Capture Compare Register value */
LL_TIM_OC_SetCompareCH2(TIMx, TIM_OCInitStruct->CompareValue);
/* Write to TIMx CCER */
LL_TIM_WriteReg(TIMx, CCER, tmpccer);
return SUCCESS;
}
/**
* @brief Configure the TIMx output channel 3.
* @param TIMx Timer Instance
* @param TIM_OCInitStruct pointer to the the TIMx output channel 3 configuration data structure
* @retval An ErrorStatus enumeration value:
* - SUCCESS: TIMx registers are de-initialized
* - ERROR: not applicable
*/
static ErrorStatus OC3Config(TIM_TypeDef *TIMx, LL_TIM_OC_InitTypeDef *TIM_OCInitStruct)
{
uint32_t tmpccmr2 = 0U;
uint32_t tmpccer = 0U;
uint32_t tmpcr2 = 0U;
/* Check the parameters */
assert_param(IS_TIM_CC3_INSTANCE(TIMx));
assert_param(IS_LL_TIM_OCMODE(TIM_OCInitStruct->OCMode));
assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCState));
assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCPolarity));
assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCNState));
assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCNPolarity));
/* Disable the Channel 3: Reset the CC3E Bit */
CLEAR_BIT(TIMx->CCER, TIM_CCER_CC3E);
/* Get the TIMx CCER register value */
tmpccer = LL_TIM_ReadReg(TIMx, CCER);
/* Get the TIMx CR2 register value */
tmpcr2 = LL_TIM_ReadReg(TIMx, CR2);
/* Get the TIMx CCMR2 register value */
tmpccmr2 = LL_TIM_ReadReg(TIMx, CCMR2);
/* Reset Capture/Compare selection Bits */
CLEAR_BIT(tmpccmr2, TIM_CCMR2_CC3S);
/* Select the Output Compare Mode */
MODIFY_REG(tmpccmr2, TIM_CCMR2_OC3M, TIM_OCInitStruct->OCMode);
/* Set the Output Compare Polarity */
MODIFY_REG(tmpccer, TIM_CCER_CC3P, TIM_OCInitStruct->OCPolarity << 8U);
/* Set the Output State */
MODIFY_REG(tmpccer, TIM_CCER_CC3E, TIM_OCInitStruct->OCState << 8U);
if (IS_TIM_BREAK_INSTANCE(TIMx))
{
assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCNIdleState));
assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCIdleState));
/* Set the complementary output Polarity */
MODIFY_REG(tmpccer, TIM_CCER_CC3NP, TIM_OCInitStruct->OCNPolarity << 10U);
/* Set the complementary output State */
MODIFY_REG(tmpccer, TIM_CCER_CC3NE, TIM_OCInitStruct->OCNState << 10U);
/* Set the Output Idle state */
MODIFY_REG(tmpcr2, TIM_CR2_OIS3, TIM_OCInitStruct->OCIdleState << 4U);
/* Set the complementary output Idle state */
MODIFY_REG(tmpcr2, TIM_CR2_OIS3N, TIM_OCInitStruct->OCNIdleState << 5U);
}
/* Write to TIMx CR2 */
LL_TIM_WriteReg(TIMx, CR2, tmpcr2);
/* Write to TIMx CCMR2 */
LL_TIM_WriteReg(TIMx, CCMR2, tmpccmr2);
/* Set the Capture Compare Register value */
LL_TIM_OC_SetCompareCH3(TIMx, TIM_OCInitStruct->CompareValue);
/* Write to TIMx CCER */
LL_TIM_WriteReg(TIMx, CCER, tmpccer);
return SUCCESS;
}
/**
* @brief Configure the TIMx output channel 4.
* @param TIMx Timer Instance
* @param TIM_OCInitStruct pointer to the the TIMx output channel 4 configuration data structure
* @retval An ErrorStatus enumeration value:
* - SUCCESS: TIMx registers are de-initialized
* - ERROR: not applicable
*/
static ErrorStatus OC4Config(TIM_TypeDef *TIMx, LL_TIM_OC_InitTypeDef *TIM_OCInitStruct)
{
uint32_t tmpccmr2 = 0U;
uint32_t tmpccer = 0U;
uint32_t tmpcr2 = 0U;
/* Check the parameters */
assert_param(IS_TIM_CC4_INSTANCE(TIMx));
assert_param(IS_LL_TIM_OCMODE(TIM_OCInitStruct->OCMode));
assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCState));
assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCPolarity));
assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCNPolarity));
assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCNState));
/* Disable the Channel 4: Reset the CC4E Bit */
CLEAR_BIT(TIMx->CCER, TIM_CCER_CC4E);
/* Get the TIMx CCER register value */
tmpccer = LL_TIM_ReadReg(TIMx, CCER);
/* Get the TIMx CR2 register value */
tmpcr2 = LL_TIM_ReadReg(TIMx, CR2);
/* Get the TIMx CCMR2 register value */
tmpccmr2 = LL_TIM_ReadReg(TIMx, CCMR2);
/* Reset Capture/Compare selection Bits */
CLEAR_BIT(tmpccmr2, TIM_CCMR2_CC4S);
/* Select the Output Compare Mode */
MODIFY_REG(tmpccmr2, TIM_CCMR2_OC4M, TIM_OCInitStruct->OCMode << 8U);
/* Set the Output Compare Polarity */
MODIFY_REG(tmpccer, TIM_CCER_CC4P, TIM_OCInitStruct->OCPolarity << 12U);
/* Set the Output State */
MODIFY_REG(tmpccer, TIM_CCER_CC4E, TIM_OCInitStruct->OCState << 12U);
if (IS_TIM_BREAK_INSTANCE(TIMx))
{
assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCNIdleState));
assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCIdleState));
/* Set the Output Idle state */
MODIFY_REG(tmpcr2, TIM_CR2_OIS4, TIM_OCInitStruct->OCIdleState << 6U);
}
/* Write to TIMx CR2 */
LL_TIM_WriteReg(TIMx, CR2, tmpcr2);
/* Write to TIMx CCMR2 */
LL_TIM_WriteReg(TIMx, CCMR2, tmpccmr2);
/* Set the Capture Compare Register value */
LL_TIM_OC_SetCompareCH4(TIMx, TIM_OCInitStruct->CompareValue);
/* Write to TIMx CCER */
LL_TIM_WriteReg(TIMx, CCER, tmpccer);
return SUCCESS;
}
/**
* @brief Configure the TIMx input channel 1.
* @param TIMx Timer Instance
* @param TIM_ICInitStruct pointer to the the TIMx input channel 1 configuration data structure
* @retval An ErrorStatus enumeration value:
* - SUCCESS: TIMx registers are de-initialized
* - ERROR: not applicable
*/
static ErrorStatus IC1Config(TIM_TypeDef *TIMx, LL_TIM_IC_InitTypeDef *TIM_ICInitStruct)
{
/* Check the parameters */
assert_param(IS_TIM_CC1_INSTANCE(TIMx));
assert_param(IS_LL_TIM_IC_POLARITY(TIM_ICInitStruct->ICPolarity));
assert_param(IS_LL_TIM_ACTIVEINPUT(TIM_ICInitStruct->ICActiveInput));
assert_param(IS_LL_TIM_ICPSC(TIM_ICInitStruct->ICPrescaler));
assert_param(IS_LL_TIM_IC_FILTER(TIM_ICInitStruct->ICFilter));
/* Disable the Channel 1: Reset the CC1E Bit */
TIMx->CCER &= (uint32_t)~TIM_CCER_CC1E;
/* Select the Input and set the filter and the prescaler value */
MODIFY_REG(TIMx->CCMR1,
(TIM_CCMR1_CC1S | TIM_CCMR1_IC1F | TIM_CCMR1_IC1PSC),
(TIM_ICInitStruct->ICActiveInput | TIM_ICInitStruct->ICFilter | TIM_ICInitStruct->ICPrescaler) >> 16U);
/* Select the Polarity and set the CC1E Bit */
MODIFY_REG(TIMx->CCER,
(TIM_CCER_CC1P | TIM_CCER_CC1NP),
(TIM_ICInitStruct->ICPolarity | TIM_CCER_CC1E));
return SUCCESS;
}
/**
* @brief Configure the TIMx input channel 2.
* @param TIMx Timer Instance
* @param TIM_ICInitStruct pointer to the the TIMx input channel 2 configuration data structure
* @retval An ErrorStatus enumeration value:
* - SUCCESS: TIMx registers are de-initialized
* - ERROR: not applicable
*/
static ErrorStatus IC2Config(TIM_TypeDef *TIMx, LL_TIM_IC_InitTypeDef *TIM_ICInitStruct)
{
/* Check the parameters */
assert_param(IS_TIM_CC2_INSTANCE(TIMx));
assert_param(IS_LL_TIM_IC_POLARITY(TIM_ICInitStruct->ICPolarity));
assert_param(IS_LL_TIM_ACTIVEINPUT(TIM_ICInitStruct->ICActiveInput));
assert_param(IS_LL_TIM_ICPSC(TIM_ICInitStruct->ICPrescaler));
assert_param(IS_LL_TIM_IC_FILTER(TIM_ICInitStruct->ICFilter));
/* Disable the Channel 2: Reset the CC2E Bit */
TIMx->CCER &= (uint32_t)~TIM_CCER_CC2E;
/* Select the Input and set the filter and the prescaler value */
MODIFY_REG(TIMx->CCMR1,
(TIM_CCMR1_CC2S | TIM_CCMR1_IC2F | TIM_CCMR1_IC2PSC),
(TIM_ICInitStruct->ICActiveInput | TIM_ICInitStruct->ICFilter | TIM_ICInitStruct->ICPrescaler) >> 8U);
/* Select the Polarity and set the CC2E Bit */
MODIFY_REG(TIMx->CCER,
(TIM_CCER_CC2P | TIM_CCER_CC2NP),
((TIM_ICInitStruct->ICPolarity << 4U) | TIM_CCER_CC2E));
return SUCCESS;
}
/**
* @brief Configure the TIMx input channel 3.
* @param TIMx Timer Instance
* @param TIM_ICInitStruct pointer to the the TIMx input channel 3 configuration data structure
* @retval An ErrorStatus enumeration value:
* - SUCCESS: TIMx registers are de-initialized
* - ERROR: not applicable
*/
static ErrorStatus IC3Config(TIM_TypeDef *TIMx, LL_TIM_IC_InitTypeDef *TIM_ICInitStruct)
{
/* Check the parameters */
assert_param(IS_TIM_CC3_INSTANCE(TIMx));
assert_param(IS_LL_TIM_IC_POLARITY(TIM_ICInitStruct->ICPolarity));
assert_param(IS_LL_TIM_ACTIVEINPUT(TIM_ICInitStruct->ICActiveInput));
assert_param(IS_LL_TIM_ICPSC(TIM_ICInitStruct->ICPrescaler));
assert_param(IS_LL_TIM_IC_FILTER(TIM_ICInitStruct->ICFilter));
/* Disable the Channel 3: Reset the CC3E Bit */
TIMx->CCER &= (uint32_t)~TIM_CCER_CC3E;
/* Select the Input and set the filter and the prescaler value */
MODIFY_REG(TIMx->CCMR2,
(TIM_CCMR2_CC3S | TIM_CCMR2_IC3F | TIM_CCMR2_IC3PSC),
(TIM_ICInitStruct->ICActiveInput | TIM_ICInitStruct->ICFilter | TIM_ICInitStruct->ICPrescaler) >> 16U);
/* Select the Polarity and set the CC3E Bit */
MODIFY_REG(TIMx->CCER,
(TIM_CCER_CC3P | TIM_CCER_CC3NP),
((TIM_ICInitStruct->ICPolarity << 8U) | TIM_CCER_CC3E));
return SUCCESS;
}
/**
* @brief Configure the TIMx input channel 4.
* @param TIMx Timer Instance
* @param TIM_ICInitStruct pointer to the the TIMx input channel 4 configuration data structure
* @retval An ErrorStatus enumeration value:
* - SUCCESS: TIMx registers are de-initialized
* - ERROR: not applicable
*/
static ErrorStatus IC4Config(TIM_TypeDef *TIMx, LL_TIM_IC_InitTypeDef *TIM_ICInitStruct)
{
/* Check the parameters */
assert_param(IS_TIM_CC4_INSTANCE(TIMx));
assert_param(IS_LL_TIM_IC_POLARITY(TIM_ICInitStruct->ICPolarity));
assert_param(IS_LL_TIM_ACTIVEINPUT(TIM_ICInitStruct->ICActiveInput));
assert_param(IS_LL_TIM_ICPSC(TIM_ICInitStruct->ICPrescaler));
assert_param(IS_LL_TIM_IC_FILTER(TIM_ICInitStruct->ICFilter));
/* Disable the Channel 4: Reset the CC4E Bit */
TIMx->CCER &= (uint32_t)~TIM_CCER_CC4E;
/* Select the Input and set the filter and the prescaler value */
MODIFY_REG(TIMx->CCMR2,
(TIM_CCMR2_CC4S | TIM_CCMR2_IC4F | TIM_CCMR2_IC4PSC),
(TIM_ICInitStruct->ICActiveInput | TIM_ICInitStruct->ICFilter | TIM_ICInitStruct->ICPrescaler) >> 8U);
/* Select the Polarity and set the CC2E Bit */
MODIFY_REG(TIMx->CCER,
(TIM_CCER_CC4P | TIM_CCER_CC4NP),
((TIM_ICInitStruct->ICPolarity << 12U) | TIM_CCER_CC4E));
return SUCCESS;
}
/**
* @}
*/
/**
* @}
*/
#endif /* TIM1 || TIM2 || TIM3 || TIM14 || TIM15 || TIM16 || TIM17 || TIM6 || TIM7 */
/**
* @}
*/
#endif /* USE_FULL_LL_DRIVER */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
the_stack_data/105196.c | #include <stdio.h>
int main(int argc, char ** argv)
{
(void)argc;
(void)argv;
// This is comment
printf("Hello, World!\n");
/* This is a block
comment
*/
return 0;
}
|
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.