Init basesystem source codes.
[staging/basesystem.git] / video_in_hal / otherservice / vehicle_parameter_library / library / src / VP_FuncCheck_CanRcv.c
1 /*
2  * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * @file  VP_FuncCheck_CanRcv.c
19  * @brief Get function existence API
20  */
21
22
23 /* ====================================================================== */
24 /* Header                                                                 */
25 /* ====================================================================== */
26 #include <assert.h>
27 #include <string.h>
28 #include <regex.h>
29
30 #include <other_service/VP_GetEnv.h>
31 #include "VP_FuncCheck_CanRcv_private.h"
32
33 /* ====================================================================== */
34 /* Enumeration types                                                      */
35 /* ====================================================================== */
36 typedef enum VPFuncTableDestIndexTag{
37     /*
38      *  Note.
39      *  This feature needs to be defined by the vendor.
40      */
41     VP_FUNC_TABLE_DEST_INDEX_A     ,
42     VP_FUNC_TABLE_DEST_INDEX_B     ,
43
44     VP_FUNC_TABLE_DEST_INDEX_MAX         /**< Number of choices (index maximum value: 1) */
45 } VP_FUNC_TABLE_DEST_INDEX;
46
47 typedef enum VPFuncTableBrandTag{
48     /*
49      *  Note.
50      *  This feature needs to be defined by the vendor.
51      */
52     VP_FUNC_TABLE_BRAND_A,
53     VP_FUNC_TABLE_BRAND_B,
54
55     VP_FUNC_TABLE_BRAND_INDEX_MAX        /**< Number of choices (index maximum value: 1) */
56 } VP_FUNC_TABLE_BRAND;
57
58 typedef enum VPFuncTableGradeLTag{
59     /*
60      *  Note.
61      *  This feature needs to be defined by the vendor.
62      */
63     VP_FUNC_TABLE_GRADE_A1,
64     VP_FUNC_TABLE_GRADE_A2,
65
66     VP_FUNC_TABLE_GRADE_A_INDEX_MAX      /**< Number of choices (index maximum value: 1) */
67 } VP_FUNC_TABLE_GRADE_A;
68
69 typedef enum VPFuncTableGradeTTag{
70     /*
71      *  Note.
72      *  This feature needs to be defined by the vendor.
73      */
74     VP_FUNC_TABLE_GRADE_B1,
75     VP_FUNC_TABLE_GRADE_B2,
76
77     VP_FUNC_TABLE_GRADE_B_INDEX_MAX      /**< Number of choices (index maximum value: 1) */
78 } VP_FUNC_TABLE_GRADE_B;
79
80 typedef enum VPFuncTableFuncTypeIndexTag{
81     VP_FUNC_TABLE_FUNC_TYPE_INDEX_UNKNOWN              , /**< Unknown function                           */
82     VP_FUNC_TABLE_FUNC_TYPE_INDEX_XM_AUDIO             , /**< XM Audio                                   */
83     VP_FUNC_TABLE_FUNC_TYPE_INDEX_VP_CANRCV__CWORD27_  , /**< _CWORD27_                                  */
84     VP_FUNC_TABLE_FUNC_TYPE_INDEX_WIFI_HOTSPOT         , /**< Wifi Hotspot                               */
85     VP_FUNC_TABLE_FUNC_TYPE_INDEX_RESTRICT_FUNCTION    , /**< Travel Restriction                         */
86     VP_FUNC_TABLE_FUNC_TYPE_INDEX_HD_DATA              , /**< HD Data                                    */
87     VP_FUNC_TABLE_FUNC_TYPE_INDEX_WIFI_5G              , /**< Wifi 5G                                    */
88
89     VP_FUNC_TABLE_FUNC_TYPE_INDEX_MAX                    /**< Number of choices (index maximum value: 1) */
90 } VP_FUNC_TABLE_FUNC_TYPE;
91
92 /** Processing definitions for CAN information availability */
93 typedef enum CANFuncCheckSwitchTag{
94     CAN_FUNC_CHEK_AVAILABLE   ,
95     CAN_FUNC_CHEK_UNAVAILABLE ,
96     CAN_FUNC_CHEK_COUNTRY_CODE
97 } CAN_FUNC_CHEK_SWITCH;
98
99
100
101 /**< Definition of number of functions (required for initial definition of function availability table) */
102
103 #define VP_FUNC_TABLE_FUNCTION_INDEX_MAX      ((unsigned int)7)
104
105 /* ====================================================================== */
106 /* Macro definitions                                                      */
107 /* ====================================================================== */
108 /* Definition for return value from string functions */
109 #define RET_STD_LIB_STRING_STR_CMP_OK ((int)0) /**< The return value of the strncmp. this value is returned when matched. */
110
111 /* Default index values */
112 #define DEFAULT_TABLE_INDEX_DEST        (VP_FUNC_TABLE_DEST_INDEX_A) /* Initial value changed by the specification which returns the setting of the belonging property when the undefined country code is gotten. */
113 #define DEFAULT_TABLE_INDEX_BRAND       (VP_FUNC_TABLE_BRAND_A)
114 #define DEFAULT_TABLE_INDEX_GRADE_A     (VP_FUNC_TABLE_GRADE_A1)
115 #define DEFAULT_TABLE_INDEX_GRADE_B     (VP_FUNC_TABLE_GRADE_B1)
116 #define DEFAULT_CAN_JUDGE_STATUS        (CAN_FUNC_CHEK_COUNTRY_CODE)
117
118 /* ====================================================================== */
119 /* Constant definitions                                                   */
120 /* ====================================================================== */
121
122 /* ====================================================================== */
123 /* Structures                                                             */
124 /* ====================================================================== */
125
126 /* ====================================================================== */
127 /* Internal function prototype declarations                               */
128 /* ====================================================================== */
129 #ifdef VP_FUNCCHECK_CANRCV_CANRCV_ACTIVATE
130 MT_STATIC u_int8_t     getResult_CanJudge( unsigned int idx_func     );
131 MT_STATIC unsigned int getIndexOfFunc(     u_int8_t     func         );
132 MT_STATIC unsigned int getIndexOfTable(    const char   vp_param_str[]  , const TABLE_INDEX_INFO  table_index_info[]           ,  unsigned int  info_size,  unsigned int  default_index );
133 MT_STATIC VP_FCCR_BOOL hasMultipleCoutnry( const char   dest_str[]      , const char              multiple_country_code_desig[] );
134 #endif
135 /* ====================================================================== */
136 /* Public function definitions                                            */
137 /* ====================================================================== */
138 /**
139  * @fn
140  * u_int8_t VP_FuncCheck_CanRcv( u_int8_t FunctionName )
141  * @brief Get function existence API(Public)
142  * @param[in]  (FunctionName)  Function Name (Number)
143  * @return FUNCTION_CHECK_RESULT_OK      :This function is available
144  *         FUNCTION_CHECK_RESULT_NG      :This function is unavailable
145  *         FUNCTION_CHECK_RESULT_UNKNOWN :This function does not exist
146  * @details  Read the function name as feature name specified in the argument, then return one of the 
147  *           "This function is available"/"This function is unavailable"/"This function does not exist"
148  *           of the feature as the following check-result:
149  *             - vehicle parameter:CAN information availability(destination package) judge
150  *             - vehicle parameter:country code
151  *             - Whether or not supported the features corresponding to the country code in this API
152  *           
153  *           When CAN information availability (destination package) in vehicle parameters is
154  *           "Control ON/OFF according to CAN information" or "Country code", return "This function is available"
155  *           if this function is called when the country code from CAN is unacquired or undetermined country code.
156  */
157 /* ====================================================================== */
158 u_int8_t VP_FuncCheck_CanRcv( u_int8_t FunctionName )
159 {
160 #ifndef VP_FUNCCHECK_CANRCV_CANRCV_ACTIVATE
161         u_int8_t        result;
162
163         switch(FunctionName) {
164             case XM_AUDIO:
165                 result = FUNCTION_CHECK_RESULT_NG;
166                 break;
167
168             case VP_CANRCV__CWORD27_:
169             case WIFI_HOTSPOT:
170             case AREA1_STD_TRAF_LIMIT:
171             case HD_DATA:
172             case WIFI_5G:
173                 result = FUNCTION_CHECK_RESULT_OK;
174                 break;
175             default:
176                 result = FUNCTION_CHECK_RESULT_UNKNOWN;
177                 break;
178         }
179
180         return result;
181 #else
182
183     /* ====================================================================== */
184     /* Internal table definition                                              */
185     /* ====================================================================== */
186     /** Vehicle Parameter "CAN information Support/Not Support"- processing selector translation table */
187     const TABLE_INDEX_INFO TABLE_STATUS_INFO_CAN_JUDGE[] =
188     {
189         { "available"   ,  CAN_FUNC_CHEK_AVAILABLE    }, // Yes
190         { "unavailable" ,  CAN_FUNC_CHEK_UNAVAILABLE  }, // None
191         { "CAN_judge"   ,  CAN_FUNC_CHEK_COUNTRY_CODE }, // Control ON/OFF according to CAN information
192         { "country_ID"  ,  CAN_FUNC_CHEK_COUNTRY_CODE }  // Country code
193     };
194
195     /* ====================================================================== */
196     /* Table Size Definition                                                  */
197     /* ====================================================================== */
198     const unsigned int LENGTHOF_TABLE_INDEX_INFO_CAN_JUDGE = ( sizeof(TABLE_STATUS_INFO_CAN_JUDGE ) / sizeof( TABLE_INDEX_INFO ) );
199
200     /* ====================================================================== */
201     /* Internal variable declarations                                         */
202     /* ====================================================================== */
203     u_int8_t result = FUNCTION_CHECK_RESULT_UNKNOWN;
204
205     unsigned int idx_func  = 0;
206
207     unsigned int can_judge_status  = CAN_FUNC_CHEK_COUNTRY_CODE;
208     char VP_canjudge[ VP_MAX_LENGTH ];
209     char VP_area[     VP_MAX_LENGTH ];
210
211     /* ====================================================================== */
212     /* Process                                                                */
213     /* ====================================================================== */
214     /* Get vehicle parameter */
215     VP_GetEnv( VEHICLEPARAMETERLIBRARY_AREA , &(VP_area[0]) );
216
217     DEBUG_PRINTF( "AREA     =  %s; " , VP_area )
218
219     /* Get feature name index */
220     idx_func = getIndexOfFunc( FunctionName );
221
222     DEBUG_PRINTF( "Function = %d; " , FunctionName )
223     DEBUG_PRINTF( "idx_func = %d\n" , idx_func     )
224
225     /* Judge as other than area1 because it is not a area1 */
226     if ( strncmp( VP_area, "AREA1", VP_MAX_LENGTH ) != RET_STD_LIB_STRING_STR_CMP_OK )
227     {
228         result = FUNCTION_CHECK_RESULT_OUT_OF_AREA1;
229     }
230     else
231     {
232         /* If the feature is unknown, it is judged to be unknown before checking CAN information. */
233         if ( VP_FUNC_TABLE_FUNC_TYPE_INDEX_UNKNOWN == idx_func )
234         {
235             result = FUNCTION_CHECK_RESULT_UNKNOWN;
236         }
237         else
238         {
239             /* Get vehicle parameter */ /* It is unnecessary to get the parameter every time, but because there is no process to check the change, it is gotten every time as a precaution. */
240             VP_GetEnv( VP__CWORD31__TELEMATICS_FUNCTION , &(VP_canjudge[0]) );
241
242             /* Choose processing according to CAN information Support/Not Support. */
243             can_judge_status =  getIndexOfTable(
244                             &(VP_canjudge[0]),
245                             &(TABLE_STATUS_INFO_CAN_JUDGE[0]),
246                             LENGTHOF_TABLE_INDEX_INFO_CAN_JUDGE,
247                             DEFAULT_CAN_JUDGE_STATUS
248                         );
249
250             DEBUG_PRINTF( "VP_canjudge = %s; ", VP_canjudge )
251
252             /* When judging from CAN information or country code */
253             if ( CAN_FUNC_CHEK_COUNTRY_CODE == can_judge_status )
254             {
255                 DEBUG_PRINT( "CAN judge : C_CODE or CAN_JUDGE" )
256                 result = getResult_CanJudge( idx_func );
257             }
258             else
259             {
260                 /* For available/unavailable */
261                 /* Standard travel restriction of AREA1 */
262                 if ( AREA1_STD_TRAF_LIMIT == idx_func )
263                 {
264                     result = FUNCTION_CHECK_RESULT_OK;
265                 }
266                 else
267                 {
268                     switch( can_judge_status )
269                     {
270                         case CAN_FUNC_CHEK_UNAVAILABLE:
271                             DEBUG_PRINT( "CAN judge : UNAVAILABLE" )
272                             result = FUNCTION_CHECK_RESULT_NG;
273                             break;
274
275                         case CAN_FUNC_CHEK_AVAILABLE:
276                         default: /* If the default value of canjudge_status are set correctly, the default cannot be selected */
277                             DEBUG_PRINT( "CAN judge : AVAILABLE" )
278                             result = FUNCTION_CHECK_RESULT_OK;
279                             break;
280                     }
281                 }
282             }
283         }
284     }
285     DEBUG_PRINTF( "RESULT = %d\n", result )
286
287     return result;
288
289 #endif
290 }
291
292 /* ====================================================================== */
293 /* Internal function definitions                                          */
294 /* ====================================================================== */
295 #ifdef VP_FUNCCHECK_CANRCV_CANRCV_ACTIVATE
296 /* ====================================================================== */
297 /**
298  * @brief      Get function existence in consideration of country code
299  * @detials    Internal-use functions - Processing when CAN information availability is "Country Code"
300  * @param[in]  idx_func Table index corresponding to the feature (takes as its argument the value after conversion to a table index, not the feature name)
301  * @return     Availability of the feature in current vehicle parameters
302  */
303 /* ====================================================================== */
304 MT_STATIC u_int8_t getResult_CanJudge( unsigned int idx_func )
305 {
306     /* ====================================================================== */
307     /* Internal constant definition                                           */
308     /* ====================================================================== */
309     static const char MULTIPLE_COUNTRY_CODE_DESIG[] = "^[0-9]{3}(;[0-9]{3})+;{0,1}"; /**< Regular Expression String for Multiple Countries (Attributes). Make sure at least two country codes are stored / delimited */
310
311     /* ====================================================================== */
312     /* Internal table definitions                                             */
313     /* ====================================================================== */
314     /** Feature table index conversion table (country code) */
315     const TABLE_INDEX_INFO TABLE_INDEX_INFO_DESTINATION[] =
316     {
317         /*
318          *  Note.
319          *  This feature needs to be defined by the vendor.
320          */
321         { "101" ,  VP_FUNC_TABLE_DEST_INDEX_A     }, // Detination A
322         { "102" ,  VP_FUNC_TABLE_DEST_INDEX_B     }  // Detination B
323     };
324
325     /** @todo The consideration. For the feature table by country code, if it can be summarized the GRADE A1/GRADE A2 and GRADE B1/GRADE B2,
326               It can be also summarized the translation table.
327               However, it must be able to guarantee that there are no differences in the table format in L/T. */
328     /** Index Ttranslation Table for feature availability table (for grade A) */
329     const TABLE_INDEX_INFO TABLE_INDEX_INFO_GRADE_A[] =
330     {
331         /*
332          *  Note.
333          *  This feature needs to be defined by the vendor.
334          */
335         { "A1" ,    VP_FUNC_TABLE_GRADE_A1 }, // GRADE A1
336         { "A2" ,    VP_FUNC_TABLE_GRADE_A2 }  // GRADE A2
337     };
338
339     /** Index Translation Table for feature availability table (for grade B) */
340     const TABLE_INDEX_INFO TABLE_INDEX_INFO_GRADE_B[] =
341     {
342         /*
343          *  Note.
344          *  This feature needs to be defined by the vendor.
345          */
346         { "B1" ,    VP_FUNC_TABLE_GRADE_B1 }, // GRADE B1
347         { "B2" ,    VP_FUNC_TABLE_GRADE_B2 }, // GRADE B2
348     };
349
350     /** Index Translation Table for feature availability table (brand) */
351     const TABLE_INDEX_INFO TABLE_INDEX_INFO_BRAND[] =
352     {
353         /*
354          *  Note.
355          *  This feature needs to be defined by the vendor.
356          */
357         { "A" ,  VP_FUNC_TABLE_BRAND_A }, // BRAND A
358         { "B" ,  VP_FUNC_TABLE_BRAND_B }  // BRAND B
359     };
360
361     /* ====================================================================== */
362     /**
363      * @brief   Feature availability table for BRAND A
364      * @details Array of type u_int8_t accessed by the following index
365      */
366     /* ====================================================================== */
367     const u_int8_t VP_FUNC_CHECK_CANRCV_TABLE_A[ VP_FUNC_TABLE_DEST_INDEX_MAX     ]
368                                                [ VP_FUNC_TABLE_GRADE_A_INDEX_MAX  ]
369                                                [ VP_FUNC_TABLE_FUNCTION_INDEX_MAX ] =
370     {
371         /*
372          *  Note.
373          *  This feature needs to be defined by the vendor.
374          */
375         /* Destination A */
376         {
377             // Unknown                     ,  XM Audio                ,  _CWORD27_               ,  Wifi HotSpot            ,  Travel Restriction      ,  HD Data                    Wifi 5G
378             { FUNCTION_CHECK_RESULT_UNKNOWN,  FUNCTION_CHECK_RESULT_OK,  FUNCTION_CHECK_RESULT_OK,  FUNCTION_CHECK_RESULT_OK,  FUNCTION_CHECK_RESULT_OK,  FUNCTION_CHECK_RESULT_OK,  FUNCTION_CHECK_RESULT_OK }, // GRADE A1
379             { FUNCTION_CHECK_RESULT_UNKNOWN,  FUNCTION_CHECK_RESULT_OK,  FUNCTION_CHECK_RESULT_OK,  FUNCTION_CHECK_RESULT_OK,  FUNCTION_CHECK_RESULT_OK,  FUNCTION_CHECK_RESULT_NG,  FUNCTION_CHECK_RESULT_OK }  // GRADE A2
380         },
381
382         /* Destination B */
383         {
384             { FUNCTION_CHECK_RESULT_UNKNOWN,  FUNCTION_CHECK_RESULT_NG,  FUNCTION_CHECK_RESULT_OK,  FUNCTION_CHECK_RESULT_OK,  FUNCTION_CHECK_RESULT_OK,  FUNCTION_CHECK_RESULT_OK,  FUNCTION_CHECK_RESULT_OK }, // GRADE A1
385             { FUNCTION_CHECK_RESULT_UNKNOWN,  FUNCTION_CHECK_RESULT_NG,  FUNCTION_CHECK_RESULT_OK,  FUNCTION_CHECK_RESULT_OK,  FUNCTION_CHECK_RESULT_OK,  FUNCTION_CHECK_RESULT_NG,  FUNCTION_CHECK_RESULT_NG }  // GRADE A2
386         }
387     };
388
389     /* ====================================================================== */
390     /**
391      * @brief  Feature availability table for BRAND B
392      */
393     /* ====================================================================== */
394     const u_int8_t VP_FUNC_CHECK_CANRCV_TABLE_B[ VP_FUNC_TABLE_DEST_INDEX_MAX     ]
395                                                [ VP_FUNC_TABLE_GRADE_B_INDEX_MAX  ]
396                                                [ VP_FUNC_TABLE_FUNCTION_INDEX_MAX ] =
397     {
398         /*
399          *  Note.
400          *  This feature needs to be defined by the vendor.
401          */
402         /* Destination A */
403         {
404             // Unknown                     ,  XM Audio                ,  _CWORD27_               ,  Wifi HotSpot            ,  Travel Restriction      ,  HD Data                 ,  Wifi 5G
405             { FUNCTION_CHECK_RESULT_UNKNOWN,  FUNCTION_CHECK_RESULT_OK,  FUNCTION_CHECK_RESULT_OK,  FUNCTION_CHECK_RESULT_OK,  FUNCTION_CHECK_RESULT_OK,  FUNCTION_CHECK_RESULT_OK,  FUNCTION_CHECK_RESULT_OK }, // GRADE B1
406             { FUNCTION_CHECK_RESULT_UNKNOWN,  FUNCTION_CHECK_RESULT_OK,  FUNCTION_CHECK_RESULT_OK,  FUNCTION_CHECK_RESULT_OK,  FUNCTION_CHECK_RESULT_OK,  FUNCTION_CHECK_RESULT_NG,  FUNCTION_CHECK_RESULT_OK }, // GRADE B2
407         },
408
409         /* Detination B */
410         {
411             { FUNCTION_CHECK_RESULT_UNKNOWN,  FUNCTION_CHECK_RESULT_NG,  FUNCTION_CHECK_RESULT_OK,  FUNCTION_CHECK_RESULT_OK,  FUNCTION_CHECK_RESULT_OK,  FUNCTION_CHECK_RESULT_OK,  FUNCTION_CHECK_RESULT_OK }, // GRADE B1
412             { FUNCTION_CHECK_RESULT_UNKNOWN,  FUNCTION_CHECK_RESULT_NG,  FUNCTION_CHECK_RESULT_OK,  FUNCTION_CHECK_RESULT_OK,  FUNCTION_CHECK_RESULT_OK,  FUNCTION_CHECK_RESULT_NG,  FUNCTION_CHECK_RESULT_NG }, // GRADE B2
413         }
414     };
415
416     /* ====================================================================== */
417     /* Table Size Definitions                                                 */
418     /* ====================================================================== */
419     const unsigned int SIZE_TABLE_INDEX_INFO_BRAND       = ( sizeof(TABLE_INDEX_INFO_BRAND      ) / sizeof( TABLE_INDEX_INFO ) );
420     const unsigned int SIZE_TABLE_INDEX_INFO_GRADE_A     = ( sizeof(TABLE_INDEX_INFO_GRADE_A    ) / sizeof( TABLE_INDEX_INFO ) );
421     const unsigned int SIZE_TABLE_INDEX_INFO_GRADE_B     = ( sizeof(TABLE_INDEX_INFO_GRADE_B    ) / sizeof( TABLE_INDEX_INFO ) );
422     const unsigned int SIZE_TABLE_INDEX_INFO_DESTINATION = ( sizeof(TABLE_INDEX_INFO_DESTINATION) / sizeof( TABLE_INDEX_INFO ) );
423
424     /* ====================================================================== */
425     /* Variable declarations                                                  */
426     /* ====================================================================== */
427     u_int8_t result = FUNCTION_CHECK_RESULT_UNKNOWN;
428
429     VP_FCCR_BOOL isMultipleCountry = B_FALSE;
430
431     unsigned int idx_dest  = 0;
432     unsigned int idx_brand = 0;
433     unsigned int idx_grade = 0;
434
435     char VP_destination[ VP_MAX_LENGTH ];
436     char VP_brand[       VP_MAX_LENGTH ];
437     char VP_grade[       VP_MAX_LENGTH ];
438
439     /* ====================================================================== */
440     /* Static assertion                                                       */
441     /* ====================================================================== */
442     /* The following are expected to be identical */
443     VP_DEBUG_STATIC_ASSERT( SIZE_TABLE_INDEX_INFO_BRAND   == VP_FUNC_TABLE_BRAND_INDEX_MAX   )
444     VP_DEBUG_STATIC_ASSERT( SIZE_TABLE_INDEX_INFO_GRADE_A == VP_FUNC_TABLE_GRADE_A_INDEX_MAX )
445
446     /* Country code does not match because there are multiple countries. */
447     VP_DEBUG_STATIC_ASSERT( VP_FUNC_TABLE_DEST_INDEX_MAX > SIZE_TABLE_INDEX_INFO_DESTINATION )
448
449     /* ====================================================================== */
450     /* Process                                                                */
451     /* ====================================================================== */
452
453     /* Argument check */
454     if ( VP_FUNC_TABLE_FUNC_TYPE_INDEX_MAX <= idx_func )
455     {
456         DEBUG_PRINTF( "ERROR : tebale index overed idx_func = %d\n", idx_func )
457
458         // Return unknown if the table size is exceeded. (However, this function can be called only from the API at the moment.)
459         result = FUNCTION_CHECK_RESULT_UNKNOWN;
460     }
461     else
462     {
463
464         /* Get vehicle parameter */
465         VP_GetEnv( VP__CWORD31__DESTINATION, &(VP_destination[0]) );
466         VP_GetEnv( VEHICLEPARAMETERLIBRARY_BRAND           , &(VP_brand[0])       );
467         VP_GetEnv( VP_VEHICLEPARAMETERLIBRARY_GRADE        , &(VP_grade[0])       );
468
469         DEBUG_PRINTF( "VP_destination = %s\n", VP_destination )
470
471         /* Append NULL at the end just in case. (so as not to cause any problems using the strlen or regcomp later) */
472         VP_destination[ VP_MAX_LENGTH - 1 ] = '\0';
473         VP_brand[       VP_MAX_LENGTH - 1 ] = '\0';
474         VP_grade[       VP_MAX_LENGTH - 1 ] = '\0';
475
476         /* Check if the country code is NULL */
477         if ( VP_destination[0] == '\0' )
478         {
479             /* If NULL, set the index for the country code of the US. */
480             idx_dest = VP_FUNC_TABLE_DEST_INDEX_A;
481             DEBUG_PRINTF( "[debug]idx_dest = %d\n", idx_dest )
482         }
483         else
484         {
485             /* Check whether it is a member (multiple countries) */
486             isMultipleCountry = hasMultipleCoutnry( &(VP_destination[0]), &(MULTIPLE_COUNTRY_CODE_DESIG[0]) );
487
488             /* Get the index for a country code */
489             if ( B_TRUE == isMultipleCountry )
490             {
491                 /* If it is dependent (multiple countries), set the index for the country code of the dependent */
492                 DEBUG_PRINT( "isMultipleCountry = TRUE" )
493
494                 idx_dest = VP_FUNC_TABLE_DEST_INDEX_B;
495             }
496             else
497             {
498                 /* If it is not dependent (multiple countries), it searches the translation table and sets the index. */
499                 DEBUG_PRINT( "isMultipleCountry = FALSE" )
500
501                 idx_dest = getIndexOfTable( &(VP_destination[0]), &(TABLE_INDEX_INFO_DESTINATION[0]), SIZE_TABLE_INDEX_INFO_DESTINATION, DEFAULT_TABLE_INDEX_DEST );
502             }
503         }
504         DEBUG_PRINTF( "idx_dest = %d\n", idx_dest )
505
506         /* Get brand index */
507         idx_brand = getIndexOfTable(    &(VP_brand[0])      , &(TABLE_INDEX_INFO_BRAND[0])      , SIZE_TABLE_INDEX_INFO_BRAND      , DEFAULT_TABLE_INDEX_BRAND );
508
509         /*
510          * Get grade index
511          * Setting Defaults for each brand
512          * e.g. The default is A, so if it is not B, it is determined to be A.
513          */
514         if ( VP_FUNC_TABLE_BRAND_B == idx_brand )
515         {
516             DEBUG_PRINT( "idx_brand = B")
517
518             idx_grade = getIndexOfTable( &(VP_grade[0])     , &(TABLE_INDEX_INFO_GRADE_B[0])    , SIZE_TABLE_INDEX_INFO_GRADE_B    , DEFAULT_TABLE_INDEX_GRADE_B );
519
520             /* Table access */
521             result = VP_FUNC_CHECK_CANRCV_TABLE_B[idx_dest][idx_grade][idx_func];
522
523         }
524         else
525         {
526             DEBUG_PRINT( "idx_brand = A")
527
528             idx_grade = getIndexOfTable( &(VP_grade[0])     , &(TABLE_INDEX_INFO_GRADE_A[0])    , SIZE_TABLE_INDEX_INFO_GRADE_A    , DEFAULT_TABLE_INDEX_GRADE_A );
529
530             /* Table access */
531             result = VP_FUNC_CHECK_CANRCV_TABLE_A[idx_dest][idx_grade][idx_func];
532
533         }
534
535         //DEBUG_PRINTF( "RESULT = %d\n", result )
536     }
537
538     return result;
539 }
540
541
542 /* ====================================================================== */
543 /**
544  * @brief      Feature-Table Index Translation Function
545  * @detials    Internal-use functions. It is translate the feature definition number to an index for the table.
546  * @param[in]  Feature name defined by the func define
547  * @return     The table index corresponding to the feature. If the given country code is invalid, return the index given by default_idx
548  */
549  /* ====================================================================== */
550 MT_STATIC unsigned int getIndexOfFunc(  u_int8_t func )
551 {
552     /* ====================================================================== */
553     /* Internal table definitions                                             */
554     /* ====================================================================== */
555     /** Index translation table for feature table (Features) */
556     const VP_FUNC_TABLE_FUNC_TYPE GET_INDEX_OF_FUNC[] = {
557         VP_FUNC_TABLE_FUNC_TYPE_INDEX_UNKNOWN              , //#define VP_FUNCCHECK_CANRCV_UNKNOWN ((u_int8_t)0)       /* Unknown Features                             */
558         VP_FUNC_TABLE_FUNC_TYPE_INDEX_XM_AUDIO             , //#define XM_AUDIO                    ((u_int8_t)1)       /* XM Audio                                     */
559         VP_FUNC_TABLE_FUNC_TYPE_INDEX_VP_CANRCV__CWORD27_  , //#define _CWORD27_                   ((u_int8_t)3)       /* _CWORD27_                                    */
560         VP_FUNC_TABLE_FUNC_TYPE_INDEX_WIFI_HOTSPOT         , //#define WIFI_HOTSPOT                ((u_int8_t)4)       /* WiFi HotSpot                                 */
561         VP_FUNC_TABLE_FUNC_TYPE_INDEX_RESTRICT_FUNCTION    , //#define AREA1_STD_TRAF_LIMIT        ((u_int8_t)5)       /* Standard Travel Restriction of AREA1         */
562         VP_FUNC_TABLE_FUNC_TYPE_INDEX_HD_DATA              , //#define HD_DATA                     ((u_int8_t)6)       /* HD Data (Include traffic)                    */
563         VP_FUNC_TABLE_FUNC_TYPE_INDEX_WIFI_5G                //#define WIFI_5G                     ((u_int8_t)7)       /* WiFi 5G                                      */
564
565     };
566
567
568     /* ====================================================================== */
569     /* Variable declarations                                                  */
570     /* ====================================================================== */
571     const unsigned int index_table_size = sizeof( GET_INDEX_OF_FUNC ) / sizeof( VP_FUNC_TABLE_FUNC_TYPE );
572
573     u_int8_t table_index = VP_FUNC_TABLE_FUNC_TYPE_INDEX_UNKNOWN;
574
575     /* ====================================================================== */
576     /* Static assertions                                                      */
577     /* ====================================================================== */
578     /* In the current configuration, the feature's defined value and index match, so the translation table size should also match (remove this assertion if there is no match) */
579     VP_DEBUG_STATIC_ASSERT( index_table_size ==  VP_FUNC_TABLE_FUNCTION_INDEX_MAX )
580
581     /* Translation tables or the enumeration pair (VP_FUNC_TABLE_FUNC_TYPE) must also be modified when the definition value changes.
582        It may also be changed, added, or deleted following asserts as appropriate according to the defined value. */
583     VP_DEBUG_STATIC_ASSERT( XM_AUDIO             == VP_FUNC_TABLE_FUNC_TYPE_INDEX_XM_AUDIO            )
584
585     VP_DEBUG_STATIC_ASSERT( VP_CANRCV__CWORD27_  == VP_FUNC_TABLE_FUNC_TYPE_INDEX_VP_CANRCV__CWORD27_ )
586     VP_DEBUG_STATIC_ASSERT( WIFI_HOTSPOT         == VP_FUNC_TABLE_FUNC_TYPE_INDEX_WIFI_HOTSPOT        )
587     VP_DEBUG_STATIC_ASSERT( AREA1_STD_TRAF_LIMIT == VP_FUNC_TABLE_FUNC_TYPE_INDEX_RESTRICT_FUNCTION   )
588     VP_DEBUG_STATIC_ASSERT( HD_DATA              == VP_FUNC_TABLE_FUNC_TYPE_INDEX_HD_DATA             )
589     VP_DEBUG_STATIC_ASSERT( WIFI_5G              == VP_FUNC_TABLE_FUNC_TYPE_INDEX_WIFI_5G             )
590
591
592     /* ====================================================================== */
593     /* Process                                                                */
594     /* ====================================================================== */
595
596     /* Argument check: Treat as unknown feature if it is larger than index translation table */
597     if ( index_table_size <= func )
598     {
599         table_index = VP_FUNC_TABLE_FUNC_TYPE_INDEX_UNKNOWN;
600     }
601     else
602     {
603         table_index = (u_int8_t)(GET_INDEX_OF_FUNC[func]);
604     }
605
606     return table_index;
607
608 }
609
610 /* ====================================================================== */
611 /**
612  * @brief      Vehicle parameter string to integer conversion function
613  * @detials    Internal-use function. Convert the given string (vehicle parameter) into an index for the table.
614  *             The value gotten using VP_GetEnv() is assumed. Thus, the maximum length is VP_MAX_LENGTH.
615  *             Return the value set in default_index if the conversion is failed.
616  * @param[in]  vp_param_str      String as source of convetion to the table index
617  * @param[in]  table_index_info  String corresponding to table index and an array of structs with table indexes set
618  * @param[in]  info_size         Size of the table_index_info array
619  * @param[in]  default_index     Default index. Return this value if none of table_index_info matches
620  * @return     The table index corresponding to the vehicle parameter string given by the argument. Return the value given by the default_index argument if the given country code is invalid.
621  */
622  /* ====================================================================== */
623 MT_STATIC unsigned int getIndexOfTable( const char vp_param_str[],  const TABLE_INDEX_INFO table_index_info[], unsigned int info_size, unsigned int  default_index )
624 {
625     unsigned int table_index = 0;
626
627     table_index = default_index; /* Set as initial value so that it can return the set default if it is unknown */
628
629     //DEBUG_PRINTF("info_size = %d\n", info_size)
630
631     /* NULL checking */
632     if ( NULL != vp_param_str )
633     {
634         if ( NULL != table_index_info )
635         {
636             unsigned int i = 0;
637
638             for ( i = 0; i < info_size; i++ )
639             {
640                 if ( RET_STD_LIB_STRING_STR_CMP_OK == strncmp( &(vp_param_str[0]), &((table_index_info[i]).code_str[0]), VP_MAX_LENGTH ) )
641                 {
642                     table_index = (table_index_info[i]).index;
643
644                     break;
645                 }
646             }
647         }
648         else
649         {
650             DEBUG_PRINT( "ERROR!! the Bad Teble overd." )
651         }
652     }
653
654     return table_index;
655 }
656
657 /* ====================================================================== */
658 /**
659  * @brief      Function to check whether country code is multiple countries or not
660  * @detials    Internal-use functions. Check if the country code given in the argument contains more than one country.
661  *             The determination whether multiple country code or not shall be true if it exactly matches the specified 
662  *             regular expression which is a characteristic of multiple countries.
663  *             The exact match determination shall be the exact match if the length of the matched character matches
664  *             the length of the character passed in the argument.
665  * @param[in]  dest_str                     Country code string. The value gotten using VP_GetEnv() is assumed. Therefore, the maximum length is VP_MAX_LENGTH.
666  * @param[in]  multiple_country_code_desig  String for determining multiple country codes. Regular expression strings if a regular expression library is used. Otherwise, a single-character string representing the delimiter.
667  *                                          If it gets trapped inside a function, it will have to stub the regcomp during function unit tests, which is very cumbersome and can be removed as arguments.
668  * @return     True if country code indicates multiple countries, otherwise false
669  */
670 /* ====================================================================== */
671 MT_STATIC VP_FCCR_BOOL hasMultipleCoutnry( const char dest_str[], const char multiple_country_code_desig[] )
672 {
673     /* ====================================================================== */
674     /* Variable declarations                                                  */
675     /* ====================================================================== */
676     VP_FCCR_BOOL isMultiple = B_FALSE;
677
678     /* ====================================================================== */
679     /* Processing                                                             */
680     /* ====================================================================== */
681
682     /* NULL checking for arguments */
683     if ( ( NULL != dest_str ) && ( NULL != multiple_country_code_desig ) )
684     {
685         regex_t preg;
686
687         if ( 0 == regcomp( &preg, multiple_country_code_desig, REG_EXTENDED ) )
688         {
689             regmatch_t pmatch = { 0, 0 };
690
691             if ( REG_NOMATCH != regexec( &preg, &(dest_str[0]), 1, &pmatch, 0) )
692             {
693                 /** @note Exactly match is considered if the end-of-match offset matches the string length.
694                   *       Assumed that it should not be used as the end-of-line character so that "$" is not included in the C base character set.
695                   */
696                 if ( (strnlen( dest_str, VP_MAX_LENGTH ) == (unsigned int)(pmatch.rm_eo) ) )
697                 {
698                     isMultiple = B_TRUE;
699                 }
700                 else
701                 {
702                     isMultiple = B_FALSE;
703                 }
704
705                 DEBUG_PRINT( "FOUND" )
706             }
707             else
708             {
709                 isMultiple = B_FALSE;
710
711                 DEBUG_PRINT( "NOT FOUND" )
712             }
713
714             regfree( &preg );
715         }
716         else
717         {
718             /* In the case of a library error,
719              * return false so that the default value that is set by high layer works.
720              */
721
722             /** @todo Should output using FRAMEWORKUNIFIEDLOG for library errors? */
723             isMultiple = B_FALSE;
724
725             DEBUG_PRINT( "FOUND" )
726         }
727     }
728
729     return isMultiple;
730
731 }
732 #endif