/* LUFA Library Copyright (C) Dean Camera, 2017. dean [at] fourwalledcubicle [dot] com www.lufa-lib.org */ /* Copyright 2017 Dean Camera (dean [at] fourwalledcubicle [dot] com) Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that the copyright notice and this permission notice and warranty disclaimer appear in supporting documentation, and that the name of the author not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. The author disclaims all warranties with regard to this software, including all implied warranties of merchantability and fitness. In no event shall the author be liable for any special, indirect or consequential damages or any damages whatsoever resulting from loss of use, data or profits, whether in an action of contract, negligence or other tortious action, arising out of or in connection with the use or performance of this software. */ /** \file * * DHCP Client Application. When connected to the uIP stack, this will retrieve IP configuration settings from the * DHCP server on the network. */ #define INCLUDE_FROM_DHCPCLIENTAPP_C #include "DHCPClientApp.h" #if defined(ENABLE_DHCP_CLIENT) || defined(__DOXYGEN__) /** Initialization function for the DHCP client. */ void DHCPClientApp_Init(void) { /* Create a new UDP connection to the DHCP server port for the DHCP solicitation */ struct uip_udp_conn* Connection = uip_udp_new(&uip_broadcast_addr, HTONS(DHCP_SERVER_PORT)); /* If the connection was successfully created, bind it to the local DHCP client port */ if (Connection != NULL) { uip_udp_appstate_t* const AppState = &Connection->appstate; uip_udp_bind(Connection, HTONS(DHCP_CLIENT_PORT)); /* Set the initial client state */ AppState->DHCPClient.CurrentState = DHCP_STATE_SendDiscover; /* Set timeout period to half a second for a DHCP server to respond */ timer_set(&AppState->DHCPClient.Timeout, CLOCK_SECOND / 2); } } /** uIP stack application callback for the DHCP client. This function must be called each time the TCP/IP stack * needs a UDP packet to be processed. */ void DHCPClientApp_Callback(void) { uip_udp_appstate_t* const AppState = &uip_udp_conn->appstate; DHCP_Header_t* const AppData = (DHCP_Header_t*)uip_appdata; uint16_t AppDataSize = 0; switch (AppState->DHCPClient.CurrentState) { case DHCP_STATE_SendDiscover: /* Clear all DHCP settings, reset client IP address */ memset(&AppState->DHCPClient.DHCPOffer_Data, 0x00, sizeof(AppState->DHCPClient.DHCPOffer_Data)); uip_sethostaddr((uip_ipaddr_t*)&AppState->DHCPClient.DHCPOffer_Data.AllocatedIP); /* Fill out the DHCP response header */ AppDataSize += DHCPClientApp_FillDHCPHeader(AppData, DHCP_DISCOVER, AppState); /* Add the required DHCP options list to the packet */ uint8_t RequiredOptionList[] = {DHCP_OPTION_SUBNET_MASK, DHCP_OPTION_ROUTER, DHCP_OPTION_DNS_SERVER}; AppDataSize += DHCPCommon_SetOption(AppData->Options, DHCP_OPTION_REQ_LIST, sizeof(RequiredOptionList), RequiredOptionList); /* Send the DHCP DISCOVER packet */ uip_udp_send(AppDataSize); /* Reset the timeout timer, progress to next state */ timer_reset(&AppState->DHCPClient.Timeout); AppState->DHCPClient.CurrentState = DHCP_STATE_WaitForOffer; break; case DHCP_STATE_WaitForOffer: if (!(uip_newdata())) { /* Check if the DHCP timeout period has expired while waiting for a response */ if (timer_expired(&AppState->DHCPClient.Timeout)) AppState->DHCPClient.CurrentState = DHCP_STATE_SendDiscover; break; } uint8_t OfferResponse_MessageType; if ((AppData->TransactionID == DHCP_TRANSACTION_ID) && DHCPCommon_GetOption(AppData->Options, DHCP_OPTION_MSG_TYPE, &OfferResponse_MessageType) && (OfferResponse_MessageType == DHCP_OFFER)) { /* Received a DHCP offer for an IP address, copy over values for later request */ memcpy(&AppState->DHCPClient.DHCPOffer_Data.AllocatedIP, &AppData->YourIP, sizeof(uip_ipaddr_t)); DHCPCommon_GetOption(AppData->Options, DHCP_OPTION_SUBNET_MASK, &AppState->DHCPClient.DHCPOffer_Data.Netmask); DHCPCommon_GetOption(AppData->Options, DHCP_OPTION_ROUTER, &AppState->DHCPClient.DHCPOffer_Data.GatewayIP); DHCPCommon_GetOption(AppData->Options, DHCP_OPTION_SERVER_ID, &AppState->DHCPClient.DHCPOffer_Data.ServerIP); timer_reset(&AppState->DHCPClient.Timeout); AppState->DHCPClient.CurrentState = DHCP_STATE_SendRequest; } break; case DHCP_STATE_SendRequest: /* Fill out the DHCP response header */ AppDataSize += DHCPClientApp_FillDHCPHeader(AppData, DHCP_REQUEST, AppState); /* Add the DHCP REQUESTED IP ADDRESS option to the packet */ AppDataSize += DHCPCommon_SetOption(AppData->Options, DHCP_OPTION_REQ_IPADDR, sizeof(uip_ipaddr_t), &AppState->DHCPClient.DHCPOffer_Data.AllocatedIP); /* Add the DHCP SERVER IP ADDRESS option to the packet */ AppDataSize += DHCPCommon_SetOption(AppData->Options, DHCP_OPTION_SERVER_ID, sizeof(uip_ipaddr_t), &AppState->DHCPClient.DHCPOffer_Data.ServerIP); /* Send the DHCP REQUEST packet */ uip_udp_send(AppDataSize); /* Reset the timeout timer, progress to next state */ timer_reset(&AppState->DHCPClient.Timeout); AppState->DHCPClient.CurrentState = DHCP_STATE_WaitForACK; break; case DHCP_STATE_WaitForACK: if (!(uip_newdata())) { /* Check if the DHCP timeout period has expired while waiting for a response */ if (timer_expired(&AppState->DHCPClient.Timeout)) AppState->DHCPClient.CurrentState = DHCP_STATE_SendDiscover; break; } uint8_t RequestResponse_MessageType; if ((AppData->TransactionID == DHCP_TRANSACTION_ID) && DHCPCommon_GetOption(AppData->Options, DHCP_OPTION_MSG_TYPE, &RequestResponse_MessageType) && (RequestResponse_MessageType == DHCP_ACK)) { /* Set the new network parameters from the DHCP server */ uip_sethostaddr((uip_ipaddr_t*)&AppState->DHCPClient.DHCPOffer_Data.AllocatedIP); uip_setnetmask((uip_ipaddr_t*)&AppState->DHCPClient.DHCPOffer_Data.Netmask); uip_setdraddr((uip_ipaddr_t*)&AppState->DHCPClient.DHCPOffer_Data.GatewayIP); AppState->DHCPClient.CurrentState = DHCP_STATE_AddressLeased; } break; } } /** Fills the DHCP packet response with the appropriate BOOTP header for DHCP. This fills out all the required * fields, leaving only the additional DHCP options to be added to the packet before it is sent to the DHCP server. * * \param[out] DHCPHeader Location in the packet buffer where the BOOTP header should be written to * \param[in] DHCPMessageType DHCP Message type, such as DHCP_DISCOVER * \param[in] AppState Application state of the current UDP connection * * \return Size in bytes of the created DHCP packet */ static uint16_t DHCPClientApp_FillDHCPHeader(DHCP_Header_t* const DHCPHeader, const uint8_t DHCPMessageType, uip_udp_appstate_t* const AppState) { /* Erase existing packet data so that we start will all 0x00 DHCP header data */ memset(DHCPHeader, 0, sizeof(DHCP_Header_t)); /* Fill out the DHCP packet header */ DHCPHeader->Operation = DHCP_OP_BOOTREQUEST; DHCPHeader->HardwareType = DHCP_HTYPE_ETHERNET; DHCPHeader->HardwareAddressLength = sizeof(MACAddress); DHCPHeader->Hops = 0; DHCPHeader->TransactionID = DHCP_TRANSACTION_ID; DHCPHeader->ElapsedSeconds = 0; DHCPHeader->Flags = HTONS(BOOTP_BROADCAST); memcpy(&DHCPHeader->ClientIP, &uip_hostaddr, sizeof(uip_ipaddr_t)); memcpy(&DHCPHeader->YourIP, &AppState->DHCPClient.DHCPOffer_Data.AllocatedIP, sizeof(uip_ipaddr_t)); memcpy(&DHCPHeader->NextServerIP, &AppState->DHCPClient.DHCPOffer_Data.ServerIP, sizeof(uip_ipaddr_t)); memcpy(&DHCPHeader->ClientHardwareAddress, &MACAddress, sizeof(struct uip_eth_addr)); DHCPHeader->Cookie = DHCP_MAGIC_COOKIE; /* Add a DHCP message type and terminator options to the start of the DHCP options field */ DHCPHeader->Options[0] = DHCP_OPTION_MSG_TYPE; DHCPHeader->Options[1] = 1; DHCPHeader->Options[2] = DHCPMessageType; DHCPHeader->Options[3] = DHCP_OPTION_END; /* Calculate the total number of bytes added to the outgoing packet */ return (sizeof(DHCP_Header_t) + 4); } #endif a> 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506
# Keycodes Overview
When defining a [keymap](keymap.md) each key needs a valid key definition. This page documents the symbols that correspond to keycodes that are available to you in QMK.
This is a reference only. Each group of keys links to the page documenting their functionality in more detail.
## [Basic Keycodes](keycodes_basic.md)
|Key |Aliases |Description |
|-----------------------|------------------------------|-----------------------------------------------|
|`KC_NO` |`XXXXXXX` |Ignore this key (NOOP) |
|`KC_TRANSPARENT` |`KC_TRNS`, `_______` |Use the next lowest non-transparent key |
|`KC_A` | |`a` and `A` |
|`KC_B` | |`b` and `B` |
|`KC_C` | |`c` and `C` |
|`KC_D` | |`d` and `D` |
|`KC_E` | |`e` and `E` |
|`KC_F` | |`f` and `F` |
|`KC_G` | |`g` and `G` |
|`KC_H` | |`h` and `H` |
|`KC_I` | |`i` and `I` |
|`KC_J` | |`j` and `J` |
|`KC_K` | |`k` and `K` |
|`KC_L` | |`l` and `L` |
|`KC_M` | |`m` and `M` |
|`KC_N` | |`n` and `N` |
|`KC_O` | |`o` and `O` |
|`KC_P` | |`p` and `P` |
|`KC_Q` | |`q` and `Q` |
|`KC_R` | |`r` and `R` |
|`KC_S` | |`s` and `S` |
|`KC_T` | |`t` and `T` |
|`KC_U` | |`u` and `U` |
|`KC_V` | |`v` and `V` |
|`KC_W` | |`w` and `W` |
|`KC_X` | |`x` and `X` |
|`KC_Y` | |`y` and `Y` |
|`KC_Z` | |`z` and `Z` |
|`KC_1` | |`1` and `!` |
|`KC_2` | |`2` and `@` |
|`KC_3` | |`3` and `#` |
|`KC_4` | |`4` and `$` |
|`KC_5` | |`5` and `%` |
|`KC_6` | |`6` and `^` |
|`KC_7` | |`7` and `&` |
|`KC_8` | |`8` and `*` |
|`KC_9` | |`9` and `(` |
|`KC_0` | |`0` and `)` |
|`KC_ENTER` |`KC_ENT` |Return (Enter) |
|`KC_ESCAPE` |`KC_ESC` |Escape |
|`KC_BSPACE` |`KC_BSPC` |Delete (Backspace) |
|`KC_TAB` | |Tab |
|`KC_SPACE` |`KC_SPC` |Spacebar |
|`KC_MINUS` |`KC_MINS` |`-` and `_` |
|`KC_EQUAL` |`KC_EQL` |`=` and `+` |
|`KC_LBRACKET` |`KC_LBRC` |`[` and `{` |
|`KC_RBRACKET` |`KC_RBRC` |`]` and `}` |
|`KC_BSLASH` |`KC_BSLS` |`\` and `\|` |
|`KC_NONUS_HASH` |`KC_NUHS` |Non-US `#` and `~` |
|`KC_SCOLON` |`KC_SCLN` |`;` and `:` |
|`KC_QUOTE` |`KC_QUOT` |`'` and `"` |
|`KC_GRAVE` |`KC_GRV`, `KC_ZKHK` |<code>`</code> and `~`, JIS Zenkaku/Hankaku|
|`KC_COMMA` |`KC_COMM` |`,` and `<` |
|`KC_DOT` | |`.` and `>` |
|`KC_SLASH` |`KC_SLSH` |`/` and `?` |
|`KC_CAPSLOCK` |`KC_CLCK`, `KC_CAPS` |Caps Lock |
|`KC_F1` | |F1 |
|`KC_F2` | |F2 |
|`KC_F3` | |F3 |
|`KC_F4` | |F4 |
|`KC_F5` | |F5 |
|`KC_F6` | |F6 |
|`KC_F7` | |F7 |
|`KC_F8` | |F8 |
|`KC_F9` | |F9 |
|`KC_F10` | |F10 |
|`KC_F11` | |F11 |
|`KC_F12` | |F12 |
|`KC_PSCREEN` |`KC_PSCR` |Print Screen |
|`KC_SCROLLLOCK` |`KC_SLCK`, `KC_BRMD` |Scroll Lock, Brightness Down (macOS) |
|`KC_PAUSE` |`KC_PAUS`, `KC_BRK`, `KC_BRMU`|Pause, Brightness Up (macOS) |
|`KC_INSERT` |`KC_INS` |Insert |
|`KC_HOME` | |Home |
|`KC_PGUP` | |Page Up |
|`KC_DELETE` |`KC_DEL` |Forward Delete |
|`KC_END` | |End |
|`KC_PGDOWN` |`KC_PGDN` |Page Down |
|`KC_RIGHT` |`KC_RGHT` |Right Arrow |
|`KC_LEFT` | |Left Arrow |
|`KC_DOWN` | |Down Arrow |
|`KC_UP` | |Up Arrow |
|`KC_NUMLOCK` |`KC_NLCK` |Keypad Num Lock and Clear |
|`KC_KP_SLASH` |`KC_PSLS` |Keypad `/` |
|`KC_KP_ASTERISK` |`KC_PAST` |Keypad `*` |
|`KC_KP_MINUS` |`KC_PMNS` |Keypad `-` |
|`KC_KP_PLUS` |`KC_PPLS` |Keypad `+` |
|`KC_KP_ENTER` |`KC_PENT` |Keypad Enter |
|`KC_KP_1` |`KC_P1` |Keypad `1` and End |
|`KC_KP_2` |`KC_P2` |Keypad `2` and Down Arrow |
|`KC_KP_3` |`KC_P3` |Keypad `3` and Page Down |
|`KC_KP_4` |`KC_P4` |Keypad `4` and Left Arrow |
|`KC_KP_5` |`KC_P5` |Keypad `5` |
|`KC_KP_6` |`KC_P6` |Keypad `6` and Right Arrow |
|`KC_KP_7` |`KC_P7` |Keypad `7` and Home |
|`KC_KP_8` |`KC_P8` |Keypad `8` and Up Arrow |
|`KC_KP_9` |`KC_P9` |Keypad `9` and Page Up |
|`KC_KP_0` |`KC_P0` |Keypad `0` and Insert |
|`KC_KP_DOT` |`KC_PDOT` |Keypad `.` and Delete |
|`KC_NONUS_BSLASH` |`KC_NUBS` |Non-US `\` and `\|` |
|`KC_APPLICATION` |`KC_APP` |Application (Windows Menu Key) |
|`KC_POWER` | |System Power (macOS) |
|`KC_KP_EQUAL` |`KC_PEQL` |Keypad `=` |
|`KC_F13` | |F13 |
|`KC_F14` | |F14 |
|`KC_F15` | |F15 |
|`KC_F16` | |F16 |
|`KC_F17` | |F17 |
|`KC_F18` | |F18 |
|`KC_F19` | |F19 |
|`KC_F20` | |F20 |
|`KC_F21` | |F21 |
|`KC_F22` | |F22 |
|`KC_F23` | |F23 |
|`KC_F24` | |F24 |
|`KC_EXECUTE` |`KC_EXEC` |Execute |
|`KC_HELP` | |Help |