RDK Documentation (Open Sourced RDK Components)
wifi_linux_wireless.c
1 /*
2 * If not stated otherwise in this file or this component's Licenses.txt file the
3 * following copyright and licenses apply:
4 *
5 * Copyright 2022 RDK Management
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19 //#include <linux/wireless.h>
20 #include <errno.h>
21 #include <stdbool.h>
22 #include <sys/ioctl.h>
23 #include <sys/types.h>
24 #include <sys/socket.h>
25 #include <string.h>
26 #include <unistd.h>
27 #include <linux/wireless.h>
28 
29 #include <wifi_common_hal.h>
30 #include "wifi_log.h"
31 
32 bool wifi_interfaceIsWireless(const char * ifname)
33 {
34  bool hasWirelessExtensions = false;
35 
36  int soc = socket(AF_INET, SOCK_STREAM, 0);
37  if (soc == -1) {
38  WIFI_LOG_WARN("error creating socket while looking for wireless extensions. %d\n",
39  errno);
40  return false;
41  }
42  else {
43  struct iwreq req;
44  memset(&req, 0, sizeof(req));
45  strncpy(req.ifr_name, ifname, IFNAMSIZ);
46 
47  if (ioctl(soc, SIOCGIWNAME, &req) != -1)
48  hasWirelessExtensions = true;
49 
50  close(soc);
51  }
52 
53  return hasWirelessExtensions;
54 }