• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  * Description: common function of shell cmds
15  * Author: none
16  * Create: 2020
17  */
18 
19 #include "lwip/nettool/utility.h"
20 
21 #if LWIP_ENABLE_BASIC_SHELL_CMD
22 
convert_string_to_hex(const char * src,unsigned char * dest)23 int convert_string_to_hex(const char *src, unsigned char *dest)
24 {
25   *dest = 0;
26   while (*src) {
27     *dest = (unsigned char)((*dest << 4) & 0xFF);
28     if ((*src >= '0') && (*src <= '9')) {   /* between 0 to 9 */
29       *dest |= (unsigned char)(*src - '0');
30     } else if ((*src >= 'A' && *src <= 'F')) { /* between A to F */
31       *dest |= (unsigned char)((*src - 'A') + 10);
32     } else if ((*src >= 'a' && *src <= 'f')) { /* between a to f */
33       *dest |= (unsigned char)((*src - 'a') + 10);
34     } else {
35       return -1;
36     }
37     ++src;
38   }
39 
40   return 0;
41 }
42 
43 #endif /* LWIP_ENABLE_BASIC_SHELL_CMD */
44 
lwip_isdigitstr(const s8_t * str)45 s32_t lwip_isdigitstr(const s8_t* str)
46 {
47   while(*str) {
48     if((*str >= '0') && (*str <= '9')) {
49       ++str;
50       continue;
51     }
52 
53     return -1;
54   }
55 
56   return 0;
57 }
58