def performance_characteristics(signature):
  """Parse 802.11n/ac capabilities bitmasks from sig.

  Args:
    signature: the Wifi signature string.

  Returns:
    (standard, nss, width) where:
    standard: 802.11 standard like 'a/b/g', 'n', 'ac', etc.
    nss: number of spatial streams as an int, 0 for unknown.
    width: channel width as a string: '20', '40', '80', '160', '80+80', '??'
  """
  segments = signature.split('|')
  vhtseg = ''
  for segment in segments:
    # There are a few kindof broken devices which
    # include a vhtcap in their Probe even though
    # they are not 802.11ac devices. They didn't
    # notice because its the Association which
    # really counts. For client devices, only look
    # at the Association. For APs, look at the
    # Beacon.
    if segment.startswith('assoc:') or segment.startswith('beacon:'):
      vhtseg = segment
  if not vhtseg:
    return ''
  fields = vhtseg.split(',')
  vht_nss = ht_nss = 0
  vht_width = ht_width = ''
  for field in fields:
    if field.startswith('vhtcap:'):
      try:
        bitmap = int(field[len('vhtcap:'):], base=16)
      except ValueError:
        vht_width = '??'
      else:
        scw = (bitmap >> 2) & 0x3
        widths = {0: '80', 1: '160', 2: '80+80'}
        vht_width = widths.get(scw, '??')
    elif field.startswith('htcap:'):
      try:
        bitmap = int(field[len('htcap:'):], base=16)
      except ValueError:
        ht_width = '??'
      else:
        ht_width = '40' if bitmap & 0x2 else '20'
    elif field.startswith('htmcs:'):
      try:
        mcs = int(field[len('htmcs:'):], base=16)
      except ValueError:
        pass
      else:
        ht_nss = ((mcs & 0x000000ff != 0) + (mcs & 0x0000ff00 != 0) +
                  (mcs & 0x00ff0000 != 0) + (mcs & 0xff000000 != 0))
    elif field.startswith('vhtrxmcs:'):
      try:
        mcs = int(field[len('vhtrxmcs:'):], base=16)
      except ValueError:
        pass
      else:
        vht_nss = ((mcs & 0x0003 != 0x0003) + (mcs & 0x000c != 0x000c) +
                   (mcs & 0x0030 != 0x0030) + (mcs & 0x00c0 != 0x00c0) +
                   (mcs & 0x0300 != 0x0300) + (mcs & 0x0c00 != 0x0c00) +
                   (mcs & 0x3000 != 0x3000) + (mcs & 0xc000 != 0xc000))
  if vht_width:
    return ('802.11ac', vht_nss, vht_width)
  if ht_width:
    return ('802.11n', ht_nss, ht_width)
  return ('802.11a/b/g', 1, '20')