1 /******************************************************************************* 2 **+--------------------------------------------------------------------------+** 3 **| |** 4 **| Copyright 1998-2008 Texas Instruments, Inc. - http://www.ti.com/ |** 5 **| |** 6 **| Licensed under the Apache License, Version 2.0 (the "License"); |** 7 **| you may not use this file except in compliance with the License. |** 8 **| You may obtain a copy of the License at |** 9 **| |** 10 **| http://www.apache.org/licenses/LICENSE-2.0 |** 11 **| |** 12 **| Unless required by applicable law or agreed to in writing, software |** 13 **| distributed under the License is distributed on an "AS IS" BASIS, |** 14 **| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |** 15 **| See the License for the specific language governing permissions and |** 16 **| limitations under the License. |** 17 **| |** 18 **+--------------------------------------------------------------------------+** 19 *******************************************************************************/ 20 21 /**************************************************************************/ 22 /* */ 23 /* MODULE: proc_main.c */ 24 /* PURPOSE: Supplicant Initialization */ 25 /* */ 26 /**************************************************************************/ 27 #include <string.h> 28 #include <stdlib.h> 29 #include <stdio.h> 30 #include <errno.h> 31 32 #include <fcntl.h> /* for O_WRONLY*/ 33 34 #include <sys/time.h> 35 #include <sys/resource.h> 36 #include <unistd.h> 37 38 typedef unsigned int UINT32; /*nick*/ 39 40 #include "osTIType.h" 41 42 #include "TI_SupplicantStub.h" 43 #include "TI_IPC_Api.h" 44 #include "ipc_event.h" 45 46 47 48 extern tiBOOL g_bTerminate ; 49 50 int main(int argc, char ** argv) 51 { 52 #ifdef TI_DBG 53 struct rlimit rLimit; 54 55 rLimit.rlim_cur = 1024*1024; 56 rLimit.rlim_max = 1024*1024; 57 58 setrlimit(RLIMIT_CORE,&rLimit); 59 #endif 60 61 FILE *f = fopen("/dev/console", "w" ); 62 int hfile_output = -1; 63 if( !f ) 64 fprintf(stderr, "/dev/console open failed: %d(%s)\n", errno, strerror(errno) ); 65 else 66 { 67 if( dup2( f->_fileno, 1 ) == -1 ) 68 { 69 fprintf(f, "dup2(hfile, 1) failed: %d(%s)\n", errno, strerror(errno) ); 70 } 71 if( dup2( f->_fileno, 2 ) == -1 ) 72 { 73 fprintf(f, "dup2(hfile, 2) failed: %d(%s)\n", errno, strerror(errno) ); 74 } 75 } 76 77 if( argc == 2 ) 78 { 79 hfile_output = open((char *) argv[1], O_WRONLY ); 80 if( hfile_output == -1 ) 81 { 82 perror((char *) argv[1]); 83 goto exit; 84 } 85 if( dup2( 1, hfile_output ) == -1 ) 86 { 87 fprintf(stderr, "dup2(1, hfile_output) failed: %d(%s)\n", errno, strerror(errno) ); 88 } 89 if( dup2( 2, hfile_output ) == -1 ) 90 { 91 fprintf(stderr, "dup2(2, hfile_output) failed: %d(%s)\n", errno, strerror(errno) ); 92 } 93 } 94 /* Open socket channel for CLI configuration */ 95 if(cnfg_open() != 0) 96 { 97 printf("\nCan't initialize configure socket\n"); 98 return -1; 99 } 100 101 if(IPC_Init()) 102 { 103 printf("---main(): ERROR IPC init\n"); 104 105 } 106 107 IPC_CONFIG_PARAMS *pRegistry_config = (IPC_CONFIG_PARAMS*)malloc(sizeof(IPC_CONFIG_PARAMS)); 108 109 pRegistry_config->F_ConfigNotification = SendDataStub; 110 111 if(IPC_RegisterConfig((void*)pRegistry_config, 112 sizeof(IPC_CONFIG_PARAMS))) 113 { 114 printf("---main(): ERROR registration CONFIG Messages\n"); 115 } 116 free(pRegistry_config); 117 118 119 for(;g_bTerminate != TRUE;) 120 { 121 usleep(1000000); /* sleep 1 sec*/ 122 } 123 124 exit: 125 if( f > 0 ) 126 fclose( f ); 127 if( hfile_output > 0 ) 128 close( hfile_output ); 129 return 0; 130 } 131 132 133