- memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
- wk.ik_keyix = IEEE80211_KEYIX_NONE;
+- memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
+- wk.ik_keyix = IEEE80211_KEYIX_NONE;
++ os_memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
++ /*
++ * Deduce whether group/global or unicast key by checking
++ * the address (yech). Note also that we can only mark global
++ * keys default; doing this for a unicast key is an error.
++ */
++ if (os_memcmp(addr, "\xff\xff\xff\xff\xff\xff",
++ IEEE80211_ADDR_LEN) == 0) {
++ wk.ik_flags |= IEEE80211_KEY_GROUP;
++ wk.ik_keyix = key_idx;
++ } else {
++ wk.ik_keyix = key_idx == 0 ? IEEE80211_KEYIX_NONE :
++ key_idx;
++ }