wps_dev_attr.c

Go to the documentation of this file.
00001 
00016 #include "includes.h"
00017 
00018 #include "common.h"
00019 #include "wps_i.h"
00020 #include "wps_dev_attr.h"
00021 
00022 
00023 static int wps_build_manufacturer(struct wps_device_data *dev,
00024                                   struct wpabuf *msg)
00025 {
00026         size_t len;
00027         wpa_printf(MSG_DEBUG, "WPS:  * Manufacturer");
00028         wpabuf_put_be16(msg, ATTR_MANUFACTURER);
00029         len = dev->manufacturer ? os_strlen(dev->manufacturer) : 0;
00030         if (len == 0) {
00031                 /*
00032                  * Some deployed WPS implementations fail to parse zero-length
00033                  * attributes. As a workaround, send a null character if the
00034                  * device attribute string is empty.
00035                  */
00036                 wpabuf_put_be16(msg, 1);
00037                 wpabuf_put_u8(msg, '\0');
00038         } else {
00039                 wpabuf_put_be16(msg, len);
00040                 wpabuf_put_data(msg, dev->manufacturer, len);
00041         }
00042         return 0;
00043 }
00044 
00045 
00046 static int wps_build_model_name(struct wps_device_data *dev,
00047                                 struct wpabuf *msg)
00048 {
00049         size_t len;
00050         wpa_printf(MSG_DEBUG, "WPS:  * Model Name");
00051         wpabuf_put_be16(msg, ATTR_MODEL_NAME);
00052         len = dev->model_name ? os_strlen(dev->model_name) : 0;
00053         if (len == 0) {
00054                 /*
00055                  * Some deployed WPS implementations fail to parse zero-length
00056                  * attributes. As a workaround, send a null character if the
00057                  * device attribute string is empty.
00058                  */
00059                 wpabuf_put_be16(msg, 1);
00060                 wpabuf_put_u8(msg, '\0');
00061         } else {
00062                 wpabuf_put_be16(msg, len);
00063                 wpabuf_put_data(msg, dev->model_name, len);
00064         }
00065         return 0;
00066 }
00067 
00068 
00069 static int wps_build_model_number(struct wps_device_data *dev,
00070                                   struct wpabuf *msg)
00071 {
00072         size_t len;
00073         wpa_printf(MSG_DEBUG, "WPS:  * Model Number");
00074         wpabuf_put_be16(msg, ATTR_MODEL_NUMBER);
00075         len = dev->model_number ? os_strlen(dev->model_number) : 0;
00076         if (len == 0) {
00077                 /*
00078                  * Some deployed WPS implementations fail to parse zero-length
00079                  * attributes. As a workaround, send a null character if the
00080                  * device attribute string is empty.
00081                  */
00082                 wpabuf_put_be16(msg, 1);
00083                 wpabuf_put_u8(msg, '\0');
00084         } else {
00085                 wpabuf_put_be16(msg, len);
00086                 wpabuf_put_data(msg, dev->model_number, len);
00087         }
00088         return 0;
00089 }
00090 
00091 
00092 static int wps_build_serial_number(struct wps_device_data *dev,
00093                                    struct wpabuf *msg)
00094 {
00095         size_t len;
00096         wpa_printf(MSG_DEBUG, "WPS:  * Serial Number");
00097         wpabuf_put_be16(msg, ATTR_SERIAL_NUMBER);
00098         len = dev->serial_number ? os_strlen(dev->serial_number) : 0;
00099         if (len == 0) {
00100                 /*
00101                  * Some deployed WPS implementations fail to parse zero-length
00102                  * attributes. As a workaround, send a null character if the
00103                  * device attribute string is empty.
00104                  */
00105                 wpabuf_put_be16(msg, 1);
00106                 wpabuf_put_u8(msg, '\0');
00107         } else {
00108                 wpabuf_put_be16(msg, len);
00109                 wpabuf_put_data(msg, dev->serial_number, len);
00110         }
00111         return 0;
00112 }
00113 
00114 
00115 int wps_build_primary_dev_type(struct wps_device_data *dev, struct wpabuf *msg)
00116 {
00117         struct wps_dev_type *d;
00118         wpa_printf(MSG_DEBUG, "WPS:  * Primary Device Type");
00119         wpabuf_put_be16(msg, ATTR_PRIMARY_DEV_TYPE);
00120         wpabuf_put_be16(msg, sizeof(*d));
00121         d = wpabuf_put(msg, sizeof(*d));
00122         WPA_PUT_BE16(d->categ_id, dev->categ);
00123         WPA_PUT_BE32(d->oui, dev->oui);
00124         WPA_PUT_BE16(d->sub_categ_id, dev->sub_categ);
00125         return 0;
00126 }
00127 
00128 
00129 static int wps_build_dev_name(struct wps_device_data *dev, struct wpabuf *msg)
00130 {
00131         size_t len;
00132         wpa_printf(MSG_DEBUG, "WPS:  * Device Name");
00133         wpabuf_put_be16(msg, ATTR_DEV_NAME);
00134         len = dev->device_name ? os_strlen(dev->device_name) : 0;
00135         if (len == 0) {
00136                 /*
00137                  * Some deployed WPS implementations fail to parse zero-length
00138                  * attributes. As a workaround, send a null character if the
00139                  * device attribute string is empty.
00140                  */
00141                 wpabuf_put_be16(msg, 1);
00142                 wpabuf_put_u8(msg, '\0');
00143         } else {
00144                 wpabuf_put_be16(msg, len);
00145                 wpabuf_put_data(msg, dev->device_name, len);
00146         }
00147         return 0;
00148 }
00149 
00150 
00151 int wps_build_device_attrs(struct wps_device_data *dev, struct wpabuf *msg)
00152 {
00153         if (wps_build_manufacturer(dev, msg) ||
00154             wps_build_model_name(dev, msg) ||
00155             wps_build_model_number(dev, msg) ||
00156             wps_build_serial_number(dev, msg) ||
00157             wps_build_primary_dev_type(dev, msg) ||
00158             wps_build_dev_name(dev, msg))
00159                 return -1;
00160         return 0;
00161 }
00162 
00163 
00164 int wps_build_os_version(struct wps_device_data *dev, struct wpabuf *msg)
00165 {
00166         wpa_printf(MSG_DEBUG, "WPS:  * OS Version");
00167         wpabuf_put_be16(msg, ATTR_OS_VERSION);
00168         wpabuf_put_be16(msg, 4);
00169         wpabuf_put_be32(msg, 0x80000000 | dev->os_version);
00170         return 0;
00171 }
00172 
00173 
00174 int wps_build_rf_bands(struct wps_device_data *dev, struct wpabuf *msg)
00175 {
00176         wpa_printf(MSG_DEBUG, "WPS:  * RF Bands (%x)", dev->rf_bands);
00177         wpabuf_put_be16(msg, ATTR_RF_BANDS);
00178         wpabuf_put_be16(msg, 1);
00179         wpabuf_put_u8(msg, dev->rf_bands);
00180         return 0;
00181 }
00182 
00183 
00184 static int wps_process_manufacturer(struct wps_device_data *dev, const u8 *str,
00185                                     size_t str_len)
00186 {
00187         if (str == NULL) {
00188                 wpa_printf(MSG_DEBUG, "WPS: No Manufacturer received");
00189                 return -1;
00190         }
00191 
00192         wpa_hexdump_ascii(MSG_DEBUG, "WPS: Manufacturer", str, str_len);
00193 
00194         os_free(dev->manufacturer);
00195         dev->manufacturer = os_malloc(str_len + 1);
00196         if (dev->manufacturer == NULL)
00197                 return -1;
00198         os_memcpy(dev->manufacturer, str, str_len);
00199         dev->manufacturer[str_len] = '\0';
00200 
00201         return 0;
00202 }
00203 
00204 
00205 static int wps_process_model_name(struct wps_device_data *dev, const u8 *str,
00206                                   size_t str_len)
00207 {
00208         if (str == NULL) {
00209                 wpa_printf(MSG_DEBUG, "WPS: No Model Name received");
00210                 return -1;
00211         }
00212 
00213         wpa_hexdump_ascii(MSG_DEBUG, "WPS: Model Name", str, str_len);
00214 
00215         os_free(dev->model_name);
00216         dev->model_name = os_malloc(str_len + 1);
00217         if (dev->model_name == NULL)
00218                 return -1;
00219         os_memcpy(dev->model_name, str, str_len);
00220         dev->model_name[str_len] = '\0';
00221 
00222         return 0;
00223 }
00224 
00225 
00226 static int wps_process_model_number(struct wps_device_data *dev, const u8 *str,
00227                                     size_t str_len)
00228 {
00229         if (str == NULL) {
00230                 wpa_printf(MSG_DEBUG, "WPS: No Model Number received");
00231                 return -1;
00232         }
00233 
00234         wpa_hexdump_ascii(MSG_DEBUG, "WPS: Model Number", str, str_len);
00235 
00236         os_free(dev->model_number);
00237         dev->model_number = os_malloc(str_len + 1);
00238         if (dev->model_number == NULL)
00239                 return -1;
00240         os_memcpy(dev->model_number, str, str_len);
00241         dev->model_number[str_len] = '\0';
00242 
00243         return 0;
00244 }
00245 
00246 
00247 static int wps_process_serial_number(struct wps_device_data *dev,
00248                                      const u8 *str, size_t str_len)
00249 {
00250         if (str == NULL) {
00251                 wpa_printf(MSG_DEBUG, "WPS: No Serial Number received");
00252                 return -1;
00253         }
00254 
00255         wpa_hexdump_ascii(MSG_DEBUG, "WPS: Serial Number", str, str_len);
00256 
00257         os_free(dev->serial_number);
00258         dev->serial_number = os_malloc(str_len + 1);
00259         if (dev->serial_number == NULL)
00260                 return -1;
00261         os_memcpy(dev->serial_number, str, str_len);
00262         dev->serial_number[str_len] = '\0';
00263 
00264         return 0;
00265 }
00266 
00267 
00268 static int wps_process_dev_name(struct wps_device_data *dev, const u8 *str,
00269                                 size_t str_len)
00270 {
00271         if (str == NULL) {
00272                 wpa_printf(MSG_DEBUG, "WPS: No Device Name received");
00273                 return -1;
00274         }
00275 
00276         wpa_hexdump_ascii(MSG_DEBUG, "WPS: Device Name", str, str_len);
00277 
00278         os_free(dev->device_name);
00279         dev->device_name = os_malloc(str_len + 1);
00280         if (dev->device_name == NULL)
00281                 return -1;
00282         os_memcpy(dev->device_name, str, str_len);
00283         dev->device_name[str_len] = '\0';
00284 
00285         return 0;
00286 }
00287 
00288 
00289 static int wps_process_primary_dev_type(struct wps_device_data *dev,
00290                                         const u8 *dev_type)
00291 {
00292         struct wps_dev_type *d;
00293 
00294         if (dev_type == NULL) {
00295                 wpa_printf(MSG_DEBUG, "WPS: No Primary Device Type received");
00296                 return -1;
00297         }
00298 
00299         d = (struct wps_dev_type *) dev_type;
00300         dev->categ = WPA_GET_BE16(d->categ_id);
00301         dev->oui = WPA_GET_BE32(d->oui);
00302         dev->sub_categ = WPA_GET_BE16(d->sub_categ_id);
00303 
00304         wpa_printf(MSG_DEBUG, "WPS: Primary Device Type: category %d "
00305                    "OUI %08x sub-category %d",
00306                    dev->categ, dev->oui, dev->sub_categ);
00307 
00308         return 0;
00309 }
00310 
00311 
00312 int wps_process_device_attrs(struct wps_device_data *dev,
00313                              struct wps_parse_attr *attr)
00314 {
00315         if (wps_process_manufacturer(dev, attr->manufacturer,
00316                                      attr->manufacturer_len) ||
00317             wps_process_model_name(dev, attr->model_name,
00318                                    attr->model_name_len) ||
00319             wps_process_model_number(dev, attr->model_number,
00320                                      attr->model_number_len) ||
00321             wps_process_serial_number(dev, attr->serial_number,
00322                                       attr->serial_number_len) ||
00323             wps_process_primary_dev_type(dev, attr->primary_dev_type) ||
00324             wps_process_dev_name(dev, attr->dev_name, attr->dev_name_len))
00325                 return -1;
00326         return 0;
00327 }
00328 
00329 
00330 int wps_process_os_version(struct wps_device_data *dev, const u8 *ver)
00331 {
00332         if (ver == NULL) {
00333                 wpa_printf(MSG_DEBUG, "WPS: No OS Version received");
00334                 return -1;
00335         }
00336 
00337         dev->os_version = WPA_GET_BE32(ver);
00338         wpa_printf(MSG_DEBUG, "WPS: OS Version %08x", dev->os_version);
00339 
00340         return 0;
00341 }
00342 
00343 
00344 int wps_process_rf_bands(struct wps_device_data *dev, const u8 *bands)
00345 {
00346         if (bands == NULL) {
00347                 wpa_printf(MSG_DEBUG, "WPS: No RF Bands received");
00348                 return -1;
00349         }
00350 
00351         dev->rf_bands = *bands;
00352         wpa_printf(MSG_DEBUG, "WPS: Enrollee RF Bands 0x%x", dev->rf_bands);
00353 
00354         return 0;
00355 }
00356 
00357 
00358 void wps_device_data_dup(struct wps_device_data *dst,
00359                          const struct wps_device_data *src)
00360 {
00361         if (src->device_name)
00362                 dst->device_name = os_strdup(src->device_name);
00363         if (src->manufacturer)
00364                 dst->manufacturer = os_strdup(src->manufacturer);
00365         if (src->model_name)
00366                 dst->model_name = os_strdup(src->model_name);
00367         if (src->model_number)
00368                 dst->model_number = os_strdup(src->model_number);
00369         if (src->serial_number)
00370                 dst->serial_number = os_strdup(src->serial_number);
00371         dst->categ = src->categ;
00372         dst->oui = src->oui;
00373         dst->sub_categ = src->sub_categ;
00374         dst->os_version = src->os_version;
00375         dst->rf_bands = src->rf_bands;
00376 }
00377 
00378 
00379 void wps_device_data_free(struct wps_device_data *dev)
00380 {
00381         os_free(dev->device_name);
00382         dev->device_name = NULL;
00383         os_free(dev->manufacturer);
00384         dev->manufacturer = NULL;
00385         os_free(dev->model_name);
00386         dev->model_name = NULL;
00387         os_free(dev->model_number);
00388         dev->model_number = NULL;
00389         os_free(dev->serial_number);
00390         dev->serial_number = NULL;
00391 }
00392 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on Sat Nov 21 23:16:54 2009 for hostapd by  doxygen 1.6.1